Lab 6: Working with Multiple Files and an Introduction to Objects


Due Sunday, February 18 at 11:59 PM

Goals for This Lab

By the time you have completed this work, you should be able to write programs which:

Provided files:

Step-by-Step Instructions

Step 1: Edit PrintString.java

Download the PrintString.java file, and open it in jGrasp (or a text editor of your choice). You will need to define a static method that prints out a given String, without modifying the main method. When you run this program, you should see the following output:

foo      

Further details are provided in the comments of the file.

Step 2: Edit PrintInt.java

Download the PrintInt.java file, and open it in jGrasp (or a text editor of your choice). You will need to define a static method that prints out a given int, without modifying the main method. When you run this program, you should see the following output:

57      

Further details are provided in the comments of the file.

Step 3: Edit PrintMain.java

Download the PrintMain.java file, and open it in jGrasp (or a text editor of your choice). You will need to write code in main that calls the methods you defined in PrintString.java and PrintInt.java, with specific actual parameters. Example output of this program is shown below:

bar
98

Do not simply print out "bar" and 98! Solutions which merely print these values directlt will receive no credit. You must instead call printString and printInt.

Step 4: Edit TwoDoubles.java

Download the TwoDoubles.java file, and open it in jGrasp (or a text editor of your choice). This file requires you to write a class containing two instance variables, a constructor, and an instance (non-static) method. This file already contains a main method, which can be used to test your code. The main method reads two values of type double from the user, which are used to call your TwoDoubles constructor. It will then call your printMe method on the created object. Example output is shown below, with user inputs shown in bold:

Enter first double: 2.5
Enter second double: 3.8
First: 2.5
Second: 3.8

Further details are provided in the comments in the file.

Step 5: Edit TwoOperations.java

Download the TwoOperations.java file, and open it in jGrasp (or a text editor of your choice). You will have to define two static methods which will use your TwoDoubles class you defined in the previous step, as well as defining a main method which will call the aforementioned methods. Example output is shown below, with user inputs shown in bold:

Enter first double: 2.2
Enter second double: 8.9
First: 19.580000000000002
Second: 0.24719101123595508
First: -6.7
Second: 11.100000000000001

Further details are provided in the comments in the file.

Step 6: Turn in Your Solution Using Canvas

Log into Canvas, and go to the COMP 110L class. Click “Assignments” on the left pane, then click “Lab 6”. From here, you can upload your answers and your code. Specifically, you must turn in the following five files:

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.