This is your first graded lab. You have one week to complete this lab.
This lab requires you to do two exercises. You are advised to review the material covered in chapters 1 through 4 and read Programming Style, Design and Marking Guidelines before attempting this lab assignment. You should not use syntax or constructs not covered in lectures; you shouldn't need to and may even be penalized for doing so (if the objective of the assignment is undermined). Unless a template is given, you should start each program afresh (ie. don't cut and paste and modify) so that you get sufficient practice with writing a complete Java program.
A word of advice: Code incrementally. Don't try to finish all parts of a program then compile it. Write your program in bits and pieces and compile frequently. Try to maintain a compilable program even while you are working on it. Submitting a compilable program that partially works is better than submitting an un-compilable one. This last point especially applies to the programming exams. Seriously, code incrementally.
The following topic has not been covered and hence you should not use them:
Note that:
For more information on CourseMarker, please refer to CS1101X lab page.
For this lab, the number of submissions is set to 15. For subsequent labs, it may be reduced. Only your last submission will be graded.
If you have any questions, you may post your queries in the IVLE forum of your respective lecture group. Do not post your programs (partial or complete) in the forum before the deadline!
Write a program that checks that a pair of latitude and longitude coordinate point is in Singapore.
You may assume that we use a bounding-box to represent Singapore. A coordinate point is in Singapore if it falls within the range where (1.2427 < lat < 1.4548) AND (103.6271 < long < 103.9993).
Sample run using interactive input (user's input shown in blue; output shown in bold purple):
$ javac LatLong.java $ java LatLong Enter Latitude: 1.3126 Enter Longitude: 103.8634 (1.3126, 103.8634) is in Singapore.
Another sample run is shown below
$ javac LatLong.java $ java LatLong Enter Latitude: 1.1168 Enter Longitude: 103.6272 (1.1168, 103.6272) is not in Singapore.
Submit your program through CourseMarker.
In this exercise, you are to write a simple shopping cart program. Your task is to write a program that accepts up to three sets of input.
Each set of input is an item with item name, cost (in cents) and quantity. After entering the details for each set, the user is prompted if he wants to insert more items (up to two times).
After three items have been entered or when the user has selected not to add more items, the program will print out the total cost in dollars and cents as shown in the sample runs below.
Note that you are not allowed to use arrays in this exercise.
Some lecture groups will only cover repetition structures (loops) this Friday, so you need not use loop for Exercise 2. The exercise is set in such a way that it can be written without using loop (although the code will be slightly longer than one that uses it). However, if you choose to use loop, it is fine too.
While this may seem to be a tough lab, if you work it out step by step and test each part of your code incrementally, you will not have any problems. However if you try to code finish the entire lab without compiling at all, you will definitely have problems.
Hint: Try to first code the data input and output for the FIRST item. After you have done that, check to see that the input and output corresponds to the sample run. If you are successful, code the data entry for the second item and then the third item.
Sample run using interactive input (user's input shown in blue; output shown in bold purple):
$ javac SimpleCart.java $ java SimpleCart Enter item name: Blue Pen Enter cost for each item: 40 Enter quantity: 4 Do you wish to add more items? (y/n): y Enter item name: Ruler Enter cost for each item: 100 Enter quantity: 1 Do you wish to add more items? (y/n): y Enter item name: Eraser Enter cost for each item: 40 Enter quantity: 2 Total: $3.40
Another sample run is shown below:
$ javac SimpleCart.java $ java SimpleCart Enter item name: Blue Pen Enter cost for each item: 40 Enter quantity: 4 Do you wish to add more items? (y/n): n Total: $1.60
Submit your program through CourseMarker.
The deadline for handing in all programs is 10 September 2008, Wednesday, 23:59. Late submissions will NOT be accepted.