Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Program Requirements A party planner needs to do calculations for an event, base

ID: 3710528 • Letter: P

Question

Program Requirements A party planner needs to do calculations for an event, based on the number of guests and the size of tables. Class files are PartyPlanner.java and Party.java Documentation: Only the top of file descriptions an author tags are required for this program. Test 1 (5 pts) Within the PartyPlanner class Write the code to read the number of guests and table capacity (i.e. number of people that each table will hold) from the user as integers After reading the first input, display a "Guest input valid integer" message After reading the second input, display a "Table input valid integer" message Example Enter number of guests: 10 Guest input valid integer Enter capacity of one table: Table input valid integer Tests 2 through 4 (10 pts, 10 pts, 5 pts) Within the PartyPlanner class: Add an exception handler that includes o A trv block around the code that reads the user inputs If no exception is thrown after reading the first input, display the same "Guest input valid integer" message as before If no exception is thrown after reading the second input, display the same "Table input valid integer" message as before o A catch block to catch the InputMismatchException thrown if the user does not enter an integer for one of the inputs . The catch block should display "Error - did not enter an integer value" Test 5 (10 pts) Within the Party class . Add a constructor that has parameters for both data fields Add getters for both data fields

Explanation / Answer

Here is Solution >>>>>>

<<<<<<<<<<<<<<<<<< Party.java starts here >>>>>>>>>>>>>>>>>

package com.test.test2;

public class Party {

private int numGuests;

private int tableCapacity;

//Constructor

public Party(int numGuests, int tableCapacity) {

this.numGuests = numGuests;

this.tableCapacity = tableCapacity;

}

// getters and setters

public int getNumGuests() {

return numGuests;

}

public void setNumGuests(int numGuests) {

this.numGuests = numGuests;

}

public int getTableCapacity() {

return tableCapacity;

}

public void setTableCapacity(int tableCapacity) {

this.tableCapacity = tableCapacity;

}

public int calcFullTables() {

if(this.numGuests < 0 || this.tableCapacity < 0) {

throw new IllegalArgumentException("Error - can not compute tables using negative value(s)");

}

return this.numGuests/this.tableCapacity;

}

}

<<<<<<<<<<<<<<<<<< Party.java ends here >>>>>>>>>>>>>>>>>

<<<<<<<<<<<<<<<<<< PartyPlanner.java starts here >>>>>>>>>>>>>>>>>

package com.test.test2;

import java.util.InputMismatchException;

import java.util.Scanner;

public class PartyPlanner {

public static void main(String[] args) {

int guests,tables;

Scanner in = new Scanner(System.in);

try {

System.out.println("Enter num1ber of guests:");

guests = in.nextInt();

System.out.println("Guest input valid integer");

System.out.println("Enter capacity of one table:");

tables = in.nextInt();

System.out.println("Table input valid integer");

//Creating Object

Party party = new Party(guests, tables);

int result = party.calcFullTables();

//displaying result

System.out.println(result+" full table(s) needed for party of "+party.getNumGuests() +" guests");

}catch (InputMismatchException e) {

System.out.println("Error - did not enter an integer value");

e.printStackTrace();

}catch (ArithmeticException e) {

System.out.println("Error - can not determine number of tables when table capacity is 0");

e.printStackTrace();

}catch (IllegalArgumentException e) {

System.out.println(e.getMessage());

e.printStackTrace();

}catch (Exception e) {

e.printStackTrace();

}

}

}

<<<<<<<<<<<<<<<<<< PartyPlanner.java ends here >>>>>>>>>>>>>>>>>

<<<<<<<<<<<<<<<<<< Output for different taest cases>>>>>>>>>>>>>>>>>

1).

Enter num1ber of guests:
10
Guest input valid integer
Enter capacity of one table:
2
Table input valid integer
5 full table(s) needed for party of 10 guests

2).

Enter num1ber of guests:

10

Guest input valid integer

Enter capacity of one table:

a

Error - did not enter an integer value

java.util.InputMismatchException

at java.util.Scanner.throwFor(Scanner.java:864)

at java.util.Scanner.next(Scanner.java:1485)

at java.util.Scanner.nextInt(Scanner.java:2117)

at java.util.Scanner.nextInt(Scanner.java:2076)

at com.test.test2.PartyPlanner.main(PartyPlanner.java:17)

3).

Enter num1ber of guests:

-10

Guest input valid integer

Enter capacity of one table:

-2

Table input valid integer

Error - can not compute tables using negative value(s)

java.lang.IllegalArgumentException: Error - can not compute tables using negative value(s)

at com.test.test2.Party.calcFullTables(Party.java:34)

at com.test.test2.PartyPlanner.main(PartyPlanner.java:22)

4).

Enter num1ber of guests:

10

Guest input valid integer

Enter capacity of one table:

0

Table input valid integer

Error - can not determine number of tables when table capacity is 0

java.lang.ArithmeticException: / by zero

at com.test.test2.Party.calcFullTables(Party.java:37)

at com.test.test2.PartyPlanner.main(PartyPlanner.java:22)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote