Problem Solving Assignment #9
Due Sunday March 10th, 11.59pm for extra credit
Due Monday March 11th, 11:59 pm
Interview Thursday March 14th, 11:59 am
You will be designing and implementing part of a class for this PSA.
This homework requires skills from all Chapters up to Chapter 11.
Note 1: This assignment is to be done individually, without a programming partner.
This homework requires skills from all Chapters up to Chapter 11.
Note 1: This assignment is to be done individually, without a programming partner.
Setup
1) Highlight the following 8 lines with the mouse, right-click to copy:
cd ../public/PSA9
make directories
make install
cd
cd PSA9
ls
mv ParticipantTester.java.empty ParticipantTester.java
mv Participant.java.empty Participant.java
cd ../public/PSA9
make directories
make install
cd
cd PSA9
ls
mv ParticipantTester.java.empty ParticipantTester.java
mv Participant.java.empty Participant.java
Participant -- Write a class that represents a participant in a study. This includes their name, weight, height.
You must put a comment at the top of your code that specifies your: real name, login name, email, and PID, And a two to four sentence description of the program (one description for each program).
Use a multi-line comment (/* */).
Comments Comments in the style detailed in the book ARE required. Your code must be properly commented to receive full credit. (2 points)
IMPORTANT: Code that does not compile and run will receive a 0 on this assignment. It is your responsibility to ensure it compiles and runs properly on lab machines.
Problem
You must put a comment at the top of your code that specifies your: real name, login name, email, and PID, And a two to four sentence description of the program (one description for each program).
Use a multi-line comment (/* */).
Comments Comments in the style detailed in the book ARE required. Your code must be properly commented to receive full credit. (2 points)
IMPORTANT: Code that does not compile and run will receive a low score on this assignment. It is your responsibility to ensure it compiles and runs properly on lab machines.ParticipantIn this assignment you will create a Participant Class. Then you will test your class with a tester application we provide. You should read the descriptions of the Participant class methods below, but then open and read the tester application's main method in detail before you write them (so you understand how your methods will be used.) The Participant class will have the following features:
Private Instance variables (3 points):
For every instance variable - create two methods:
Testing your method (in an application): For this assignment, you MUST use our tester application. Incorrect execution of the tester application will result in a potentially low grade. We recommend you review the testing application prior to starting the assignment - it will help you in understanding what is required.
Use a multi-line comment (/* */).
Comments Comments in the style detailed in the book ARE required. Your code must be properly commented to receive full credit. (2 points)
IMPORTANT: Code that does not compile and run will receive a low score on this assignment. It is your responsibility to ensure it compiles and runs properly on lab machines.ParticipantIn this assignment you will create a Participant Class. Then you will test your class with a tester application we provide. You should read the descriptions of the Participant class methods below, but then open and read the tester application's main method in detail before you write them (so you understand how your methods will be used.) The Participant class will have the following features:
Private Instance variables (3 points):
- name - the name of the participant, of type String
- weight - the weight of the participant in lbs, of type int
- height - the height of the participant in feet, of type double
- One constructor should take in no parameters and set the instance variables to default values. (default name: "Joe Bob", default weight: 1, default height: 1.0).
- One constructor should take in only one parameter (a String to set the name), and set the other two instance variables to their default values.
- One constructor should take an appropriate number of parameters to set every instance variable. If weight or height are not positive, this constructor should print "Incorrect height, height must be positive. Height will be set to default value." or "Incorrect weight, weight must be positive. Weight will be set to default value." and set the weight and height to their default values.
For every instance variable - create two methods:
- 1. a setter which takes an appropriate parameter and sets the appropriate instance variable to the new value. (NOTE: If weight or height are not positive, their set methods should not set the variables to the passed-in values, instead it should print "Incorrect height, height must be positive. Height will not be updated." or "Incorrect weight, weight must be positive. Weight will not be updated." and leave the weight and height to the last value that was stored in them.
- 2. a getter which returns the value of the instance variable.
Testing your method (in an application): For this assignment, you MUST use our tester application. Incorrect execution of the tester application will result in a potentially low grade. We recommend you review the testing application prior to starting the assignment - it will help you in understanding what is required.
- Please note: This simple tester does NOT test for all possible failure conditions. More extensive automated testing is often applied in industry.
Correct Output
> java ParticipantTester
Creating a default participant
Testing correct default name using the getName method
[Correct]
Testing correct default weight using the getWeight method
[Correct]
Testing correct default height using the getHeight method
[Correct]
Testing each set method using a default participant
Testing setName method using the getName method
[Correct]
Testing setWeight method using the getWeight method
[Correct]
Testing setHeight using the getHeight method
[Correct]
Default testing complete
****************************** *********************************************
·
Creating a new participant
Testing correct name using the getName method
[Correct]
Testing correct default weight using the getWeight method
[Correct]
Testing correct default height using the getHeight method
[Correct]
Single parameter constructor testing complete
***************************************************************************
Creating a new participant
Testing correct name using the getName method
[Correct]
Testing correct weight using the getWeight method
[Correct]
Testing correct height using the getHeight method
[Correct]
Three parameter constructor testing complete
***************************************************************************
Testing the toString method
[Correct]
toString testing complete
***************************************************************************
Creating a new participant with negative height
Should print "Incorrect height, height must be positive. Height will be set to default value."
Incorrect height, height must be positive. Height will be set to default value.
[Correct]
Testing setWeight method with negative weight
Should print "Incorrect weight, weight must be positive. Weight will not be updated."
Incorrect weight, weight must be positive. Weight will not be updated.
[Correct]
Creating a new participant with negative weight
Should print "Incorrect weight, weight must be positive. Weight will be set to default value."
Incorrect weight, weight must be positive. Weight will be set to default value.
[Correct]
Testing setHeight method with negative height
Should print "Incorrect height, height must be positive. Height will not be updated."
Incorrect height, height must be positive. Height will not be updated.
[Correct]
Negative height and weight testing complete.
******Minimal testing passed******
>
Creating a default participant
Testing correct default name using the getName method
[Correct]
Testing correct default weight using the getWeight method
[Correct]
Testing correct default height using the getHeight method
[Correct]
Testing each set method using a default participant
Testing setName method using the getName method
[Correct]
Testing setWeight method using the getWeight method
[Correct]
Testing setHeight using the getHeight method
[Correct]
Default testing complete
****************************** *********************************************
·
Creating a new participant
Testing correct name using the getName method
[Correct]
Testing correct default weight using the getWeight method
[Correct]
Testing correct default height using the getHeight method
[Correct]
Single parameter constructor testing complete
***************************************************************************
Creating a new participant
Testing correct name using the getName method
[Correct]
Testing correct weight using the getWeight method
[Correct]
Testing correct height using the getHeight method
[Correct]
Three parameter constructor testing complete
***************************************************************************
Testing the toString method
[Correct]
toString testing complete
***************************************************************************
Creating a new participant with negative height
Should print "Incorrect height, height must be positive. Height will be set to default value."
Incorrect height, height must be positive. Height will be set to default value.
[Correct]
Testing setWeight method with negative weight
Should print "Incorrect weight, weight must be positive. Weight will not be updated."
Incorrect weight, weight must be positive. Weight will not be updated.
[Correct]
Creating a new participant with negative weight
Should print "Incorrect weight, weight must be positive. Weight will be set to default value."
Incorrect weight, weight must be positive. Weight will be set to default value.
[Correct]
Testing setHeight method with negative height
Should print "Incorrect height, height must be positive. Height will not be updated."
Incorrect height, height must be positive. Height will not be updated.
[Correct]
Negative height and weight testing complete.
******Minimal testing passed******
>
How to turnin Homework
1) Open the terminal
2) cd PSA9
3) autograder login -e yourucsdemailhere -p (wait for password prompt)
4) type in your password
5) turnin PSA9
2) cd PSA9
3) autograder login -e yourucsdemailhere -p (wait for password prompt)
4) type in your password
5) turnin PSA9