Search code examples
javamethodsmain-method

Where do I add a main method so that I can run this program properly?


I don't know where to add the main method so I can run this class. Help! I'm not sure about where to put the main method either.

This class manages a hair salon. Global variables are used to keep track of dailyRevues (total $ coming in), dailyTax (total tax amount) and the number of hair cuts, permanents and colorings. Also, the number of customers who have been serviced is to be kept track of A daily report is to be printed which gives the total number of customers, the total number of hair cuts, permanents and colorings. Also, the total amount of revenue (money taken in) and tax needs to be printed in the daily report. Finally, the average amount of money spent by each customer should be calculated and printed in the report. If the store brings in $650 or more, then the store manager receives 5% of the daily total revenue as a bonus. You should include the store manager bonus in your report and subtract it from the total revenue to give the net revenue for the day. Feel free to add additional variables and methods as you deem necessary

Here is My Code

 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);
    }
}

 }

Solution

  • In Java, everything is a class. Main methods are written inside the class as such:

    public class Main
    {
        public static void main(String[] args) {
            System.out.println("Hello World");
        }
    }
    

    In your case that'd be:

    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 static void main(String[] args) {
            Salon s = new Salon();
            s.menu();
            // add your code here
        }
        
        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);
            }
        }
    }