Question
Can I get corrections to my code based on this feedback? Feedback: The order id was not requested when adding. Only one order was ever
Can I get corrections to my code based on this feedback?
Feedback:
The order id was not requested when adding.
Only one order was ever added to the array.
The result of the calculation was always 0.00.
There is no find selection.
Only one row is displayed no matter the number of orders added.
/* Manuel Garcia CMIS 242 This code allows you to pick a basket.
*/ package com.mycompany.wk4garciam;
import java.util.Scanner;
/** * Gift class is the base class representing a gift basket */ class Gift {
// ID of the gift basket protected String id; // Size of the gift basket public char size; // Price of the gift basket public double price;
/** * Constructor to create a gift basket * * @param id the id of the gift basket */ public Gift(String id) { this.id = id; }
/** * Set the size of the gift basket * * @param c the size of the gift basket */ public void Set_size(char c) { this.size = c; }
/** * Calculate the price of the gift basket based on its size */ public void price() { if (size == 'S') { this.price = 19.99; }
if (size == 'M') { this.price = 29.99; }
if (size == 'L') { this.price = 39.99; } } }
/** * FruitBasket class represents a gift basket with fruits */ class FruitBasket extends Gift {
// Number of fruits in the gift basket private int fruit_no; // Indication of the presence of citrus fruits private boolean citrus_fruits_indication;
/** * Constructor to create a fruit basket * * @param id the id of the fruit basket */ public FruitBasket(String id) { super(id); }
/** * Calculate the number of fruits in the fruit basket based on its size */ 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; } }
/** * Set the indication of the presence of citrus fruits * * @param b the indication of the presence of citrus fruits */ public void Set_citrus_fruits_indication(boolean b) { this.citrus_fruits_indication = b; if (b == true) { price = price + 5.99; } }
/** * Get the number of fruits in the fruit basket * * @return the number of fruits in the fruit basket */ 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 + "]"); }
} // Menu public class WK4GarciaM { 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"); 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);
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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