我正在为我的编程课做作业,为草坪护理服务创建一个程序。对于任务的一部分,我必须创建一种方法,对商业企业每 1000 平方英尺土地收取 5 美元,对住宅每 1000 平方英尺土地收取 6 美元,我的问题是如何将其实施到我的代码中?到目前为止,这是我的代码:
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int choice;
do {
System.out.println("Make your choice: ");
System.out.println("1. Commercial");
System.out.println("2. Residential");
System.out.println("3. Done");
choice = in.nextInt();
if (choice!= 1 && choice != 2 && choice != 3)
System.out.println("Incorrect entry, try again!\n");
}while(choice != 1 && choice != 2 && choice != 3);
switch (choice) {
case 1:
commercial();
break;
case 2:
residential();
break;
case 3:
System.out.println("Have a nice day!");
break;
}
}
private static void commercial(){
boolean multi;
Scanner scanner = new Scanner(System.in);
System.out.println("Commercial Customer");
System.out.println("Please enter the customer name: ");
String name = scanner.nextLine();
System.out.println("Please enter the customer phone number: ");
String phone = scanner.nextLine();
System.out.println("Please enter the customer address: ");
String address = scanner.nextLine();
System.out.println("Please enter the square footage of the property: ");
String foot = scanner.nextLine();
Double footage = Double.parseDouble(foot);
System.out.println("Please type true if there is a multi-property discount: ");
String discount = scanner.nextLine();
if (discount.substring(0,1).equals("t") || discount.substring(0,1).equals("T")){
multi = true;
}
else{
multi =false;
}
Commercial cust = new Commercial(name, phone, address, footage, multi);
//cust.calculateCharges();
}
精慕HU
人到中年有点甜
相关分类