пакет торт;
импорт java .util.ArrayList; import java .util.Arrays;
publi c class Cake {
public String name;
public String[] topping;
public String[] toppingOrder;
double priceSmall;
double priceMedium;
double priceBig;
double totalPrice;
double sizePrice;
int size;
int quantity;
String stringSize;
// Class member variables
public Cake(String name, String[] topping, String[] toppingOrder, double priceSmall, double priceMedium,
double priceBig, double totalPrice, double sizePrice, int size, int quantity, String stringSize) {
this.name = name;
this.topping = topping;
this.toppingOrder = toppingOrder;
this.priceSmall = priceSmall;
this.priceMedium = priceMedium;
this.priceBig = priceBig;
this.totalPrice = totalPrice;
this.sizePrice = sizePrice;
this.size = size;
this.quantity = quantity;
this.stringSize = stringSize;
}
public Cake() {
name = " ";
String[] topping = {"Lava Chocolate","Cream Cheese", "Butter Cream", "Fondant"};
priceSmall = 45.0;
priceMedium = 65.0;
priceBig = 80.0;
totalPrice = 0;
sizePrice = 0;
size = 0;
quantity = 5;
String[] stringSize = {"Small","Medium","Big"};
}
//Constructor that accept String cake’s name
// and set the value to class member name
public Cake(String name) {
this.name = name;
}
// void method setCake that accept four parameters
public void setCake(String[] topping, double priceSmall,
double priceMedium, double priceBig) {
this.topping = topping;
this.priceSmall = 45.00;
this.priceMedium = 65.00;
this.priceBig = 80.00;
}
public String[] topping() {
return topping;
}
public int quantity() {
return quantity;
}
public int size() {
return size;
}
// Void method called orderCake that accept three parameters
public void orderCake(String[] topping, int quantity, int size) {
this.topping = topping;
this.quantity = quantity;
this.size = size;
totalPrice = sizePrice * quantity + (topping.length*10);
}
// • Method called getSizePrice that return
// a double data type where it checks size and return
// the price.
public double getSizePrice(int size, double sizePrice) {
if (size == 1)
{
return 45.0;
}
else if(size == 2)
{
return 65.0;
}
else
{
return 80.0;
}
}
// Method called getTotalPrice
// that return a double data type totalPrice
// Method called getSize which returns
// a String value according to the class member size
public String getSize() {
if (size == 1) {
return "Small";
} else if(size == 2) {
return "Medium";
} else if(size == 3) {
return "Big";
} else {
return null;
}
}
public int getQuantity() {
return quantity;
}
publi c double getTotalPrice () {
totalPrice = getSizePrice() * quantity + (topping.length*10);
return totalPrice;
}
class orderCake extends Cake{
String[] topping;
int size;
int quantity;
}
public void printCake() {
// TODO Auto-generated method stub
System.out.println("------------------------------------------------");
System.out.println("\t\tCake Menu");
System.out.println("------------------------------------------------");
System.out.println("\nGeneric Cake with available Toppings:\n");
System.out.println("1) Lava Chocolate");
System.out.println("2) Cream Cheese");
System.out.println("3) Butter Cream");
System.out.println("4) Fondant");
System.out.println("\nPrice:\n");
System.out.println("[1] Small: RM45.0");
System.out.println("[2] Medium: RM65.0");
System.out.println("[3] Big: RM80.0");
System.out.println();
}
public void printOrder() {
// TODO Auto-generated method stub
System.out.println("Cake order detail:\n");
System.out.println("------------------------");
System.out.println("Topping:" + Arrays.toString(topping));
System.out.println("Size: " + getSize() + "\t");
System.out.println("------------------------");
System.out.println("\nTotal Price:" + getTotalPrice() + "\t");
System.out.println();
}
}
Мой код, наконец, может работать после изменения int getSize () на string getSize (), но у меня все еще есть проблема с моей расчетной частью. Я не могу запустить свой код, и он говорит об ошибке с getSize () в publi c double getTotalPrice ()