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
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);
}
}
102 163 164 165 166 167 168 } 169 170 s.set_size(DS); s.price(); System.out.println("Do you want nut Sweet CMIS242ASG2MeeksT [Java Application] C:\Program Files\Java\jdk-17.0.1\bin\javaw.exe (Apr b = sc.nextBoolean(); What size do you want: S, M, or L: M s.Set_nuts_indication(b); if (a == 0) { Do you want citrus fruits included? true/false: true MENU System.out.print("No gift has been ordere 1: Order a Gift Basket continue; case 3: if (a == 1) { f. Display(); } if (a == 2) { s.Display(); if (a == 0) { 2: Change Gift Basket 3: Display Gift Basket 4: Display all Gift Baskets 9: Exit program Enter your selection : 3 FruitBasket[ numFruits-9 haveCitrus-true size-M id=FB3150 price=35.98] MENU 1: Order a Gift Basket 2: Change Gift Basket 3: Display Gift Basket 4: Display all Gift Baskets 9: Exit program System.out.print("No gift has been ordere Enter your selection : 171 } 172 173 174 175 176 177 178 179 180 181 182 } 183 184 185 186 } continue; 187 188 case 9: 189 190 191 192 193 } } while (choice != 9); 194 195 } 196 197} 198 199 System.out.print("Thank you for using the program. Goodbye! ");
Step by Step Solution
There are 3 Steps involved in it
Step: 1
To address your first issue regarding input validation for the order number You can modify the code ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started