[XX='Renzo_Tino, c: 560661, m: 1796307'][/XX]
import java.util.Scanner;
public class Printing {
public static void main(String[] args) {
// Constants
final int ONE_INCH = 72;
final char DOUBLE_LOWER = 'd';
final char DOUBLE_UPPER = 'D';
final char SINGLE_LOWER = 's';
final char SINGLE_UPPER = 'S';
// input fields accept from user
char space = 0;
double length = 0;
double width = 0;
double leftMargin = 0;
double rightMargin = 0;
double topMargin = 0;
double bottomMargin = 0;
double pointSize = 0;
int totalCharacters = 0;
int totalLines = 0;
int finalLength = 0;
double finalWidth = 0;
int pointsLength = 0;
double pointsWidth = 0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the length of the paper:");
length = sc.nextDouble();
System.out.println("Enter the width of the paper:");
width = sc.nextDouble();
System.out.println("Enter the left margin of the paper:");
leftMargin = sc.nextDouble();
System.out.println("Enter the right margin of the paper:");
rightMargin = sc.nextDouble();
System.out.println("Enter the top margin of the paper:");
topMargin = sc.nextDouble();
System.out.println("Enter the bottom margin of the paper:");
bottomMargin = sc.nextDouble();
System.out.println("Enter the point size of the paper:");
pointSize = sc.nextDouble();
System.out
.println("Enterline spacing,s or S (Single spaced),d or D (Double spaced):");
String lineSpace = sc.next();
space = lineSpace.charAt(0);
finalLength = (int) (length - (topMargin + bottomMargin));
finalWidth = width - (leftMargin + rightMargin);
pointsLength = finalLength * ONE_INCH;
pointsWidth = finalWidth * ONE_INCH;
if (space == DOUBLE_UPPER || space == DOUBLE_LOWER) {
pointSize += pointSize;
totalLines = (int) (pointsLength / pointSize);
totalCharacters = (int) (pointsWidth / pointSize);
System.out.println("The number of lines that can be printed : "
+ totalLines);
System.out
.println("The number of characters that can be printed in a line: "
+ totalCharacters);
} else if (space == SINGLE_UPPER || space == SINGLE_LOWER) {
totalLines = (int) (pointsLength / pointSize);
totalCharacters = (int) (pointsWidth / pointSize);
System.out.println("The number of lines that can be printed : "
+ totalLines);
System.out
.println("The number of characters that can be printed in a line: "
+ totalCharacters);
}
sc.close();
}
}
Output:
Enter the length of the paper:
11
Enter the width of the paper:
8.5
Enter the left margin of the paper:
1
Enter the right margin of the paper:
1
Enter the top margin of the paper:
1.5
Enter the bottom margin of the paper:
1
Enter the point size of the paper:
12
Enterline spacing,s or S (Single spaced),d or D (Double spaced):
s
The number of lines that can be printed : 48
The number of characters that can be printed in a line: 39