need help with two different things. 1- How do I ask the user to input an order
Question:
need help with two different things. 1- How do I ask the user to input an order number if menu option 1 is selected? The order has to begin with either FB or SB and then has three digits after those letters. The program then must check to be sure the order number is either letter code and only three digits. 2-How do I instill a Case 4 switch that will display all the gift baskets if menu option 4 is selected? I have a case switch for every menu option, except for menu option 4. Thank you in advance, below is my code as well.
import java.util.Scanner; class Gift { protected String id; public char size; public double price; public Gift(String id) { this.id = id; } public void Set_size(char c) { this.size = c; } public void price() { if (size == 'S') { this.price = 19.99; } if (size == 'M') { this.price = 29.99; } if (size == 'L') { this.price = 39.99; } } }
class FruitBasket extends Gift { private int fruit_no; private boolean citrus_fruits_indication; public FruitBasket(String id) { super(id); } public void fruit_no() { if (size == 'S') { this.fruit_no = 6; } if (size == 'M') { this.fruit_no = 9; } if (size == 'L') { this.fruit_no = 15; } } public void Set_citrus_fruits_indication(boolean b) { this.citrus_fruits_indication = b; if (b == true) { price = price + 5.99; } } public int get_fruit_no() { return fruit_no; } public boolean get_citrus_fruits_indication() { return citrus_fruits_indication; } public void Display() { System.out.println("FruitBasket[ numFruits=" + fruit_no + " haveCitrus=" + citrus_fruits_indication + " size=" + size + " id=" + id + " price=" + String.format("%.02f", price) + "]"); } }
class SweetBasket extends Gift { public boolean nuts_indication; public SweetBasket(String id) { super(id); } public void Set_nuts_indication(boolean t) { this.nuts_indication = t; } public boolean get_nuts_indication() { return nuts_indication; } public void Display() { System.out.println("SweetBasket[havenuts= " + nuts_indication + " size=" + size + " id= " + id + " price= " + price + "]"); } }
public class CMIS242ASG2MeeksT { public static void main(String[] args) { int choice; int a = 0; char bs; boolean b; FruitBasket f = new FruitBasket("FB3150"); SweetBasket s = new SweetBasket("SB3160"); Scanner sc = new Scanner(System.in); do { System.out.println(" MENU"); System.out.println("1: Order a Gift Basket "); System.out.println("2: Change Gift Basket"); System.out.println("3: Display Gift Basket"); System.out.println("4: Display all Gift Baskets"); System.out.println("9: Exit program"); System.out.print("Enter your selection : "); choice = sc.nextInt();
switch (choice) { case 1: System.out.print("Do you want Fruit Basket (1) or Sweets Basket (2):"); a = sc.nextInt(); if (a == 1) { System.out.print("What size do you want: S, M, or L: "); bs = sc.next().charAt(0); f.Set_size(bs); f.fruit_no(); f.price(); System.out.println("Do you want citrus fruits included? true/false:"); b = sc.nextBoolean(); f.Set_citrus_fruits_indication(b); }
if (a == 2) { System.out.print("What size do you want: S, M, or L: "); bs = sc.next().charAt(0); s.Set_size(bs); s.price(); System.out.println("Do you want nut Sweet included? true/false:"); b = sc.nextBoolean(); s.Set_nuts_indication(b); } continue;
case 2: if (a == 1) { System.out.print("Current gift size is: S What size do you want? S, M, or L: "); bs = sc.next().charAt(0); f.Set_size(bs); f.fruit_no(); f.price(); System.out.println("Current basket citrus=" + f.get_citrus_fruits_indication() + " Do you want citrus fruits included? true/false:"); b = sc.nextBoolean(); f.Set_citrus_fruits_indication(b); } if (a == 2) { System.out.print("What size do you want: S, M, or L: "); bs = sc.next().charAt(0); s.Set_size(bs); s.price(); System.out.println("Do you want nut Sweet included? true/false:"); b = sc.nextBoolean(); s.Set_nuts_indication(b);
} if (a == 0) { System.out.print("No gift has been ordered yet "); }
continue; case 3: if (a == 1) { f.Display(); } if (a == 2) { s.Display();
} if (a == 0) { System.out.print("No gift has been ordered yet "); } continue; case 9: System.out.print("Thank you for using the program. Goodbye! ");
}
} while (choice != 9);
}
}
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch