BIS 335 Homework 6
VerifiedAdded on 2019/09/18
|3
|1669
|208
Homework Assignment
AI Summary
This assignment involves creating a Java program that simulates an online shopping cart. It requires building several classes: an abstract `Item` class with subclasses `Book`, `Clothing`, `Television`, and `Computer`, all inheriting from `Item` or `Electronic` (which extends `Item`). Each class has specific attributes and methods, including input validation. A `ShoppingCart` class manages adding items, calculating the total price (including tax), and handling checkout. The program should prompt the user for item details, add them to the cart, display a summary at checkout, and allow for additional purchases or program termination.

BIS 335 Homework 6 – Fall 2016
Please review the syllabus for more detailed information on grading of homework assignments. For
this assignment you ARE required to validate input (that is, you MUST give user friendly error
messages when users enter unexpected data, like alpha characters for numbers, or a floating point
number instead of an integer, or a number out of range – example, the user entered 202 when
prompted for age – you would respond that this is not an appropriate input and ask for it again until
the program met input requirements).
Part 1: item classes
In this part of the homework you will create 6 class files that will be used by Part 2. These are classes
that will create objects that can be purchased online and put into a shopping cart – they will NOT have
main methods. Note that all instance variables should be private. Note that all methods should be
public.
Item.java: This abstract class defines an item for sale online. Each item has a 9 digit ID number, name,
and price. The ID number could start with zeros or could include letters, so think carefully about its type.
In this class you should also create a variable to track the total number of items created. This variable is
a class variable (not an instance variable). Create a constructor that will create an item object and
increase the total number of items counter. This constructor will take input for each of the instance
variables to create the object. Also, for each of the instance variables, create a method that will get the
variable and another method that will set the variable. These are the “getter” and “setter” methods
talked about in lecture (see section 5.1.3 of your textbook). Then create a toString() method in this class
to RETURN a user friendly description about the item (see section 5.3.2 of your textbook). Include an
abstract method called tax() in this class that returns a double and takes no parameters
Book.java: This class extends the Item class and defines a book. It adds ISBN (International Standard
Book Number), author first name, author last name, type (Hardcover, Softcover, or Electronic, noted by
H, S or E), and number of pages as instance variables.
Create a constructor in this class that calls the parent constructor from Item.java (see section 5.6.2 of
your textbook) and adds the instance variables particular to Book.java as well. Also, for each of the Book
instance variables, create a method that will get the variable and another method that will set the
variable. Finally, create a toString() method that calls the parent toString() method from Item.java and
adds in the particular instance variables for Book.java. The toString method should return book item
information in a user friendly way. Override the abstract method tax() which will return the sales tax on
this individual book object. Assume 6% sales tax.
Clothing.java: This class extends the Item class and defines a clothing item. It adds brand, size, and color
as instance variables that are particular to the clothing class. Note that size could have values like
“medium” and “6”.
Create a constructor in this class that calls the parent constructor from Item.java (see section 5.6.2 of
your textbook) and adds the instance variables particular to clothing.java as well. Also, for each of the
instance variables for clothing, create a method that will get the variable and another method that will
set the variable. Finally, create a toString() method that calls the parent toString() method from
Item.java and adds in the particular instance variables for clothing.java. The toString method should
return the clothing item information in a user friendly way. Override the abstract method tax() which
will return the sales tax on this individual clothing object. Assume no tax on clothing.
Please review the syllabus for more detailed information on grading of homework assignments. For
this assignment you ARE required to validate input (that is, you MUST give user friendly error
messages when users enter unexpected data, like alpha characters for numbers, or a floating point
number instead of an integer, or a number out of range – example, the user entered 202 when
prompted for age – you would respond that this is not an appropriate input and ask for it again until
the program met input requirements).
Part 1: item classes
In this part of the homework you will create 6 class files that will be used by Part 2. These are classes
that will create objects that can be purchased online and put into a shopping cart – they will NOT have
main methods. Note that all instance variables should be private. Note that all methods should be
public.
Item.java: This abstract class defines an item for sale online. Each item has a 9 digit ID number, name,
and price. The ID number could start with zeros or could include letters, so think carefully about its type.
In this class you should also create a variable to track the total number of items created. This variable is
a class variable (not an instance variable). Create a constructor that will create an item object and
increase the total number of items counter. This constructor will take input for each of the instance
variables to create the object. Also, for each of the instance variables, create a method that will get the
variable and another method that will set the variable. These are the “getter” and “setter” methods
talked about in lecture (see section 5.1.3 of your textbook). Then create a toString() method in this class
to RETURN a user friendly description about the item (see section 5.3.2 of your textbook). Include an
abstract method called tax() in this class that returns a double and takes no parameters
Book.java: This class extends the Item class and defines a book. It adds ISBN (International Standard
Book Number), author first name, author last name, type (Hardcover, Softcover, or Electronic, noted by
H, S or E), and number of pages as instance variables.
Create a constructor in this class that calls the parent constructor from Item.java (see section 5.6.2 of
your textbook) and adds the instance variables particular to Book.java as well. Also, for each of the Book
instance variables, create a method that will get the variable and another method that will set the
variable. Finally, create a toString() method that calls the parent toString() method from Item.java and
adds in the particular instance variables for Book.java. The toString method should return book item
information in a user friendly way. Override the abstract method tax() which will return the sales tax on
this individual book object. Assume 6% sales tax.
Clothing.java: This class extends the Item class and defines a clothing item. It adds brand, size, and color
as instance variables that are particular to the clothing class. Note that size could have values like
“medium” and “6”.
Create a constructor in this class that calls the parent constructor from Item.java (see section 5.6.2 of
your textbook) and adds the instance variables particular to clothing.java as well. Also, for each of the
instance variables for clothing, create a method that will get the variable and another method that will
set the variable. Finally, create a toString() method that calls the parent toString() method from
Item.java and adds in the particular instance variables for clothing.java. The toString method should
return the clothing item information in a user friendly way. Override the abstract method tax() which
will return the sales tax on this individual clothing object. Assume no tax on clothing.
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

Electronic.java: This abstract class extends the Item class and defines an electronic item. It adds
manufacturer and model as instance variables that are particular to the electronic class.
Create a constructor in this class that calls the parent constructor from Item.java (see section 5.6.2 of
your textbook) and adds the instance variables particular to electronic.java as well. Also, for each of the
instance variables for electronic, create a method that will get the variable and another method that will
set the variable. Finally, create a toString() method that calls the parent toString() method from
Item.java and adds in the particular instance variables for electronic.java. The toString method should
return the electronic item information in a user friendly way. Override the abstract method tax() which
will return the sales tax on this individual book object. Assume 6% sales tax.
Television.java: This class extends the electronic class and defines a television item. It adds screen size,
smart (boolean variable) and 3D (boolean variable) as instance variables that are particular to the
television class.
Create a constructor in this class that calls the parent constructor from electronics.java (see section
5.6.2 of your textbook) and adds the instance variables particular to television.java as well. Also, for
each of the instance variables for television, create a method that will get the variable and another
method that will set the variable. Finally, create a toString() method that calls the parent toString()
method from electronics.java and adds in the particular instance variables for television.java. The
toString method should return the television item information in a user friendly way.
Computer.java: This class extends the electronic class and defines a computer item. It adds screen size,
processor speed (in GHz) and hard drive size (in GB) as instance variables that are particular to the
computer class. Do some research online to figure out the types for processor speed and hard drive size.
Create a constructor in this class that calls the parent constructor from electronics.java (see section
5.6.2 of your textbook) and adds the instance variables particular to computer.java as well. Also, for
each of the instance variables for computer, create a method that will get the variable and another
method that will set the variable. Finally, create a toString() method that calls the parent toString()
method from electronics.java and adds in the particular instance variables for computer.java. The
toString method should return the computer item information in a user friendly way.
Part 2: Shoppingcart.java
Create a “driver” program called shoppingcart.java that has a main method and uses the classes
described above to mimic the process of putting items in an online shopping cart that a user wants to
purchase.
Create a loop that will continue to ask the user what type of item they wish to purchase, and then will
ask the specific questions to create that particular type of item. For example, the user could choose to
purchase a book. The system would then prompt the user for information about the book including the
ID Number, name, price, author, ISBN, title, type(H or S), and number of pages. Create the object for
that item using the user’s inputs, and place that object in an array that represents the shopping cart (this
array should be a global variable in this class). The cart does not need to hold more than 25 items.
Create a static method in this class called checkout() which does the following: After the user is done
putting items in the cart, produce a “checkout” output on the console window using the toString
method for each item in the shopping cart. At the bottom, after all items are printed out, have the total
manufacturer and model as instance variables that are particular to the electronic class.
Create a constructor in this class that calls the parent constructor from Item.java (see section 5.6.2 of
your textbook) and adds the instance variables particular to electronic.java as well. Also, for each of the
instance variables for electronic, create a method that will get the variable and another method that will
set the variable. Finally, create a toString() method that calls the parent toString() method from
Item.java and adds in the particular instance variables for electronic.java. The toString method should
return the electronic item information in a user friendly way. Override the abstract method tax() which
will return the sales tax on this individual book object. Assume 6% sales tax.
Television.java: This class extends the electronic class and defines a television item. It adds screen size,
smart (boolean variable) and 3D (boolean variable) as instance variables that are particular to the
television class.
Create a constructor in this class that calls the parent constructor from electronics.java (see section
5.6.2 of your textbook) and adds the instance variables particular to television.java as well. Also, for
each of the instance variables for television, create a method that will get the variable and another
method that will set the variable. Finally, create a toString() method that calls the parent toString()
method from electronics.java and adds in the particular instance variables for television.java. The
toString method should return the television item information in a user friendly way.
Computer.java: This class extends the electronic class and defines a computer item. It adds screen size,
processor speed (in GHz) and hard drive size (in GB) as instance variables that are particular to the
computer class. Do some research online to figure out the types for processor speed and hard drive size.
Create a constructor in this class that calls the parent constructor from electronics.java (see section
5.6.2 of your textbook) and adds the instance variables particular to computer.java as well. Also, for
each of the instance variables for computer, create a method that will get the variable and another
method that will set the variable. Finally, create a toString() method that calls the parent toString()
method from electronics.java and adds in the particular instance variables for computer.java. The
toString method should return the computer item information in a user friendly way.
Part 2: Shoppingcart.java
Create a “driver” program called shoppingcart.java that has a main method and uses the classes
described above to mimic the process of putting items in an online shopping cart that a user wants to
purchase.
Create a loop that will continue to ask the user what type of item they wish to purchase, and then will
ask the specific questions to create that particular type of item. For example, the user could choose to
purchase a book. The system would then prompt the user for information about the book including the
ID Number, name, price, author, ISBN, title, type(H or S), and number of pages. Create the object for
that item using the user’s inputs, and place that object in an array that represents the shopping cart (this
array should be a global variable in this class). The cart does not need to hold more than 25 items.
Create a static method in this class called checkout() which does the following: After the user is done
putting items in the cart, produce a “checkout” output on the console window using the toString
method for each item in the shopping cart. At the bottom, after all items are printed out, have the total

price of all items (this is a subtotal), the total amount to be paid in sales tax for all items, and grand total
of the shopping cart printout. Call this method in the main method after the user is done adding things
to the cart.
After the user has completed the checkout, confirm the total price of their shopping cart to complete
the order. Allow the user to back out and shop more if they would like to. If the user accepts the price,
ask the user if they would like to shop again. If the user replies yes then restart the program. If the user
replies no, thank them for shopping and terminate the program.
Sample Output:
<toString output for Item 1>
<toString output for item 2>
<toString output for item 3>
SubTotal: xxxxx.xx
Additional Tax: xx.xx
--------------
Total: xxxxx.xx
Your total is xxxxx.xx after tax. Please say “Yes” to confirm your
purchase or “No” to continue shopping.
Yes
Your purchase is complete! Would you like to shop again?
No
Okay! Thank you for shopping with us online. Have a nice day!
of the shopping cart printout. Call this method in the main method after the user is done adding things
to the cart.
After the user has completed the checkout, confirm the total price of their shopping cart to complete
the order. Allow the user to back out and shop more if they would like to. If the user accepts the price,
ask the user if they would like to shop again. If the user replies yes then restart the program. If the user
replies no, thank them for shopping and terminate the program.
Sample Output:
<toString output for Item 1>
<toString output for item 2>
<toString output for item 3>
SubTotal: xxxxx.xx
Additional Tax: xx.xx
--------------
Total: xxxxx.xx
Your total is xxxxx.xx after tax. Please say “Yes” to confirm your
purchase or “No” to continue shopping.
Yes
Your purchase is complete! Would you like to shop again?
No
Okay! Thank you for shopping with us online. Have a nice day!
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide
1 out of 3
Related Documents

Your All-in-One AI-Powered Toolkit for Academic Success.
+13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
Copyright © 2020–2025 A2Z Services. All Rights Reserved. Developed and managed by ZUCOL.