Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CAN SOMEONE WRITE A PROGRAM FOR THIS JAVA PROJECT? Choose a theme for the items you'll be saving and come up with two concrete classes

CAN SOMEONE WRITE A PROGRAM FOR THIS JAVA PROJECT?

Choose a theme for the items you'll be saving and come up with two concrete classes that require the calculation of an additional expense to add to the final price of each item. This calculation should be based on some field or set of fields that is unique to the individual concrete child class.

All classes must be named as shown in the above UML diagram except the concrete child classes. The ItemList is a singly-linked list with the following methods: insert(index: int, item: Item) : boolean o Inserts the given item at the given index if an equal item is not already in the list. If the method is successful it returns true. If an equal item already exists in the list or the index is out of range, this method returns false. add(item: Item): boolean o Adds the given item to the front of the list. Returns true if successful and false if an equal item is already in the list. set(index: int, item: Item) : Item o Replaces the object in the list at the given index with this object. If the index is out of range or the given item is already in the list, the method returns null. If the operation is successful, the method returns the object that was replaced by this one. delete(index: int) : Item o Deletes the object at the given index from the list. If the index is out of range, the method returns null. If the operation is successful, the method returns the object that was deleted. remove(item: Item) : boolean o Removes the given item from the list. If the object does not exist in the list, the method returns false. If the operation is successful, the method returns true. report(index: int) : Item o Reports the object in the list at the given index. If the index is out of range, returns null. find(item: Item) : int o Finds the given item in the list and returns the index where it was found. Returns -1 if it is not found. size() : int o Reports the number of elements currently stored in the list. toString() : String o Reports a String representation of the list of objects currently stored in it, in the format [first item String, second item String, ..., last item String] where each item is displayed using their toString method. getTotalCost(): double o Reports the total of all the cost field values of all the items in the list. getTotalValue(): double o Reports the total of the retail prices of all the items in the list, as reported by each item's calcPrice method. Include any added expense as reported by the calcAddedExpense() method if the item is an instance of the SpecialtyItem class.

You are not allowed to use a Java LinkedList or ArrayList in this project. The whole idea is to create your own.

The JUnit tests need to test all possible outcomes of all the methods listed above for ItemList except the toString method. Note that many of the same tests used in Lab 1 will work in Lab 2 as well. Consider the purpose of this library of classes as being to assist in creating a program for wholesalers who buy items at a given cost to them and then marks them up to sell them to the public. The cost field holds the amount the wholesaler paid for the item. Each item is given a serial number or ID_NUM for identification. The calcPrice method calculates what the retail price should be for that item. You may provide a fitting percentage markup for this. For example, grocery items usually have about a 10% markup. Luxury items can have up to a 100% markup. The equals method should use the instanceof operator to make sure the given object is an Item or a child of Item and compare just ID_NUM. The SpecialtyItem abstract class introduces a calcAddedExpense method. You should use this method to add to the retail price of the item. For example, if the user paid $100 for an item and had a 25% markup, the price would be $125. If this were a specialty item with an added expense of $50, the final price would be $175. Note that the SpecialtyItem class is abstract and inherits from the concrete Item class. The two child classes inherit from the SpecialtyItem class and must implement the calcAddedExpense abstract method listed in that class. Good example of an Item class and two child classes (do not use this one for your project): Item is a musical instrument. RareInstrument is a child class to represent instruments that are very old or unique and would require special insurance to ship. The added field may be the cost of shipping insurance. A Stratovarius violin would be an object of this class. OversizedInstrument is a child class to represent instruments that are very large and would require special shipping arrangements. This may require length, width, and height fields and/or a weight field. A grand piano would be an object of this class. Bad example of an Item class and two child classes (do not use this one for your project): Item is a musical instrument. RareInstrument, where cost, value, or monetary worth is considered a field. This would be taken care of in the main Item class with the cost field. The child class needs something unique to it. GrandPiano, with length, width, and height fields and/or a weight field. These same fields would need to be applied to upright pianos, tubas, etc. So these are not unique to just grand pianos. A broader category, like OversizedInstrument is better.

HERE IS AN EXAMPLE:

public class Node { int value; Node next; public Node(int val) { value = val; } } class NodeLinkedList { Node root; int count; public int add(int val) { //Do I have any element yet if (count == 0) { root = new Node(val); count++; return count; } Node current = root; while (current.next != null) { current = current.next; } Node newNode = new Node(val); current.next = newNode; count++; return count; } public int insertAt(int index, int val) { if (index < 0 || index >= count) return -1; //Do I have any element yet if (count == 0) { root = new Node(val); count++; return count; } Node current = root; Node prev = null; int counter = 0; while (counter < index) { prev = current; current = current.next; } Node newNode = new Node(val); prev.next = newNode; newNode.next = current; count++; return count; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions