if
...else if
...else
With TestingDue Friday, October 21 at 11:59 PM
By the time you have completed this work, you should be able to:
if
...else if
...else
to write code which handles multiple conditionsif
...else if
...else
Guess.java
GuessTest.java
CompareNums.java
CompareNumsTest.java
LetterGrade.java
LetterGradeTest.java
collaborators.txt
Guess.java
Download the Guess.java
file, and open it in jGrasp (or a text editor of your choice).
This program will ask the user to guess a number between 0
and 2
inclusive, and will report if the user's guess is the same as some number the computer chose.
A caveat is that while the computer is choosing a “random” number, it always chooses 0
when run interactively, as it will always use the same “seed” value of 123456
.
Example output of the program is shown below, with user input shown in bold:
Guess a number between 0 and 2, inclusive: 1 Guess was incorrect. The correct guess was: 0
Further example output of the program is shown below, with user input shown in bold:
Guess a number between 0 and 2, inclusive: 0 Guess is correct!
GuessTest.java
as a Test File
Download the GuessTest.java
file, being sure to put it in the same folder/directory as your Guess.java
file.
This file contains a number of tests for the method you wrote in the previous step.
Open this file in jGrasp as a test file, using the same instructions you've used in previous labs.
Run the tests in the file.
Your code should pass all the tests.
If your code does not pass all of the tests, edit your code in Guess.java
until you can get all the tests to pass.
You do not need to write any of your tests in GuessTest.java
.
CompareNums.java
Download the CompareNums.java
file, and open it in jGrasp (or a text editor of your choice).
You will need to implement a method that returns different String
s, depending on the input values the method receives.
You may not modify the code in the main
method.
Example output of the program is shown below, with user input shown in bold:
Enter first integer: 1 Enter second integer: 2 The first integer is less than the second integer.
Further example output of the program is shown below, with user input shown in bold:
Enter first integer: 1 Enter second integer: 1 The first integer is equal to the second integer.
Further example output of the program is shown below, with user input shown in bold:
Enter first integer: 2 Enter second integer: 1 The first integer is greater than the second integer.
CompareNumsTest.java
as a Test File, and Edit It
Download the CompareNumsTest.java
file, being sure to put it in the same folder/directory as your CompareNums.java
file.
This file contains a number of tests for the method you wrote in the previous step.
Open this file in jGrasp as a test file, using the same instructions you've used in previous labs.
You need to write a number of tests in this file, and all of them must pass.
The comments in the file provide more details.
LetterGrade.java
Download the LetterGrade.java
file, and open it in jGrasp (or a text editor of your choice).
You will need to implement a method that takes a percentage between 0.0
and 100.0
, and returns the appropriate letter grade as a String
(e.g., “A”, “A-”, “B+”, etc.).
The letter grade assignment should be based on the table in the second page of the syllabus.
You may not modify the code in the main
method.
Example output of the program is shown below, with user input shown in bold:
Enter grade as percentage: 92.8 Letter grade: A
Further example output of the program is shown below, with user input shown in bold:
Enter grade as percentage: 79.4 Letter grade: C+
LetterGradeTest.java
as a Test File, and Edit It
Download the LetterGradeTest.java
file, being sure to put it in the same folder/directory as your LetterGrade.java
file.
This file contains a number of tests for the method you wrote in the previous step.
Open this file in jGrasp as a test file, using the same instructions you've used in previous labs.
You need to write a number of tests in this file, and all of them must pass.
The comments in the file provide more details.
Log into Canvas, and go to the COMP 110 class. Click “Assignments” on the left pane, then click “Lab 9”. From here, you can upload your answers and your code. Specifically, you must turn in the following five files:
Guess.java
CompareNums.java
CompareNumsTest.java
LetterGrade.java
LetterGradeTest.java
In addition, if you collaborated with anyone else, be sure to download collaborators.txt
and write the names of the people you collaborated with in the file, one per line.
Please submit this file along with the other five files.
You can turn in the assignment multiple times, but only the last version you submitted will be graded.