In: Computer Science
I am having problems making code to follow these parameters.
1. Create a new project and class in Eclipse. (5 points)
2. Add a comment with your name(s) on the first line of your code. (5 points)
3. Add the main method to the class. (5 points)
4. Use variables to store three book titles and their authors. (10 points)
5. Use variables to store the price of each book. (10 points)
6. Use variables to store the number of copies purchased of each book. (10 points)
7. Use a constant variable to store the tax rate (8.75%). (5 points)
8. Calculate the pretax total, sales tax, and total order cost using arithmetic operators and the variables described above. Store the calculation results in variables. (20 points)
9. Print the order information to the console. When printing dollar amounts, round each value to two decimal places (i.e., to the nearest penny). (20 points)
10. Use meaningful variable names, consistent indentation, and whitespace (blank lines and spaces) to make your code readable. Add comments where appropriate to explain the overall steps of your program. (10 points)
import java.util.Scanner;
/**
* @author Name
*
*/
public class BookOrder {
public static void main(String[] args) {
// variables for titles
String title1, title2,
title3;
// variables for authors
String author1, author2,
author3;
// variables for prices
double price1, price2,
price3;
// variables for units
int units1, units2, units3;
//constant to store tax rate
final double TAX_RATE = 8.75;
double preTaxTotal, salesTax,
total;
Scanner sc = new
Scanner(System.in);
//reading book1 details
System.out.println("Enter title and
author of book 1");
title1 = sc.nextLine();
author1 = sc.nextLine();
System.out.println("Enter the
number of units for book");
units1 = sc.nextInt();
System.out.println("Enter price for
book 1");
price1 = sc.nextDouble();
//reading book2 details
System.out.println("Enter title and
author of book 2");
title2 = sc.nextLine();
title2 = sc.nextLine();
author2 = sc.nextLine();
System.out.println("Enter the
number of units for book2");
units2 = sc.nextInt();
System.out.println("Enter price for
book 2");
price2 = sc.nextDouble();
//reading book3 details
System.out.println("Enter title
and author of book 3");
title3 = sc.nextLine();
title3 = sc.nextLine();
author3 = sc.nextLine();
System.out.println("Enter the
number of units for book 3");
units3 = sc.nextInt();
System.out.println("Enter price for
book 3");
price3 = sc.nextDouble();
//finding preTaxtotal and sales
tax and total amount
preTaxTotal = price1 * units1 +
price2 * units2 + price3 * units3;
salesTax = preTaxTotal * (TAX_RATE
/ 100);
total = preTaxTotal +
salesTax;
System.out.println("Pre Tax Amount
: " + preTaxTotal);
System.out.println("Sales Tax
Amount (" + TAX_RATE + "%): " + salesTax);
System.out.println("Total Amount :
" + total);
}
}