ICS 111, Introduction to Computer Science
Lab 11 - Java Calculator - October 14
To receive credit for this lab assignment, you must be finished by
Thursday, October 16, at 11:59 p.m. After this time you will not receive any credit. There will be only one lab this week.Instructions:
1. Login to UNIX
2. Create and edit a Java program called 'LabX.java' (substitute the lab
number for X- where is the number of the lab- such as 'Lab1.java') in Pico
to do the following:
- Write a program that will look like the following:
Simple Java Calculator
Please choose what you want to do by entering the corresponding number:
1. Add two numbers (a + b)
2. Subtract two numbers (a - b)
3. Multiply two numbers (a * b)
4. Divide two numbers (a / b)
5. Exit this program
- You must use switch statements to implement the menu choice selection
- If the user selects 1 then the program will request 2 numbers, add them and print the result. The program should end after this.
- If the user selects 2 then the program will request 2 numbers, subtract them and print the result. The program should end after this.
- If the user selects 3 then the program will request 2 numbers, multiply them and print the result. The program should end after this.
- If the user selects 4 then the program will request 2 numbers, divide the first by the second one, and print the result. If the second number is zero you will not execute the operation and instead you will display an error message (it's impossible to divide by zero). The program should end after this.
- Each one of the operations should be performed in a separate method, therefore the program should have the main method and another 4 methods.
- The four methods will be void since they will perform the task and print the result all together.
- If the user selects 5, then the program will end.
- Have user friendly error messages. "Think" about your error messages so that they tailor to the error.
- Before you submit your code, make sure that your code follows the rules of the Java Coding Standard. Visit this link to look up Java code formatting rules and be sure that your program adheres to these guidelines. At least follow the rules of proper indenting / spacing, making a comment block for classes, making a comment block for methods (main method for this lab), and do some inline commenting to explain what your program is doing. Not doing ALL of these will result in a deduction of points on your lab.
3. Compile and run the program. Be sure to thoroughly test the program after getting it compiled and running to make sure it meets ALL of the requirements above.
4. Get into Pine, and attach the file to an e-mail
5. Send the e-mail / file(s) to the ics111-lab@hawaii.edu account.
6. Check the webpage to make sure that the e-mail arrived. Note that this will be sent to the ICS 111 lab address (ics111-lab@hawaii.edu). This one is different from the ics111-homework@hawaii.edu. There are two different ones so we can have homework assignments and lab assignments separate.
Here is the URL:
http://www2.hawaii.edu/~tp_200/bmf/ics111-lab.html
7. Once I (TA) get the e-mail in my account AND I can verify it on the web, your lab assignment will be graded. For grading policies on your lab, click here...
Link to the Java API - to look up any methods of any class you would like to use.
Link to the Java Coding Standard - to look up Java code formatting rules.