Lab 15 - April 1


To receive credit for this lab assignment, you must be finished by Friday, April 4, at 10:00 p.m. After this time you will not receive any credit.



1.  Login to UNIX, and write a program to do the following:

Read two integer numbers from the user. These numbers will be your indexes inside of the for loops in the pseudo-code.

Verify that it is a positive integer number by using try and if statements.

Write four methods for adding, subtracting, multiplying and dividing.  These methods should be passed two numbers (indexes of the for loops), and return the result of adding, subtracting, multiplying or dividing.

Use the following (poorly written) pseudo-code as a base to start your program:

class {
    main {
        try {
            Parse input 1
            if (input1 > 0){
                try {
                    Parse input 2
                    if (input2 > 0) {
                        for (int i = 0; i < input1; i++) {
                            for (int j = 0; j<input2; j++) {
                                print ("Adding: " +i+ " plus " +j+ " equals: " +add (i, j) +"\t");
                                print ("Subtracting: " +i+ " from " +j+ " equals: " +sub (i, j) +"\t");
                                print ("Multiplying: " +i+ " times " +j+ " equals: " +mult (i, j) +"\t");
                                if (j != 0) {
                                    print ("Dividing: " +i+ " over " +j+ " equals: " +div (i, j) +"\t");
                catch for input 2
            catch for input 1

    add method {

    sub method {

    mult method {

    div method {

The above code should read two numbers from the user, and then enter nested for loops to add, subtract, multiply and divide. You may play around with the print / println statements to format the output however you would like it displayed.

Follow the Java Coding Standard for this lab.  The program should be fairly straightforward- most of the design is already done above.

2.  Make sure your program follows the Java Coding Standard.  The goal of this lab is for you to learn and practice the Java Coding Standard.  This lab will be graded according to the Java Coding Standard, and any mistakes will cost you your point for the lab.  Be sure your code has proper formatting, and all comments / comment blocks are done as specified by the Java Coding Standard. Be sure to follow all spacing and capitalization guidelines (including variable names), and make sure your program does the 'Version control' exemplified at the bottom of the Java Coding Standard web page. The Java Coding Standard that you are required to follow can be found here:

3.  Send an e-mail in Pine and attach your program to the e-mail.  Send to the account.  Make sure the subject is 'lab 15'.

4.  Check the webpage to make sure that the e-mail arrived.  Here is the URL:

5.  Once I (TA) get the e-mail in my account AND I can verify it on the web, you will receive your lab participation point.


Link to the Java API -  to look up any methods of any class you would like to use.