inkedmn
08-29-2002, 09:09 PM
ok, here's my code:
public class MovieCashierApplication {
public static void main(String[] args) {
EasyIn easy = new EasyIn();
int movieNumber;
int adultTickets;
int childTickets;
float adultTicketPrice = (float)8.75;
float childTicketPrice = (float)5.50;
double TAX_RATE = 0.775;
double DISCOUNT_RATE = 0.10;
System.out.println("Hello! Welcome to the Movie Cashier.");
System.out.println("Which movie would you like to see?");
System.out.println("1) Martin Lawrence Live: Runteldat (R)");
System.out.println("2) The Last Kiss (R)");
System.out.println("3) The Crocodile Hunter: Collision Course (PG-13)");
System.out.println("4) Lilo & Stitch (PG)");
System.out.println("5) Happy Times (PG)");
System.out.println("6) Austin Powers in Goldmember (PG-13)");
System.out.println("7) The Kid Stays in the Picture (R)");
System.out.println("8) The Country Bears (G)");
System.out.println("9) Full Frontal (R)");
System.out.print("\nEnter the number of the movie you would like to see: ");
movieNumber = easy.readInt();
System.out.print("\nEnter the number of Adult tickets you'd like to buy: ");
adultTickets = easy.readInt();
System.out.print("\nEnter the number of Child tickets you'd like to buy: ");
childTickets = easy.readInt();
float adultTicketTotal = (float)adultTickets * adultTicketPrice;
float childTicketTotal = (float)childTickets * childTicketPrice;
float ticketSubtotal = adultTicketTotal + childTicketTotal;
double totalWithTax = ticketSubtotal + (ticketSubtotal * TAX_RATE);
System.out.println("Subotal with tax: $" + totalWithTax);
double discountAmount = ticketSubtotal * DISCOUNT_RATE;
System.out.println("Discount: $" + discountAmount);
double totalCost = totalWithTax - discountAmount;
System.out.println("Total Cost: $" + totalCost);
}
}
the EasyIn class that's being used is something our teacher gave us to use that allows for easy input of the different primitive types. i can put it up somewhere if someone wants to see it.
and here's the output:
D:\javaclass>java MovieCashierApplication
Hello! Welcome to the Movie Cashier.
Which movie would you like to see?
1) Martin Lawrence Live: Runteldat (R)
2) The Last Kiss (R)
3) The Crocodile Hunter: Collision Course (PG-13)
4) Lilo & Stitch (PG)
5) Happy Times (PG)
6) Austin Powers in Goldmember (PG-13)
7) The Kid Stays in the Picture (R)
8) The Country Bears (G)
9) Full Frontal (R)
Enter the number of the movie you would like to see: 9
Enter the number of Adult tickets you'd like to buy: 3
Enter the number of Child tickets you'd like to buy: 2
Subotal with tax: $66.11875
Discount: $3.725
Total Cost: $62.393750000000004
so...
a) does the code look ok? the casting seems a bit messy...
b) how do i round those dollar amounts to 2 decimal places?
thanks!!!
public class MovieCashierApplication {
public static void main(String[] args) {
EasyIn easy = new EasyIn();
int movieNumber;
int adultTickets;
int childTickets;
float adultTicketPrice = (float)8.75;
float childTicketPrice = (float)5.50;
double TAX_RATE = 0.775;
double DISCOUNT_RATE = 0.10;
System.out.println("Hello! Welcome to the Movie Cashier.");
System.out.println("Which movie would you like to see?");
System.out.println("1) Martin Lawrence Live: Runteldat (R)");
System.out.println("2) The Last Kiss (R)");
System.out.println("3) The Crocodile Hunter: Collision Course (PG-13)");
System.out.println("4) Lilo & Stitch (PG)");
System.out.println("5) Happy Times (PG)");
System.out.println("6) Austin Powers in Goldmember (PG-13)");
System.out.println("7) The Kid Stays in the Picture (R)");
System.out.println("8) The Country Bears (G)");
System.out.println("9) Full Frontal (R)");
System.out.print("\nEnter the number of the movie you would like to see: ");
movieNumber = easy.readInt();
System.out.print("\nEnter the number of Adult tickets you'd like to buy: ");
adultTickets = easy.readInt();
System.out.print("\nEnter the number of Child tickets you'd like to buy: ");
childTickets = easy.readInt();
float adultTicketTotal = (float)adultTickets * adultTicketPrice;
float childTicketTotal = (float)childTickets * childTicketPrice;
float ticketSubtotal = adultTicketTotal + childTicketTotal;
double totalWithTax = ticketSubtotal + (ticketSubtotal * TAX_RATE);
System.out.println("Subotal with tax: $" + totalWithTax);
double discountAmount = ticketSubtotal * DISCOUNT_RATE;
System.out.println("Discount: $" + discountAmount);
double totalCost = totalWithTax - discountAmount;
System.out.println("Total Cost: $" + totalCost);
}
}
the EasyIn class that's being used is something our teacher gave us to use that allows for easy input of the different primitive types. i can put it up somewhere if someone wants to see it.
and here's the output:
D:\javaclass>java MovieCashierApplication
Hello! Welcome to the Movie Cashier.
Which movie would you like to see?
1) Martin Lawrence Live: Runteldat (R)
2) The Last Kiss (R)
3) The Crocodile Hunter: Collision Course (PG-13)
4) Lilo & Stitch (PG)
5) Happy Times (PG)
6) Austin Powers in Goldmember (PG-13)
7) The Kid Stays in the Picture (R)
8) The Country Bears (G)
9) Full Frontal (R)
Enter the number of the movie you would like to see: 9
Enter the number of Adult tickets you'd like to buy: 3
Enter the number of Child tickets you'd like to buy: 2
Subotal with tax: $66.11875
Discount: $3.725
Total Cost: $62.393750000000004
so...
a) does the code look ok? the casting seems a bit messy...
b) how do i round those dollar amounts to 2 decimal places?
thanks!!!