I can really use the help the get this program to run in Eclipse. I am having is
ID: 3539970 • Letter: I
Question
I can really use the help the get this program to run in Eclipse. I am having issues with the way I set up the int, it will not run in Eclipse. What am I doing wrong? Thanks
import java.util.Scanner;
public class GroceryStore {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
}
int choice = 1;
double subtotal = 0;
double price = 0;
double discount = 0;
double x = 1.0;
double y = 1.233456;{
do {
System.out.printf("Rick's Grocery Items");
System.out.printf(" ");
System.out.printf("1. Milk $%.2f per lbs", 3.45);
System.out.printf("2. Butter $%.2f", 2.95);
System.out.printf("3. Eggs $%.2f", 3.75);
System.out.printf("4. Bread $%.2f", 2.75);
System.out.printf("5. Hotdogs $%.2f", 9.99);
System.out.printf("6. Mayonnaise $%.2f", 7.75);
System.out.printf("7. Tofu $%.2f", 4.75);
System.out.printf("8. Watermelon $%.2f", 4.99);
System.out.printf("9. Cantelope $%.2f", 1.99);
System.out.printf("10. Soda $%.2f", 5.95);
System.out.printf("");
System.out.printf("0. Quit");
System.out.printf("");
System.out.printf("Your subtotal is $ " +(int) (subtotal * 100) / 100.0);
System.out.printf("What would you like to purchase? If you have completed your order, enter 0.");
choice = input.nextInt();
if (choice == 0)
break;
System.out.println("How many do you want?");
int qty = input.nextInt();
switch (choice) {
case 1:
price = 3.45;
break;
case 2:
price = 2.95;
break;
case 3:
price = 3.75;
break;
case 4:
price = 2.75;
break;
case 5:
price = 9.99;
break;
case 6:
price = 7.75;
break;
case 7:
price = 4.75;
break;
case 8:
price = 4.99;
break;
case 9:
price = 1.99;
break;
case 10:
price = 5.95;
}
subtotal = subtotal + (qty * price);
}
while(choice > 0);
System.out.println("Are you a member of the A+ discount club? (Y/N)");
String discountInput = input.next();
char discountClub = discountInput.charAt (0);
if (discountClub == 'y' || discountClub == 'Y') {
discount = subtotal * .20;
}
double tax = ((subtotal - discount) * 0.075);
double finalCost = subtotal - discount + tax;
System.out.println("The subtotal is $ " + (int) (subtotal * 100) / 100.0);
System.out.println("A+ Members Discount $ " + (int) (discount * 100) / 100.0);
System.out.println("Sales tax $ " + (int) (tax* 100) / 100.0);
System.out.println("Final price $ " + (int) (finalCost * 100) / 100.0);
}
}
Explanation / Answer
import java.util.Scanner;
public class GroceryStore {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
///////////////////////////////////////////
/////////// I'd deleted this bracket }
////////////////////////////////
int choice = 1;
double subtotal = 0;
double price = 0;
double discount = 0;
double x = 1.0;
double y = 1.233456;{
do {
System.out.printf("Rick's Grocery Items");
System.out.printf(" ");
System.out.printf("1. Milk $%.2f per lbs", 3.45);
System.out.printf("2. Butter $%.2f", 2.95);
System.out.printf("3. Eggs $%.2f", 3.75);
System.out.printf("4. Bread $%.2f", 2.75);
System.out.printf("5. Hotdogs $%.2f", 9.99);
System.out.printf("6. Mayonnaise $%.2f", 7.75);
System.out.printf("7. Tofu $%.2f", 4.75);
System.out.printf("8. Watermelon $%.2f", 4.99);
System.out.printf("9. Cantelope $%.2f", 1.99);
System.out.printf("10. Soda $%.2f", 5.95);
System.out.printf("");
System.out.printf("0. Quit");
System.out.printf("");
System.out.printf("Your subtotal is $ " +(int) (subtotal * 100) / 100.0);
System.out.printf("What would you like to purchase? If you have completed your order, enter 0.");
choice = input.nextInt();
if (choice == 0)
break;
System.out.println("How many do you want?");
int qty = input.nextInt();
switch (choice) {
case 1:
price = 3.45;
break;
case 2:
price = 2.95;
break;
case 3:
price = 3.75;
break;
case 4:
price = 2.75;
break;
case 5:
price = 9.99;
break;
case 6:
price = 7.75;
break;
case 7:
price = 4.75;
break;
case 8:
price = 4.99;
break;
case 9:
price = 1.99;
break;
case 10:
price = 5.95;
}
subtotal = subtotal + (qty * price);
}
while(choice > 0);
System.out.println("Are you a member of the A+ discount club? (Y/N)");
String discountInput = input.next();
char discountClub = discountInput.charAt (0);
if (discountClub == 'y' || discountClub == 'Y') {
discount = subtotal * .20;
}
double tax = ((subtotal - discount) * 0.075);
double finalCost = subtotal - discount + tax;
System.out.println("The subtotal is $ " + (int) (subtotal * 100) / 100.0);
System.out.println("A+ Members Discount $ " + (int) (discount * 100) / 100.0);
System.out.println("Sales tax $ " + (int) (tax* 100) / 100.0);
System.out.println("Final price $ " + (int) (finalCost * 100) / 100.0);
}
////////////////////////////////////////////////////////////////////////
//////////I'd added this bracket to end main function
}
//////////////////////////////////////////////////////////////////////
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.