【发布时间】:2021-01-18 14:14:29
【问题描述】:
我不知道在哪里添加 main 方法以便我可以运行这个类。帮助!我也不确定 main 方法应该放在哪里。
这个班级管理一家美发沙龙。全局变量用于跟踪dailyRevues(进来的总美元)、dailyTax(总税额)和剪发次数、烫发次数和染发次数。此外,将跟踪服务过的客户数量 将打印一份每日报告,其中提供客户总数、理发总数、烫发次数和染发次数。此外,需要在每日报告中打印收入(收入)和税收总额。最后,应计算每个客户平均花费的金额并将其打印在报告中。如果商店带来 650 美元或更多,那么商店经理将获得每日总收入的 5% 作为奖金。您应该在您的报告中包含商店经理奖金,并将其从总收入中减去,以得出当天的净收入。随意添加您认为必要的其他变量和方法
这是我的代码
import java.util.Scanner;
public class Salon {
See example report*/
//Globals
Scanner input = new Scanner(System.in);
int hairCuts = 0;
int permanents = 0;
int colorings = 0;
int customers = 0;
double dailyRev = 0;
double total = 0;
double dailyTax = 0;
double bonus; //money due the manager if certain conditions are met
final double COSTHC = 20; //Cost of HairCut
final double COSTPERM = 50; //Cost of Permanent
final double COSTCOLORING = 60; //Cost of Coloring
final double COSTHC_PERM = (COSTHC * 0.85) + (COSTPERM * 0.85); //Cost of Haircut and Permanent
final double COSTCOL_PERM = (COSTPERM * 0.85) + (COSTCOLORING * 0.85); //Cost of Perm and Coloring
final double COSTHC_COL = (COSTHC * 0.85) + (COSTCOLORING * 0.85); //Cost of Haircut and Coloring
final double COSTHC_PERM_COL = (COSTHC * 0.85) + (COSTPERM * 0.85) + (COSTCOLORING * 0.85); //Cost of Cut, Perm and Color
public void menu() {
//preconditions: none
//postconditions: the correct method is called depending on the user's
//input, totalValues are updated appropriately
int choice;
do {
System.out.println("---------MENU---------");
System.out.println("1 = Reset Daily Totals");
System.out.println("2 = Haircut Only");
System.out.println("3 = Permanent Only");
System.out.println("4 = Coloring Only");
System.out.println("5 = Haircut and Coloring");
System.out.println("6 = Haircut and Permanent");
System.out.println("7 = Permanent and Coloring");
System.out.println("8 = Haircut, Permanent and Coloring");
System.out.println("9 = Print Daily Report");
System.out.println("10 = Exit");
choice = input.nextInt();
if (choice == 10) {
System.exit(0);
}
if (choice == 1) {
resetTotals();
}
if (choice == 2) {
hairCuts++;
customers++;
dailyRev = dailyRev + COSTHC;
dailyTax = 0.07 * dailyRev;
total = dailyRev + dailyTax;
System.out.println("Haircut only: $");
System.out.println("Charge: $" + dailyRev);
System.out.println("Tax: $" + dailyTax);
System.out.println("Total: $" + total);
}
if (choice == 3) {
permanents++;
customers++;
dailyRev = dailyRev + COSTPERM;
dailyTax = 0.07 * dailyRev;
total = dailyRev + dailyTax;
System.out.println("Permanent only: $");
System.out.println("Charge: $" + dailyRev);
System.out.println("Tax: $" + dailyTax);
System.out.println("Total: $" + total);
}
if (choice == 4) {
colorings++;
customers++;
dailyRev = dailyRev + COSTCOLORING;
dailyTax = 0.07 * dailyRev;
total = dailyRev + dailyTax;
System.out.println("Coloring only: $");
System.out.println("Charge: $" + dailyRev);
System.out.println("Tax: $" + dailyTax);
System.out.println("Total: $" + total);
}
if (choice == 5) {
hairCuts++;
colorings++;
customers++;
dailyRev = dailyRev + COSTHC_COL;
dailyTax = 0.07 * dailyRev;
total = dailyRev + dailyTax;
System.out.println("Haircut and Coloring: $");
System.out.println("Charge: $" + dailyRev);
System.out.println("Tax: $" + dailyTax);
System.out.println("Total: $" + total);
}
if (choice == 6) {
hairCuts++;
permanents++;
customers++;
dailyRev = dailyRev + COSTHC_PERM;
dailyTax = 0.07 * dailyRev;
total = dailyRev + dailyTax;
System.out.println("Haircut and Permanent: $");
System.out.println("Charge: $" + dailyRev);
System.out.println("Tax: $" + dailyTax);
System.out.println("Total: $" + total);
}
if (choice == 7) {
permanents++;
colorings++;
customers++;
dailyRev = dailyRev + COSTCOL_PERM;
dailyTax = 0.07 * dailyRev;
total = dailyRev + dailyTax;
System.out.println("Coloring and Permanent: $");
System.out.println("Charge: $" + dailyRev);
System.out.println("Tax: $" + dailyTax);
System.out.println("Total: $" + total);
}
if (choice == 8) {
hairCuts++;
colorings++;
permanents++;
customers++;
dailyRev = dailyRev + COSTHC_PERM_COL;
dailyTax = 0.07 * dailyRev;
total = dailyRev + dailyTax;
System.out.println("haircut, Coloring, and Permanent: $");
System.out.println("Charge: $" + dailyRev);
System.out.println("Tax: $" + dailyTax);
System.out.println("Total: $" + total);
}
if (choice == 9) {
printReport();
}
} while (true);
}
public void resetTotals() {
hairCuts = 0;
permanents = 0;
colorings = 0;
customers = 0;
dailyRev = 0;
dailyTax = 0;
}
public void printReport() {
if (customers == 0) {
return;
}
System.out.println("Daily Report for Salon");
System.out.println("Number of Customers: $" + customers);
System.out.println("Number of Hair Cuts: $" + hairCuts);
System.out.println("Number of Permanents: $" + permanents);
System.out.println("Number of Colorings: $" + colorings);
System.out.println("Average amount spent per customer(Not including Tax): $" + (total / customers));
System.out.println("Total Revenues: $" + dailyRev);
System.out.println("Total Tax: $" + dailyTax);
if (dailyRev >= 650) {
System.out.println("Manager Bonus: $" + (dailyRev * 0.05));
System.out.println("Total Net Revenues: $" + 1.05 * dailyRev);
} else {
System.out.println("Manager Bonus: $0");
System.out.println("Total Net Revenues: $" + dailyRev);
}
}
}
【问题讨论】:
-
Java 之于 Javascript 就像 Pain 之于绘画,或者 Ham 之于仓鼠。它们完全不同。强烈建议有抱负的程序员尝试学习他们尝试编写代码的语言的名称。当您发布问题时,请适当地标记它 - 这可以让那些了解您需要帮助的语言的人看到您的问题。
-
很抱歉。 \-_-/
标签: java methods main-method