Answer to Question #230497 in Java | JSP | JSF for arz

Question #230497
  1. The number of lines that can be printed on a paper depends on the paper size, the point size of each character in a line, whether lines are doublespaced or single-spaced, the top and bottom margin, and the left and right margins of the paper. Assume that all characters are of the same point size, and all lines are either single-spaced or double-spaced. Note that 1 inch ¼ 72 points. Moreover, assume that the lines are printed along the width of the paper. For example, if the length of the paper is 11 inches and the width is 8.5 inches, then the maximum length of a line is 8.5 inches. 


Write a program that calculates the number of characters in a line and the number of lines that can be printed on a paper based on the following input from the user: 

a. The length and width, in inches, of the paper. 

b. The top, bottom, left, and right margins. 

c. The point size of a line. 

d. If the lines are double-spaced, then double the point size of each character.





1
Expert's answer
2021-08-29T00:58:02-0400
import java.util.Scanner;


public class PageCalulator {


	public static void main(String[] args) {
		
		Scanner input = new Scanner(System.in);
		double length, width, toptMargin, bottomtMargin, leftMargin, rightMargin, pointSize;


		System.out.print("Enter the length of the paper: ");
		length = input.nextDouble();
		System.out.print("Enter the width of the paper: ");
		width = input.nextDouble();
		System.out.print("Enter the left margin of the paper: ");
		leftMargin = input.nextDouble();
		System.out.print("Enter the right margin of the paper: ");
		rightMargin = input.nextDouble();
		System.out.print("Enter the top margin of the paper: ");
		toptMargin = input.nextDouble();
		System.out.print("Enter the bottom margin of the paper: ");
		bottomtMargin = input.nextDouble();
		System.out.print("Enter the point size of a character: ");
		pointSize = input.nextDouble();
		input.nextLine();
		System.out.print("Enter line spacing, s or S (single spaced), d or D (double spaced): ");
		String line = input.nextLine();
		if (line.toLowerCase() == "d") {
			pointSize = (pointSize * 2);
		}
		length = length - (toptMargin + bottomtMargin);
		width = width - (rightMargin + leftMargin);
		int numberCharacters = (int) ((width * (72)) / (pointSize));
		int numberLines = (int) ((length * (72)) / (pointSize))-1;
		
		System.out.println("\nThe number of lines that can be printed: " + numberLines);
		System.out.println("The number of characters that can be printed in a line: " + numberCharacters);


		input.close();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS