1. Engineering
  2. Computer Science
  3. create the following a constructor that takes no parameters have...

Question: create the following a constructor that takes no parameters have...

Question details
  1. Create the following:

    1. A constructor that takes no parameters. Have the program print out “Enter 1 or 2” and then save the input from the scanner into the instance variable you created above. If the user enters 1 make a call to the tipCalculator method and of the user enters 2 make a call to the chnageMachine method.

// Code to be placed in the constructor

System.out.println("Enter 1 or 2");

input = scan.nextInt();

if (input == 1) {
    tipCalculator();
} else if (input == 2) {
    changeMachine();
}


  1. A method called tipCalculator that takes no parameters. This method will calculate the tip and total bill based on user input and print the correct result.

Example of output (Input in blue)

Enter 1 or 2

1

Enter bill amount:

104.5

Percentage to tip:

20

Number of people:

4

Tip amount: $20.9

Total amount: $125.4

Tip per person: $5.23

Total per person: $31.35

  1. A method called changeMachine that takes no parameters. This method will calculate the change due and the appropriate coins that would be received base on user input.

Example of output (Input in blue)

Enter 1 or 2

2

Total amount?

15.43

Cash Payment?

100

Change Due $84.57

Dollars: 84

Quarters: 2

Dimes: 0

Nickels: 1

Pennies: 2


  1. A main method that makes a call to the InputOutput class to begin the program

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution