1. Homepage
  2. Programming
  3. COMPS201 Computing Fundamentals with Java: Assignment 02: Backpack, Conversion

COMPS201 Computing Fundamentals with Java: Assignment 02: Backpack, Conversion

Engage in a Conversation
HKMUCOMPS201Computing Fundamentals with JavaJava

Assignment 02 CourseNana.COM

  CourseNana.COM

  CourseNana.COM

Information CourseNana.COM

The marks allocated to each question are given in brackets in the right margin. CourseNana.COM

  CourseNana.COM

Instructions for Assignment CourseNana.COM

  CourseNana.COM

The answers to this assignment need to be prepared by a word processor. You can use MS Word or Open Office. Please show all your work for all questions. This will give your tutor an opportunity to award you some marks for partially correct answers. CourseNana.COM

  CourseNana.COM

Important CourseNana.COM

  CourseNana.COM

1.   ALL assignments will be used for assessment purposes and any missing ones will gain zero mark. For example, if you get 70, 60, 0 (missing), and 50 in Assignments 01, 02, 03 and 04 respectively, the average is (70+60+0+50)/4 = 45 and it is a pass for assignments. Normally failing to get an average of 40 marks in assignments means you will fail this course and you need to pay again to retake it. CourseNana.COM

2.   Please backup your answer file against system failure. CourseNana.COM

3.   In providing your answers, you should state clearly which question/part you are answering (in your answer file). Marks will be deducted if you do not do so. CourseNana.COM

  CourseNana.COM

CourseNana.COM

Question 1 [20 marks]
CourseNana.COM

  CourseNana.COM

You should be able to answer this question after you have completed Units 1 to 3. This is a question to consolidate important concepts learnt in these units and Assignment 01. CourseNana.COM

  CourseNana.COM

(a) Learning debugging is important if you like to be a programmer. To verify a program is doing what it should, a programmer should know the expected (correct) values of certain variables at specific places of the program. Therefore make sure you know how to perform the instructions by hand to obtain these values. Remember, you should master the technique(s) of debugging. CourseNana.COM

  CourseNana.COM

Create a new project Assignment02 in NetBeans and copy the following program into a new Java class. The author of the program intends to find the sum of the numbers 2, 7 and 12. CourseNana.COM

  CourseNana.COM

public class Assignment02Q1a { CourseNana.COM

    public static void main(String[] args) {         int from = 2;         int to = 12;         int sum = 0; CourseNana.COM

  CourseNana.COM

        for (int i=from; i<to; i++) {   // (1) CourseNana.COM

            sum += i;   // (2) CourseNana.COM

        } CourseNana.COM

  CourseNana.COM

        System.out.println("The sum is "+sum); CourseNana.COM

    } CourseNana.COM

} CourseNana.COM

  CourseNana.COM

(i) CourseNana.COM

Run the program. What is the output? CourseNana.COM

  CourseNana.COM

(ii) CourseNana.COM

What is the expected value of sum just before the for loop is executed? CourseNana.COM

  CourseNana.COM

(iii) CourseNana.COM

Write down the three expected intermediate sums after the integers 2, 7 and 12 are added one by one (in the given order) to an initial value of one. CourseNana.COM

  CourseNana.COM

(iv) CourseNana.COM

Since we have only a few executable statements here, the debugging is not difficult. Insert a System.out.println() statement just after the statement indicated by the comment "// (2)" to print out sum. What are the values of sum printed (press Ctrl-C to stop the program if necessary)? CourseNana.COM

  CourseNana.COM

(v) CourseNana.COM

What modification(s) is/are needed to make the program correct? CourseNana.COM

  CourseNana.COM

NetBeans allows you to view the values of variables at specific points (called breakpoints). This saves you the effort of inserting/removing println() statements. Again, you must know the expected (correct) values of those variables at the breakpoints. If you like, you can try to explore the use breakpoints yourself. CourseNana.COM

[8 CourseNana.COM

              CourseNana.COM

  CourseNana.COM

(b) The following is about creating a class Backpack and testing it. In every part, correct any syntax errors indicated by NetBeans until no such error messages. CourseNana.COM

  CourseNana.COM

(i) CourseNana.COM

Create a class Backpack with the attributes brand and volume. The attributes are used to store the brand and the volume of the backpack respectively. Choose suitable types for them. Copy the content of the file as the answers to this part. No screen dump is recommended to minimize the file size. CourseNana.COM

  CourseNana.COM

(ii) CourseNana.COM

Add a method setVolume() to the Backpack class with appropriate parameter(s) and return type to set the volume of the backpack. Copy the content of the method as the answers to this part. CourseNana.COM

  CourseNana.COM

(iii) CourseNana.COM

Add another method getBrand() to the Backpack class with appropriate parameter(s) and return type to get the brand of the backpack. Copy the content of the method as the answers to this part. You should create other setter/getter methods in your class file but no marks are allocated for them since they are similar to the ones here and in part (ii). CourseNana.COM

  CourseNana.COM

(iv) CourseNana.COM

Write a method capacity() which returns the category of the backpack as a string using an ifthen-else or switch-case statement. The category of the backpack is determined by the following table. CourseNana.COM

  CourseNana.COM

Capacity CourseNana.COM

Volume CourseNana.COM

"Large" CourseNana.COM

Not less than 50 CourseNana.COM

"Medium" CourseNana.COM

20 to less than 50 CourseNana.COM

"Light" CourseNana.COM

Less than 20 CourseNana.COM

  CourseNana.COM

Copy the content of the method as the answers to this part. CourseNana.COM

  CourseNana.COM

(v) CourseNana.COM

Create another class TestBackpack with a method main() to test the class Backpack. In main(), create a backpack object backpackA and print the message "An object backpackA of class Backpack has been created". Run the program. Copy the content of the file and the output showing the message as the answers to this part. CourseNana.COM

  CourseNana.COM

(vi) CourseNana.COM

In the class TestBackpack, add the following before the end of main(): CourseNana.COM

1.     Display a dialog box (see the bottom of p.35 of Unit 3 for an example of such a dialog box) which contains the message "Input a value for volume (>0)". CourseNana.COM

2.     Assume the input is a number, check if it is less than or equal to zero. If so, display the message "Volume must be > 0" in another dialog box (see the second dialog box on p.36 for an example) and go to 1. CourseNana.COM

3.     Set the volume of backpackA to the input volume. CourseNana.COM

4.     Make use of the method category(), print the category of backpackA. CourseNana.COM

  CourseNana.COM

Run the program and input 42 in step 2. Copy the content of the class and the output as the answers to this part. CourseNana.COM

  CourseNana.COM

Remember to add a suitable import statement since dialog boxes are used. CourseNana.COM

[12] CourseNana.COM

  CourseNana.COM

  CourseNana.COM

              CourseNana.COM

Question 2 [30 marks]

  CourseNana.COM

You should be able to answer this question after you have completed Unit 4. CourseNana.COM

  CourseNana.COM

(a)     Write a class DialogBox containing the following methods: CourseNana.COM

  CourseNana.COM

(i) CourseNana.COM

inputJPYAmount() : which displays a dialog box asking user to "Input the JPY Amount: " and finally returns the input as a real number. CourseNana.COM

  CourseNana.COM

  CourseNana.COM

Before the returning the input, ask the user to confirm using a dialog box, which contains "The input is: <user input>, is it correct?", where "<user input>" is the input of the user. If the user does not confirm "Yes", return zero. Copy the class, including import statement(s), as the answers to this part. CourseNana.COM

  CourseNana.COM

 (ii) CourseNana.COM

checkJPYAmount() : which calls inputJPYAmount() to get the JPY amount to check and nothing is returned. The JPY amount should be greater than zero. If not so, display the error message "The JPY amount should be greater than zero" and then call inputJPYAmount() to get the JPY amount again until it is correct. You need to use a loop to achieve this. Copy the method as the answer to this part. CourseNana.COM

  CourseNana.COM

 (iii) CourseNana.COM

main() : which creates a DialogBox object and calls the method checkJPYAmount() for testing. Copy the method as the answer to this part. CourseNana.COM

[10]              CourseNana.COM

  CourseNana.COM

(b)     Write a class Conversion containing the following methods: CourseNana.COM

  CourseNana.COM

(i) CourseNana.COM

Constructor : which builds the frame shown on the right side. The frame consists of a text field for inputting a JPY amount, a label with 10 spaces for an equivalent JPY amount in USD, and a button to start the calculation. Declare any necessary attributes in the class and add appropriate action listeners for future use. Copy the class, including import statement(s), as the answers to this part. CourseNana.COM

  CourseNana.COM

 (ii) CourseNana.COM

actionPerformed() : which performs the calculation and puts the result on the label when the button is pressed. You can assume one JPY is equivalent to 0.0063 USD. You can assume a valid real number is entered in the textfield. Copy the method as the answer to this part. CourseNana.COM

  CourseNana.COM

(iii) CourseNana.COM

main() : which creates a Conversion object and sets it visible for testing. Copy the method as the answer to this part. CourseNana.COM

[20] CourseNana.COM

              CourseNana.COM

Question 3 [20 marks]

  CourseNana.COM

You should be able to answer this question after you have completed Unit 4. CourseNana.COM

  CourseNana.COM

Write a class Launcher containing the following methods: CourseNana.COM

  CourseNana.COM

(a)     Constructor : which builds the frame shown below. The frame consists of a menu bar, two menus (Launch and Exit), some menu items, and a text area. The menu items of the Launch menu are shown and there is a single menu item "Exit" on the Exit menu. Declare any necessary attributes in the class and add appropriate action listeners for future use. Copy the class, including import statement(s), as the answers to this part. CourseNana.COM


CourseNana.COM

(b)     actionPerformed() : which performs necessary actions when each menu item is selected. Run the classes TestBackpack, DialogBox and Conversion when the menu items "Launch Backpack", "Launch DialogBox" and "Launch Conversion" is selected respectively. To launch TestBackpack, you may use the following statement: CourseNana.COM

  CourseNana.COM

TestBackpack.main(null); CourseNana.COM

  CourseNana.COM

Quit the program when the menu item "Exit" is selected. Copy the method as the answer to this part. CourseNana.COM

[9] CourseNana.COM

(c)     main() : which creates a Launcher object and sets it visible for testing. Copy the method as the answer to this part. CourseNana.COM

[1] CourseNana.COM


CourseNana.COM

Question 4 [30 marks]

  CourseNana.COM

You should be able to answer this question after you have completed Units 5. CourseNana.COM

  CourseNana.COM

(a)     You can look for leisure facilities and programme of LCSD through its home page: CourseNana.COM

https://www.lcsd.gov.hk/en/index.html CourseNana.COM

  CourseNana.COM

Suppose you like to see the squash training course. You should at least try to do the following: (1)  and client the search button, there are probably different courses at different sports centres. Then find and select one course.  CourseNana.COM

(2) On the home page, click  and find one. Using a table similar to Self Test 5.3, evaluate and give comments on the above Web interface based on the ten "characteristics of a good user interface" covered in the course. Remember to give your reason for each of the points.[20 CourseNana.COM

(b) Using two or more of the six "key principles of user interface design", discuss how to improve the user interface of the Conversion class in part (b) of Question 2, which is shown again for your convenient reference. You need to state each of the principles involved and then give your suggestion(s)[10] CourseNana.COM

**** End **** CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
HKMU代写,COMPS201代写,Computing Fundamentals with Java代写,Java代写,HKMU代编,COMPS201代编,Computing Fundamentals with Java代编,Java代编,HKMU代考,COMPS201代考,Computing Fundamentals with Java代考,Java代考,HKMUhelp,COMPS201help,Computing Fundamentals with Javahelp,Javahelp,HKMU作业代写,COMPS201作业代写,Computing Fundamentals with Java作业代写,Java作业代写,HKMU编程代写,COMPS201编程代写,Computing Fundamentals with Java编程代写,Java编程代写,HKMUprogramming help,COMPS201programming help,Computing Fundamentals with Javaprogramming help,Javaprogramming help,HKMUassignment help,COMPS201assignment help,Computing Fundamentals with Javaassignment help,Javaassignment help,HKMUsolution,COMPS201solution,Computing Fundamentals with Javasolution,Javasolution,