Classes & Constructors Assignment

See this link for Assignment Policies, Submission Instructions, and Grading Guidelines.

Instructions

1.      Write a Java application that does the following:

2.      IMPORTANT NOTE: Create a 2nd class (class definition) in the same file as your LastNameFirstNameX class (client) with 3 data fields & 2 methods. Note that these are non-static variables & methods. The 2nd class should NOT have the keyword “public” in front of it.

3.      The 2nd class models Grocery Items that you would buy at the grocery store. The 2nd class is the class definition for a Grocery Item.

4.      The Grocery Item class definition should contain the following 3 data fields (attributes): name of the item, price of the item, & count of the item.

5.      The Grocery Item class definition should contain the following 2 methods (behaviors): constructor & toString().

6.      The constructor should initialize (assign a beginning value) to all 3 data fields.

7.      The toString() method should return a string of the 3 data fields, so that they can be appropriately displayed. Think of how Grocery Items are displayed on a real grocery store receipt.

8.      The 1st class is the client. It has the same name as LastNameFirstNameX.

9.      In the 1st class, instantiate (create) 5 Grocery Item objects. Use the constructor to do this.

10.  In the 1st class, use the toString() method to display the 5 Grocery Item objects. Use either System.out.println() or JOptionPane.showMessageDialog().

11.  IMPORTANT NOTE: Make sure that your program follows the ICS 111 Java Coding Standard. The comments above each method should be written in the appropriate format.

12.  For this assignment, since there is no input (only output), you do not need to use try-catch blocks.

 

 

 

© 2007 William Albritton