Due Tuesday, January 30 at 11:59 PM
By the time you have completed this work, you should be able to:
int
and String
int
) or strings (String
)
Download the lab2questions.txt
file, and edit it with a text editor of your choice.
Answer the questions in the file.
Be sure to use the appropriate formatting.
Save your work in your own local copy of lab2questions.txt
.
Be sure to preserve the filename and file type!
SquawkParrot.java
Download the SquawkParrot.java
file, and open it in jGrasp (or a text editor of your choice).
The file contains a program which is intended to behave very similarly to Parrot.java
, except that it should print out some extra text before and after the user input.
An example which illustrates this is shown below, with user input shown in bold:
Enter something to repeat: pretty bird BRAAWK pretty bird!
Another example follows:
Enter something to repeat: apple BRAAWK apple!
One more example:
Enter something to repeat: some words BRAAWK some words!
You will need to use a variable to save exactly what the user typed in.
You should only write a single System.out.println
statement at the end of your code.
With this in mind, you'll need to use string concatenation to create a big string to print (e.g., “BRAAWK pretty bird!” above), and then print it with a single System.out.println
statement.
Note that you will need a string which contains only a single character, namely “!” (the sentence you print ends with an exclamation point).
For full credit, the output of your program must match EXACTLY to the output shown above. That is, it should start with “BRAAWK”, followed by a space, followed by the user input, followed by an exclamation point.
PerimeterCalculation.java
For this task, you need to write a program that will calculate the perimeter of a rectangle. The user will give the program the width and height of the rectangle, and the program will print out the computed perimeter. An example which illustrates this is shown below, with user input shown in bold:
Enter width: 2 Enter height: 3 Perimeter: 10
In order to write this program, you will need to use variables to save the entered width and height values, Scanner
to read integers, compute the result, and print the result with System.out.println
.
You will also need to use System.out.println
to print the user prompts for width and height.
As a hint, your code will look very similar to the AddTwo.java
program from lecture.
For full credit, the output of your program must match EXACTLY to the output shown above.
Log into Canvas, and go to the COMP 110L class. Click “Assignments” on the left pane, then click “Lab 2”. From here, you can upload your answers and your code. Specifically, you must turn in the following three files:
lab2questions.txt
SquawkParrot.java
PerimeterCalculation.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 three files.
You can turn in the assignment multiple times, but only the last version you submitted will be graded.