Stage 1

  • Create a product class for your business, giving it an appropriate class name, and supply appropriate constructor(s) and methods to get and set fields (i.e. instance variables).
    • Each product will have a unique a product code as a string. You also need to decide the length of this string. The constructor(s) need to at least set the value of the product code.
    • Each product will have price and description fields.
    • There may be special fields for your products. For example these may include colour, size, weight, type, number_in_a_box, capacity, rating or similar. It all depends on the kind of product. It does not contain 'number in stock'. Choose fields that would apply to all the different products for your business.
    • Make sure you have a method called toString() in your product class that returns a String indicating a summary of all the details of the product.
  • Write a static method called validCode(…) for your product class that accepts a product code as a string and returns true if it has the correct length and it starts with a letter; the method returns false otherwise. You should look at the online documentation for the String and Character classes to find the appropriate methods to use.
  • Using a demonstration class, demonstrate your product class does what it is supposed to do. Your demonstration should include that validCode(…) works for both correct and incorrect strings. Include the output to the console from this class in your printed submission.
  • Create a Catalogue class that holds any number of products. Use an ArrayList, to hold the products. Write at least methods
    • addAProduct(…) providing a product as parameter
    • getAllProducts() returning an ArrayList (or List)
    • findProduct(…)taking a product code as parameter and returning a product.
  • Write a method called starProduct() that returns the product details (as a String) of the product chosen at random to be the 'Managers choice' for the week.
  • Ensure your product and Catalogue classes are documented using javadoc.
  • Draw a class diagram showing your product and catalogue classes.

Stage 2

  • Develop a JUnit test that demonstrates fully that you have tested the product class, printing out the results for your report. You do not need to test the toString() method.
  • Create a csv file (you can use Excel but must save as csv) with the first line giving the names of the fields for products separated by commas, and subsequent lines containing the field data for a set of products to go into the catalogue, with each field separated by commas. You should store this file in the top level directory of your project.
  • Create a new class (with javadoc comments) called CatalogueReader whose constructor takes as a parameter the name of a csv file. If the file specified was invalid, the constructor passes an exception back to the calling code. Otherwise it reads the lines from the csv file. For each line it creates a new product based on the data on that line and adds the product to an instance of your Catalogue class. CatalogueReader also has a method getCatalogue() that returns the populated instance of the catalogue class to the caller.
  • Create another class (with javadoc comments) called Controller which has a method run() that asks the user for the name of a csv file, and uses this name to create a CatalogueReader, displaying a message to the console if an invalid file was entered. If the file was valid, run() then obtains the instance of the catalogue class from the CatalogueReader, and then gets the list of products from the Catalogue displaying all their details to the console. Then, in a loop, it asks the user to enter a product to be searched for based on product code, and prints out the summary details of the product found to the console; if either an invalid code was entered or else the product with that code can’t be found, an appropriate message will be displayed to the user . The loop will end if the user enters a special terminating string or character.
  • Create another class called ControllerDemo whose main(…) method creates an instance of Controller and calls its run() method. You should print out the console output from running ControllerDemo for your report.
  • Modify your class diagram to include the CatalogueReader, Controller, and ControllerDemo classes.

Stage 3

  • Change your product class to introduce a field that holds the date on which the product was introduced onto the market. You will be using a class called GregorianCalendar (look up the class in the Java Documentation). Do not use the Date class.
    • When you create a new instance of a product it needs to be given (amongst other things) a date.
    • You will need to provide methods to set and get the field
    • Decide on a time period beyond which any product is to be categorised ‘end-of-line’ (you could make this time period a static constant in your product class) and compose a method to determine whether a product can be classified as ‘end-of-line’.
    • You will also need to change your toString() method to include the date when the product was introduced onto the market.
    • Modify your JUnit tests for the product class to incorporate the new functionality, printing out the results for your report. Again you do not need to test toString().
  • Create a new csv file by copying the one you created in Stage 2 above, and then modify the copy to include date (e.g. a string for each of day, month, year). Change the CatalogueReader class to read in this new version of the file and to create products that now include the date/time to go into the Catalogue.
  • Change the Catalogue class (and add a javadoc comment) to have a method that returns a list of products on the basis of the date field you have just added. For example list all those products that are not classified as ‘end-of-line’.
  • Now change the Controller class you developed earlier so that, in addition to displaying all products, it also displays the products that relate to the date field you have just added – for example those products that are not ‘end-of-line’.
  • Print out your console output from running ControllerDemo (for your report this should replace the console output from the previous stage)

Stage 4

Add subclasses of the product class. For example for a watch business you may have

public class SportsWatch extends Watch{
private boolean hasStopwatch;
private int waterResistanceDepth;

... Core fields would remain in the product class. You may need to remove category-type fields in the product class (and change the product class in other ways) to take into account the new subclasses. So creating a new SportsWatch object might look like

SportsWatch myWatch = new SportsWatch( . . .,true,30);

and somehow the parameters for all watches (shown as . . . above) have to be sent up to the Watch part of the SportsWatch object (... in the constructor).

The toString() method for each subclass needs to combine summary data from the subclass with summary data in the base product class.

Ensure that the modifed product class and its descendant classes have appropriate javadoc comments.

  • Enhance your JUnit tests to fully test out your product and its descendant classes - again not including tests for the toString() method.
  • Create a new csv file, this time without a header line, to contain data for products of different classes, giving the product code as the first field, an indicator of the class next, and the fields that follow to give the data that would be supplied to the constructor of the class (see shapea.csv as read by ShapeCounterDemo from week 6 for a similar example of this).
  • Modify the CatalogueReader class (making any necessary changes to javadoc comments) to make a number of different instances of these different types of product, based on the data in the new csv file, adding them to the Catalogue, and ensure that the correct output is displayed when ControllerDemo is run. Print out the console output for your report. (For your report this should replace the console output from ControllerDemo from the previous stage).

Stage 5

Some of the subclasses you created are to be given a special price offering. This may be a fixed deduction (It depends on the kind of product as to what is a reasonable amount of discount 10p off a newspaper may be substantial, 10p off the price of a Porche is just silly). Or it may be a percentage deduction (say 10% or 25%). At least one subclass will make no change at all.

Your task is to modify a number of the classes that you developed so far so that they correctly deduct from the product price held in the super class. For instance if we stipulate that a sports watch is £10 off and we create a SportsWatch object as follows (with the actual parameter shown here indicating a price of £50 – other parameters are missing):

SportsWatch myWatch = new SportsWatch( . . .,50.00,. . .);

then

myWatch.getPrice();

should return the value 40.00.

One major condition for this stage of the software is that the price field is not to be stored in the subclass and that the price field MUST be private!

Change the toString() method so that it displays the kind of product and the discount method as well as the final price. In the example above, the statement

System.out.println( myWatch );

should display something like:

SPORTS WATCH: ...., was £50.00, now £10.00 off , price = £40.00

Create a new csv file, this time without a header line, to contain data for instances of different product classes, giving the product code as the first field, an indicator of the class next, and the fields that follow to give the data that would be supplied to the constructor of the class (see shapea.csv as read by ShapeCounterDemo from week 6 for a similar example of this).

Modify the CatalogueReader class to use instances of the different subclasses of your product class, adding them to the Catalogue class and shown by running ControllerDemo that both the getPrice() and toString() methods are working for each subclass of the product class. Print out the console output (For your report this should replace console output from ControllerDemo from the previous stage)

Create an Invoice class (with javadoc comments) embodying line-items. It has constructor/methods to set the invoice number, and the customer name and address. It also has a method to add a line-item. Each line-item should be embodied in a LineItem class and should include the product code (or reference to a product object) and the number of items. As well as a suitable constructor, the LineItem class should have methods getInvoiceEntry() which returns a suitable string for displaying on an invoice line, and getValue() which returns the value of the line-item.

The toString() method of Invoice should return a string with the customer name at the top, a list of the line-items and the quantities and a total at the bottom. Do not make any allowance for VAT or other taxes. (Look at a real invoice to see what is expected, for instance you might include your company name at the top). You may want to make use of the StringBuffer class.

Create a separate demonstration class to demonstrate the Invoice class and print out the console display for your report.

Stage 6

  • Create an interface (with javadoc comments) called ILineItem with 2 methods called getInvoiceEntry() that returns a String and getValue()that returns a double. Modify your LineItem class to implement the ILineItem interface.
  • Change the Invoice class so that it holds ILineItems instead of LineItems. You will have to change the ArrayList in the class and at least the method for adding a line-item. The toString() method needs to call the getInvoiceEntry() of each LineItem to build up the invoice. Make any necessary changes to the javadoc comments.
  • Create a new class, with javadoc comments, called Bundle. This class implements the ILineItem interface and has an additional method called add( ) that accepts other ILineItems which it holds in an ArrayList. Then getInvoiceEntry() method returns a string with the word *BUNDLE* then each LineItem it holds on a new line followed by a line with "TOTAL = " with the correct total of all the line-items held being included at this point. The getValue() method also returns the total value of all the line-items held.
  • Enhance the demonstration class to create a Bundle and add a number of different line-items to it. As well as adding a number of different line-items to the Invoice, also add the Bundle. Print out the Invoice to demonstrate the Bundle and the Invoice work together.
  • Create a class diagram for all the classes developed so far. Use your discretion about whether to display the attributes and operations for each of the classes. For your submission this can replace the class diagram generated for an earlier stage.
Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.