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.
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();
}
}
Comments
Leave a comment