Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment 3 Assignment 2 its java programming language. i only need help with the 4th assignment only. The purpose of this assignment is to practice

image text in transcribed
Assignment 3 image text in transcribed
Assignment 2
image text in transcribed
its java programming language. i only need help with the 4th assignment only.
image text in transcribed
The purpose of this assignment is to practice using polymorphism, interfaces and the compare To method. Problem Building on the class hierarchy from assignment 3: 1. Create an interface called Discount, which has 2 methods: a. to calculate the sales discount for items in the store, and b. to set the discount amount for an item. c. Note the discount will not adjust the price variable of an item; it will reduce the price by the discount amount when the toString method is called (so the toString code must be changed). d. Note getPrice will return the non discounted price. 2. In the driver program, create an array of Items, containing at least 2 items of each type (Book, Textbook, Novel, and Pen). Using polymorphism display the details of each Item in the array. 3. Use a cast to access a Textbook and Pen in the array to do sets and gets for course and color. Show that the code works by producing suitable outputs. 4. Finally have the item class implement Comparable, and code the compare To method to test the UPC code of items. Show that the compare To method can generate each of the 3 possible outcomes. You will need to do this through the child objects, since the parent is abstract. Notes: Child classes should call parent methods whenever possible to minimize code duplication. The driver program must test all the NEW methods and functionality (ie see #3 above) in each of the classes and in the array created in the driver program. Include comments in your output to describe what you are testing, for example System.out.println("testing Book toString, accessor and mutator"); Print out some blank lines in the output to make it easier to read and understand what is being output. Building on assignment 2 we'll add to the class hierarchy and add equals methods to the classes. Problem Given the class hierarchy from assignment 2 we'll add an Item class that will represent an item in a store. An item has a price (double) and a UPC code (long int) but does not exist on its own, it only exists to support sub classing (so it's an abstract class). The Book class from assignment 2 needs to be modified to extend from the Item class. Additionally the store sells pens so we'll need a pen class with a colour attribute in it. Secondly implement equals methods in all of the classes as well, and like assignment 2 test all of the functionality. (use the parent's equals method and add to it, in the child). Use the code below as a starting point, and modify it for the class you are using it in. Notes: Child classes should call parent methods whenever possible to minimize code duplication. The driver program must test all the methods in each of the classes. Include comments in your output to describe what you are testing, for example System.out.println("testing Book toString, accessor and mutator");. Print out some blank lines in the output to make it easier to read and understand what is being output. Assignment Submission: Submit a print-out of each class file, the driver file and a sample of the output. Include a UML diagram also. Marking Checklist 1. Does EACH class have all the usual methods? 2. Are all methods in EACH class tested, including child objects calling inherited parent methods? 3. Does the child class call the parent's constructor? 4. Does the child class override the parent's toString? 5. Does the child class override the parent's equals? 6. Does the output produced have lots of comments explaining what is being output? 7. Does each class, and the output, have blank lines and appropriate indenting to make them more readable? Problem Design and implement these 4 files: 1. A parent class called Book with a title and ISBN 2. Textbook inherits from Book and adds a course associated with attribute 3. Novel inherits from Book and adds genera (ie fiction or nonfiction) 4. A driver file to test the 3 classes above. The classes described in #1, 2 and 3 above should have the usual constructors (default and parameterized), get accessor) and set (mutator) methods for each attribute, and a toString method Child classes should call parent methods whenever possible to minimize code duplication. The driver program must test all the methods in each of the classes. Include comments in your output to describe what you are testing, for example System.out.println("testing Book toString, accessor and mutator"); Print out some blank lines in the output to make it easier to read and understand what is being output. Assignment Submission: Submit a print-out of each class file, the driver file and a sample of the output. Marking Checklist 1. Does EACH class have all the usual methods? 2. Are all methods in EACH class tested, including child objects calling inherited parent methods? 3. Does the child class call the parent's constructor? 4. Does the child class override the parent's toString? 5. Does the output produced have lots of comments explaining what is being output? 6. Does each class, and the output, have blank lines and appropriate indenting to make them more readable? The purpose of this assignment is to practice using polymorphism, interfaces and the compare To method. Problem Building on the class hierarchy from assignment 3: 1. Create an interface called Discount, which has 2 methods: a. to calculate the sales discount for items in the store, and b. to set the discount amount for an item. c. Note the discount will not adjust the price variable of an item; it will reduce the price by the discount amount when the toString method is called (so the toString code must be changed). d. Note getPrice will return the non discounted price. 2. In the driver program, create an array of Items, containing at least 2 items of each type (Book, Textbook, Novel, and Pen). Using polymorphism display the details of each Item in the array. 3. Use a cast to access a Textbook and Pen in the array to do sets and gets for course and color. Show that the code works by producing suitable outputs. 4. Finally have the item class implement Comparable, and code the compare To method to test the UPC code of items. Show that the compare To method can generate each of the 3 possible outcomes. You will need to do this through the child objects, since the parent is abstract. Notes: Child classes should call parent methods whenever possible to minimize code duplication. The driver program must test all the NEW methods and functionality (ie see #3 above) in each of the classes and in the array created in the driver program. Include comments in your output to describe what you are testing, for example System.out.println("testing Book toString, accessor and mutator"); Print out some blank lines in the output to make it easier to read and understand what is being output. The purpose of this assignment is to practice using polymorphism, interfaces and the compare To method. Problem Building on the class hierarchy from assignment 3: 1. Create an interface called Discount, which has 2 methods: a. to calculate the sales discount for items in the store, and b. to set the discount amount for an item. c. Note the discount will not adjust the price variable of an item; it will reduce the price by the discount amount when the toString method is called (so the toString code must be changed). d. Note getPrice will return the non discounted price. 2. In the driver program, create an array of Items, containing at least 2 items of each type (Book, Textbook, Novel, and Pen). Using polymorphism display the details of each Item in the array. 3. Use a cast to access a Textbook and Pen in the array to do sets and gets for course and color. Show that the code works by producing suitable outputs. 4. Finally have the item class implement Comparable, and code the compare To method to test the UPC code of items. Show that the compare To method can generate each of the 3 possible outcomes. You will need to do this through the child objects, since the parent is abstract. Notes: Child classes should call parent methods whenever possible to minimize code duplication. The driver program must test all the NEW methods and functionality (ie see #3 above) in each of the classes and in the array created in the driver program. Include comments in your output to describe what you are testing, for example System.out.println("testing Book toString, accessor and mutator"); Print out some blank lines in the output to make it easier to read and understand what is being output. Building on assignment 2 we'll add to the class hierarchy and add equals methods to the classes. Problem Given the class hierarchy from assignment 2 we'll add an Item class that will represent an item in a store. An item has a price (double) and a UPC code (long int) but does not exist on its own, it only exists to support sub classing (so it's an abstract class). The Book class from assignment 2 needs to be modified to extend from the Item class. Additionally the store sells pens so we'll need a pen class with a colour attribute in it. Secondly implement equals methods in all of the classes as well, and like assignment 2 test all of the functionality. (use the parent's equals method and add to it, in the child). Use the code below as a starting point, and modify it for the class you are using it in. Notes: Child classes should call parent methods whenever possible to minimize code duplication. The driver program must test all the methods in each of the classes. Include comments in your output to describe what you are testing, for example System.out.println("testing Book toString, accessor and mutator");. Print out some blank lines in the output to make it easier to read and understand what is being output. Assignment Submission: Submit a print-out of each class file, the driver file and a sample of the output. Include a UML diagram also. Marking Checklist 1. Does EACH class have all the usual methods? 2. Are all methods in EACH class tested, including child objects calling inherited parent methods? 3. Does the child class call the parent's constructor? 4. Does the child class override the parent's toString? 5. Does the child class override the parent's equals? 6. Does the output produced have lots of comments explaining what is being output? 7. Does each class, and the output, have blank lines and appropriate indenting to make them more readable? Problem Design and implement these 4 files: 1. A parent class called Book with a title and ISBN 2. Textbook inherits from Book and adds a course associated with attribute 3. Novel inherits from Book and adds genera (ie fiction or nonfiction) 4. A driver file to test the 3 classes above. The classes described in #1, 2 and 3 above should have the usual constructors (default and parameterized), get accessor) and set (mutator) methods for each attribute, and a toString method Child classes should call parent methods whenever possible to minimize code duplication. The driver program must test all the methods in each of the classes. Include comments in your output to describe what you are testing, for example System.out.println("testing Book toString, accessor and mutator"); Print out some blank lines in the output to make it easier to read and understand what is being output. Assignment Submission: Submit a print-out of each class file, the driver file and a sample of the output. Marking Checklist 1. Does EACH class have all the usual methods? 2. Are all methods in EACH class tested, including child objects calling inherited parent methods? 3. Does the child class call the parent's constructor? 4. Does the child class override the parent's toString? 5. Does the output produced have lots of comments explaining what is being output? 6. Does each class, and the output, have blank lines and appropriate indenting to make them more readable? The purpose of this assignment is to practice using polymorphism, interfaces and the compare To method. Problem Building on the class hierarchy from assignment 3: 1. Create an interface called Discount, which has 2 methods: a. to calculate the sales discount for items in the store, and b. to set the discount amount for an item. c. Note the discount will not adjust the price variable of an item; it will reduce the price by the discount amount when the toString method is called (so the toString code must be changed). d. Note getPrice will return the non discounted price. 2. In the driver program, create an array of Items, containing at least 2 items of each type (Book, Textbook, Novel, and Pen). Using polymorphism display the details of each Item in the array. 3. Use a cast to access a Textbook and Pen in the array to do sets and gets for course and color. Show that the code works by producing suitable outputs. 4. Finally have the item class implement Comparable, and code the compare To method to test the UPC code of items. Show that the compare To method can generate each of the 3 possible outcomes. You will need to do this through the child objects, since the parent is abstract. Notes: Child classes should call parent methods whenever possible to minimize code duplication. The driver program must test all the NEW methods and functionality (ie see #3 above) in each of the classes and in the array created in the driver program. Include comments in your output to describe what you are testing, for example System.out.println("testing Book toString, accessor and mutator"); Print out some blank lines in the output to make it easier to read and understand what is being output

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Knowledge Discovery In Databases

Authors: Gregory Piatetsky-Shapiro, William Frawley

1st Edition

0262660709, 978-0262660709

More Books

Students also viewed these Databases questions

Question

5. Have you stressed the topics relevance to your audience?

Answered: 1 week ago