Students, please be sure to log in. This site does not use cookies and cannot store work submitted when not signed in.

Unit 5 Problems

Party

The Party class contains the updateNumOfPeople method, which is intended to update the instance variable numOfPeople under certain conditions and return a value indicating whether the update was successful. If adding additional people to the current number of people would lead to the number going over the capacity, then the update would be unsuccessful. Otherwise, if adding the number of additional people is still below or at capacity, the update is successful.

What can you add to replace /*missing code */  to ensure that the updateNumOfPeople method works as intended?

Example Runs:

Block of Code
Output
Party p = new Party(3, 4);
System.out.println(p.updateNumOfPeople(1));
System.out.println(p.getNumofPeople());
true
4

Party p = new Party(3, 4);
System.out.println(p.updateNumOfPeople(2));
System.out.println(p.getNumofPeople());
false
3

Type your solution        
Skills Practiced:
3.B
4.A
4.B
Copyright © StudyCS 2024 All rights reserved.