Read sections 4.1 to 4.7 of the text Computing Concepts with Java Essentials. This covers material on Java's branching statements: if and if-else.
Pay particular attention to Common Error 4.3 and Common Error 4.4 on pages 156-158.
You can safely ignore the material under the "Advanced Topic" headers. In particular, you are not responsible for the ?: operator discussed on page 145 or the switch statement discussed on pages 149-150.
Please note the time that this assignment is due. Because of the exam, you have two weeks to finish this lab. However, we strongly suggest you start this lab early, especially the first two problems. The third problem will require knowledge of applets which you may not be able to do until we cover applets in class and in an in-lab exercise next week.
Note: A second in-lab exercise is now available for practice in the second week of this lab.
There is only one warm-up exercises to be performed in lab this week.
For the in-lab exercise, we are going to start with the same Piglatin example that we worked on in the last class. If you did not finish the in-lab in the last lab, you can ask your AI for a working solution for the pig-latin program.
What were the major things things that were wrong with this piglatin program? Here are a few, at least:
Okay, since a lot of people have been asking aobut the piglatin rules, here they are. I have to honestly admit, even I don't know what exactly piglating does, but here is from what I know:
In the lab, we will fix the first three problems. First thing, of course, would be for you to try the above and see for yourself that the above problems exist. Then find out how if statements come to our rescue to fix this problem.
Name this program Piglet.java and submit it by sending an email to a201@cs.indiana.edu with a subject that will be given to you in class.
NOTE: Next week we are going to post another in-lab exercise that will also apply to this assignment in the Assignments page.
Please take care to use the exact filenames specified in the problems below. Note that the proper extention on filenames is .java, not .Java.
Name this program Smartpiglet.java
This program can be written rather straight-forwardly as follows:
if (letterGrade.equals("A+"))
System.out.println(4.0);
else if (letterGrade.equals("A"))
System.out.println(4.0);
else if (letterGrade.equals("A-"))
System.out.println(3.7);
else if (letterGrade.equals("B+"))
System.out.println(3.3);
// and so on...
However, that is not very interesting. The purpose of this exercise is to get more practice using variables, and to write some more complicated branching conditions.
You must use the following algorithm as a model for your code:
Save your program in a file named Lettergrade.java.
For the Ambitious This is not part of the basic assignment, so students can certainly earn a grade of B on this lab without doing this part.
After you have completely implemented the above algorithm, go back and put in some error checking. That is, if the user input is "F+" or "F-" or "I" or "A!" or "A+++", then print a suitable error message, perhaps something of the form:
Notice that the user input is echoed in the error message exactly as it was entered. If the user enters a grade of "VeryGood", you should print a message like this:
not like this:
Don't bother implementing this error checking unless your basic program is working perfectly!
Write a graphics applet that asks the user to specify two circles. Each circle is input by clicking on the center and then clicking on a point on the circle. Draw the two circles filled with the same color. After the center point of each circle is given by the user, draw the point. Now, if the two circles intersect, display the message "Circles Intersect" (in some other color) at the center of the canvas. Otherwise, display "Circles Don't Intersect".
Hints:
Save your program in a file named Intersect.java.
You can look at a working demonstration of this program.
For this lab, you should submit three files:
Do not submit .prj, .class or .html files. Only the files named above should be submitted.
In order to submit files, click on the following link to send mail to:
with the following Subject:
and then Attach your program files to the e-mail message. You may attach multiple files in the same message, but you don't have to. You can submit your programs in separate e-mails if you wish. Do not type anything in the body of the message! You must use the filenames specified in this assignment and you must attach the files to the mail message.