所以我的问题直接针对我的家庭作业。在您问之前,是的,我已经查看了其他问题,并且查看了 java 文档以尝试帮助我,但我只了解这么多..
你已经成为餐厅大亨了。您拥有几家快餐连锁店。但是,您现在需要设置所有快餐连锁店都必须遵循的标准,以使您的软件全面统一。有一些规则对所有餐厅都是一样的。
创建一个名为 Restaurant 的抽象类
创建一个函数/方法,在调用时打印餐厅的名称。
创建一个名为总价的抽象函数/方法
创建一个名为菜单项的抽象函数/方法
创建抽象函数/方法名称位置
创建一个名为 McDonalds 的类来扩展 Restaurant
实现所有抽象方法
添加逻辑,以便总价方法/函数将给出包含 6% 税的餐食总价
添加一个返回名为 hasPlayPlace 的布尔值的方法。当此位置有游乐场时返回 true
创建一个构造函数,用于设置麦当劳的名称、位置和 hasPlayPlace
public class McDonalds extends Restaurant {
private String name;
private String location;
private boolean hasPlayPlace;
Scanner input = new Scanner(System.in);
public McDonalds (String name, String location, boolean hasPlayPlace) {
setName(name);
setLocation(location);
setHasPlayPlace(hasPlayPlace);
}
McDonalds location1 = new McDonalds("McDonalds", "Kirkman", false);
McDonalds location2 = new McDonalds("McDonalds 2", "International Dr.", true);
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLocation() {
return location;
}
public void setLocation(String location){
this.location = location;
}
public boolean isHasPlayPlace() {
return hasPlayPlace;
}
public void setHasPlayPlace(boolean hasPlayPlace) {
this.hasPlayPlace = hasPlayPlace;
}
public void totalPrice() {
double totalPrice = 0;
double tax = 0.06;
totalPrice += (totalPrice * tax);
}
public void menuItems() {
//some syntax is wrong in this method
double mcChicken = 1;
double fries = 1.25;
System.out.println("1. Mc Chicken $1");
System.out.println("2. Fries $1.25");
int choice = input.nextInt();
switch (choice){
case 1: mcChicken *= tax;
case 2: fries *= tax;
}
}
public void location() {
//Don't know what's supposed to go in here.
//But I've implemented the method as I was supposed to.
}
}
这一切是否有意义基本上就是我要问的。定位方法应该怎么做?这个类中的getter和setter有什么用,我做对了吗?