Question: Create the following: A constructor that takes no parameters. Have the program print out Enter 1 or 2 and then save the input from the

  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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!