Question: In this assignment, you will practice designing a more complex class, using while loops, using conditionals, using a Scanner object and mathematical expressions. ----------------------------------------------------------- For

In this assignment, you will practice designing a more complex class, using while loops, using conditionals, using a Scanner object and mathematical expressions.

-----------------------------------------------------------

For this assignment, you will write a class for the game Pig. Your file should be called DinnerOutLASTNAME.java where LASTNAME is replaced with your last name (notin all capital letters). Be sure to name your class and constructor according to this file name.

The class will contain the following attributes:

  • n (number of people in the dinner party)
  • person1, person2, person3, person4, person5, person6
  • tax
  • tip
  • amount1, amount2, amount3, amount4, amount5, amount6
  • scan (a Scanner object)

The "person" variables should point to the names of the people in the dinner party and the amounts should correspond to their totals.

The code should do the following:

  1. Ask the user how many people are in the party (if they enter more than 6, let them know 6 is the maximum and set n = 6)
  2. Ask the user to provide names for each person
  3. Ask the user to enter the cost of each item in the bill corresponding to the person. It should allow them to enter as many items as they like. If the user wishes to stop, they can indicate this by entering 0.
  4. Ask the user for the tax
  5. Ask the user for the tip
  6. Display the totals each person owes.

You are allowed to organize your code however you like. The code should have a constructor and as toString() method. The toString method should print out the amounts owed by each member of the dinner party. Attached is a printup of one way this could work.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Heres an implementation of the Pig class according to your requirements import javautilScanner public class DinnerOutSmith private int n private Strin... View full answer

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 Programming Questions!