SlideShare a Scribd company logo
//Book.java
package bookStore;
public class Book extends Product {
private String ISBN;
public Book(int pID, String bISBN, int noOfProduct) {
// TODO Auto-generated constructor stub
super(pID, noOfProduct);
this.ISBN = bISBN;
}
public String getISBN() {
return ISBN;
}
public void setISBN(String iSBN) {
ISBN = iSBN;
}
}
//CD.java
package bookStore;
public class CD extends Product {
public CD(int pID, int noOfProduct) {
super(pID, noOfProduct);
// TODO Auto-generated constructor stub
}
}
//DVD.java
package bookStore;
public class DVD extends Product {
public DVD(int pID, int noOfProduct) {
super(pID, noOfProduct);
// TODO Auto-generated constructor stub
}
}
//Member.java
package bookStore;
public class Member {
private int id;
private String firstName;
private String lastName;
private double moneySpent;
public Member(int id, String fName, String lName) {
this.id = id;
this.firstName = fName;
this.lastName = lName;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public double getMoneySpent() {
return moneySpent;
}
public void setMoneySpent(double moneySpent) {
this.moneySpent = moneySpent;
}
}
//PremiumMember.java
package bookStore;
public class PremiumMember extends Member {
private double feeMonthly;
private String paymentMethod;
private boolean feePaidOnTime;
public PremiumMember(int id, String fName, String lName) {
super(id, fName, lName);
}
public double getFeeMonthly() {
return feeMonthly;
}
public void setFeeMonthly(double feeMonthly) {
this.feeMonthly = feeMonthly;
}
public String getPaymentMethod() {
return paymentMethod;
}
public void setPaymentMethod(String paymentMethod) {
this.paymentMethod = paymentMethod;
}
public boolean isFeePaidOnTime() {
return feePaidOnTime;
}
public void setFeePaidOnTime(boolean feePaidOnTime) {
this.feePaidOnTime = feePaidOnTime;
}
}
//Product.java
package bookStore;
public class Product {
private int count;
private int productID;
public Product(int pID, int noOfProduct) {
// TODO Auto-generated constructor stub
this.productID = pID;
this.count = noOfProduct;
}
public int getProductID() {
return productID;
}
public void setProductID(int productID) {
this.productID = productID;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
}
//Store.java
package bookStore;
import java.util.ArrayList;
import java.util.Scanner;
public class Store {
public static ArrayList<Product> inventory = new ArrayList<Product>();
public static ArrayList<PremiumMember> members = new ArrayList<PremiumMember>();
public static Scanner sc = new Scanner(System.in);
private static void CreateInventory() {
int pID, noOfProduct;
String isBook, bISBN;
Book book;
CD cd;
DVD dvd;
System.out.println("Press Y if you want to store book in inventory");
System.out.println("Press N if you want to store CD in inventory");
System.out.println("Press NO if you want to store DVD in inventory");
isBook = sc.next();
while (true) {
System.out.println("Please enter product id");
pID = sc.nextInt();
System.out.println("Please enter number of product");
noOfProduct = sc.nextInt();
if (isBook.equalsIgnoreCase("Y")) {
System.out.println("Please enter book ISBN number");
bISBN = sc.next();
book = new Book(pID, bISBN, noOfProduct);
inventory.add(book);
} else if (isBook.equalsIgnoreCase("N")) {
cd = new CD(pID, noOfProduct);
inventory.add(cd);
} else {
dvd = new DVD(pID, noOfProduct);
inventory.add(dvd);
}
System.out.println("Press Y if you want to add another item in the inventory");
System.out.println("Press N if you do not want to add another item in the inventory");
isBook = sc.next();
if (isBook.equalsIgnoreCase("N")) {
break;
}
}
}
private static boolean findProduct(int pID) {
for (Product p : inventory) {
if (p.getProductID() == pID) {
return true;
}
}
return false;
}
private static boolean CheckInventory(int pID, int pCount) {
for (Product p : inventory) {
if (p.getProductID() == pID) {
if (p.getNoOfProducts() >= pCount) {
p.setNoOfProducts(p.getNoOfProducts() - pCount);
return true;
} else {
System.out.println("There are not enough products in the inventory.");
return false;
}
}
}
System.out.println("Product not found in inventory.");
return false;
}
private static void DistributeItem() {
int pID, pCount, id;
String premium = null, paymentMethod = null;
double fee = 0;
PremiumMember member = null;
System.out.println("Please enter product id");
pID = sc.nextInt();
if (findProduct(pID)) {
System.out.println("Please enter number of products to distribute");
pCount = sc.nextInt();
if (CheckInventory(pID, pCount)) {
System.out.println("Please enter member id");
id = sc.nextInt();
System.out.println("Please enter member first name");
String fName = sc.next();
System.out.println("Please enter member last name");
String lName = sc.next();
System.out.println("Press Y if the member is premium");
premium = sc.next();
member = new PremiumMember(id, fName, lName);
if (premium.equalsIgnoreCase("Y")) {
member.setFeeMonthly(fee);
member.setPaymentMethod(paymentMethod);
}
}
}
}
public static void main(String[] args) {
// Create array of Product class
CreateInventory();
while (true) {
// Distribute item from inventory
DistributeItem();
String check;
System.out.println("Do you want to distribute more items? Press Y for Yes or any other key for
No");
check = sc.next();
if (!check.equalsIgnoreCase("Y")) {
break;
}
}
}
}
*REVIEW THE 7 CLASSES SO THE CODE CAN RUN AND HAVE AN OUTPUT.
THERE ARE ERRORS THAT DO NOT MAKE THE CODE RUN. PLEASE HELP.
This grade is awarded for proper coding styles. This includes:
Appropriate prompts and informative output
Appropriate method, variable and object names
Proper indentation
Good commenting (explains what code is doing)
Well-organized, elegant solution
- MAKE SURE THE CODE CAN RUN!

More Related Content

PDF
database propertiesjdbc.url=jdbcderbyBigJavaDB;create=true # .pdf
DOCX
DAOFactory.javaDAOFactory.javapublicclassDAOFactory{ this .docx
DOCX
VISUALIZAR REGISTROS EN UN JTABLE
PDF
BasicPizza.javapublic class BasicPizza { Declaring instance .pdf
PPTX
CodingSerbia2014-JavaVSPig
PDF
12.9 Program Online shopping cart (continued) (C++)This program e.pdf
PDF
2024 PHPCon - Symfony background processing
PDF
Introduction to Spring Boot.pdf
database propertiesjdbc.url=jdbcderbyBigJavaDB;create=true # .pdf
DAOFactory.javaDAOFactory.javapublicclassDAOFactory{ this .docx
VISUALIZAR REGISTROS EN UN JTABLE
BasicPizza.javapublic class BasicPizza { Declaring instance .pdf
CodingSerbia2014-JavaVSPig
12.9 Program Online shopping cart (continued) (C++)This program e.pdf
2024 PHPCon - Symfony background processing
Introduction to Spring Boot.pdf

Similar to --Book-java package bookStore- public class Book extends Product { (1).docx (20)

PPT
Oop php 5
PDF
Getting error - (Return type of out-of-line definition of 'Product--Ge.pdf
PPTX
Getting the Most Out of jQuery Widgets
DOCX
SinglyLinkedListPseudoCode.txtCLASS SinglyLinkedList se.docx
PDF
Write a program that mimics the operations of several vending machin.pdf
PDF
Matching Game In Java
PDF
Why SOLID matters - even for JavaScript
PDF
import java.util.Scanner;class BinaryNode{     BinaryNode left.pdf
PDF
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
PDF
Infinum Android Talks #20 - DiffUtil
PDF
What is the difference between a good and a bad repository? (Forum PHP 2018)
PDF
Getting error - (Return type of out-of-line definition of 'Product--Ge (1).pdf
PDF
@author public class Person{   String sname, .pdf
PDF
Practical Event Sourcing
PDF
Manual tecnic sergi_subirats
PPTX
KEY
Solid principles
DOCX
Quest 1 define a class batsman with the following specifications
PPT
OBJECTS IN Object Oriented Programming .ppt
PDF
Android Design Patterns
Oop php 5
Getting error - (Return type of out-of-line definition of 'Product--Ge.pdf
Getting the Most Out of jQuery Widgets
SinglyLinkedListPseudoCode.txtCLASS SinglyLinkedList se.docx
Write a program that mimics the operations of several vending machin.pdf
Matching Game In Java
Why SOLID matters - even for JavaScript
import java.util.Scanner;class BinaryNode{     BinaryNode left.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
Infinum Android Talks #20 - DiffUtil
What is the difference between a good and a bad repository? (Forum PHP 2018)
Getting error - (Return type of out-of-line definition of 'Product--Ge (1).pdf
@author public class Person{   String sname, .pdf
Practical Event Sourcing
Manual tecnic sergi_subirats
Solid principles
Quest 1 define a class batsman with the following specifications
OBJECTS IN Object Oriented Programming .ppt
Android Design Patterns
Ad

More from PiersRCoThomsonw (20)

DOCX
-Complete the following Biology I questions for section a- (attached b.docx
DOCX
-Calculating Probability from Data- The table below gives details of s.docx
DOCX
- H2-4- (pytypes - py) Python's type (obj) function retums the type of.docx
DOCX
-Collenchyma -Cambium -Parenchyma -Vascular tissue system -Sclereid.docx
DOCX
-Analyze the effects of the COVVI-19 pandemic on food (interventions).docx
DOCX
-Analyze the effects of the COVVI-19 pandemic on (interventions) agro-.docx
DOCX
-1-_______________- 10- What is the amount of Siena and Kendall's reti.docx
DOCX
---HINT- Consider the case when n-3- Professor Kelp decides to write a.docx
DOCX
(2 points) What is the Boolean expression for P- Design a circuit that.docx
DOCX
- Use a paragraph to reflect upon why you are interested in the chosen.docx
DOCX
- With your partner- list at least two tangible resources- two intangi.docx
DOCX
- List the following in order of precedence from highest precedence to.docx
DOCX
- Execute Summary - Overall paragraph of the the numer of devices that.docx
DOCX
- Climate change is a very big deai as it affects everyone- but not al.docx
DOCX
- Annual Demand -2-000 units - Days per year considered in average dai.docx
DOCX
(Mutually exclusive projects and NPV) You have been assigned the task.docx
DOCX
(1) Nonsidering aboue ER dingram- (a) Poovide the relational scbema (b.docx
DOCX
(22 pts) Derive a complexity function T(n) for the following pseudo co.docx
DOCX
(1 point) Construct a simple graph with vertices H-I-J-K whose degrees.docx
DOCX
(4 Points) Construct to scale a diagram (likethe one used in lecture f.docx
-Complete the following Biology I questions for section a- (attached b.docx
-Calculating Probability from Data- The table below gives details of s.docx
- H2-4- (pytypes - py) Python's type (obj) function retums the type of.docx
-Collenchyma -Cambium -Parenchyma -Vascular tissue system -Sclereid.docx
-Analyze the effects of the COVVI-19 pandemic on food (interventions).docx
-Analyze the effects of the COVVI-19 pandemic on (interventions) agro-.docx
-1-_______________- 10- What is the amount of Siena and Kendall's reti.docx
---HINT- Consider the case when n-3- Professor Kelp decides to write a.docx
(2 points) What is the Boolean expression for P- Design a circuit that.docx
- Use a paragraph to reflect upon why you are interested in the chosen.docx
- With your partner- list at least two tangible resources- two intangi.docx
- List the following in order of precedence from highest precedence to.docx
- Execute Summary - Overall paragraph of the the numer of devices that.docx
- Climate change is a very big deai as it affects everyone- but not al.docx
- Annual Demand -2-000 units - Days per year considered in average dai.docx
(Mutually exclusive projects and NPV) You have been assigned the task.docx
(1) Nonsidering aboue ER dingram- (a) Poovide the relational scbema (b.docx
(22 pts) Derive a complexity function T(n) for the following pseudo co.docx
(1 point) Construct a simple graph with vertices H-I-J-K whose degrees.docx
(4 Points) Construct to scale a diagram (likethe one used in lecture f.docx
Ad

Recently uploaded (20)

PPTX
Pharma ospi slides which help in ospi learning
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
Complications of Minimal Access Surgery at WLH
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Classroom Observation Tools for Teachers
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
Pharma ospi slides which help in ospi learning
102 student loan defaulters named and shamed – Is someone you know on the list?
Anesthesia in Laparoscopic Surgery in India
GDM (1) (1).pptx small presentation for students
Chinmaya Tiranga quiz Grand Finale.pdf
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Complications of Minimal Access Surgery at WLH
202450812 BayCHI UCSC-SV 20250812 v17.pptx
human mycosis Human fungal infections are called human mycosis..pptx
Classroom Observation Tools for Teachers
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Microbial disease of the cardiovascular and lymphatic systems
VCE English Exam - Section C Student Revision Booklet
2.FourierTransform-ShortQuestionswithAnswers.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025

--Book-java package bookStore- public class Book extends Product { (1).docx

  • 1. //Book.java package bookStore; public class Book extends Product { private String ISBN; public Book(int pID, String bISBN, int noOfProduct) { // TODO Auto-generated constructor stub super(pID, noOfProduct); this.ISBN = bISBN; } public String getISBN() { return ISBN; } public void setISBN(String iSBN) { ISBN = iSBN; } } //CD.java package bookStore; public class CD extends Product { public CD(int pID, int noOfProduct) { super(pID, noOfProduct); // TODO Auto-generated constructor stub }
  • 2. } //DVD.java package bookStore; public class DVD extends Product { public DVD(int pID, int noOfProduct) { super(pID, noOfProduct); // TODO Auto-generated constructor stub } } //Member.java package bookStore; public class Member { private int id; private String firstName; private String lastName; private double moneySpent; public Member(int id, String fName, String lName) { this.id = id; this.firstName = fName; this.lastName = lName; } public int getId() { return id;
  • 3. } public void setId(int id) { this.id = id; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public double getMoneySpent() { return moneySpent; } public void setMoneySpent(double moneySpent) { this.moneySpent = moneySpent; } }
  • 4. //PremiumMember.java package bookStore; public class PremiumMember extends Member { private double feeMonthly; private String paymentMethod; private boolean feePaidOnTime; public PremiumMember(int id, String fName, String lName) { super(id, fName, lName); } public double getFeeMonthly() { return feeMonthly; } public void setFeeMonthly(double feeMonthly) { this.feeMonthly = feeMonthly; } public String getPaymentMethod() { return paymentMethod; } public void setPaymentMethod(String paymentMethod) { this.paymentMethod = paymentMethod; } public boolean isFeePaidOnTime() { return feePaidOnTime;
  • 5. } public void setFeePaidOnTime(boolean feePaidOnTime) { this.feePaidOnTime = feePaidOnTime; } } //Product.java package bookStore; public class Product { private int count; private int productID; public Product(int pID, int noOfProduct) { // TODO Auto-generated constructor stub this.productID = pID; this.count = noOfProduct; } public int getProductID() { return productID; } public void setProductID(int productID) { this.productID = productID; } public int getCount() { return count;
  • 6. } public void setCount(int count) { this.count = count; } } //Store.java package bookStore; import java.util.ArrayList; import java.util.Scanner; public class Store { public static ArrayList<Product> inventory = new ArrayList<Product>(); public static ArrayList<PremiumMember> members = new ArrayList<PremiumMember>(); public static Scanner sc = new Scanner(System.in); private static void CreateInventory() { int pID, noOfProduct; String isBook, bISBN; Book book; CD cd; DVD dvd; System.out.println("Press Y if you want to store book in inventory"); System.out.println("Press N if you want to store CD in inventory"); System.out.println("Press NO if you want to store DVD in inventory"); isBook = sc.next();
  • 7. while (true) { System.out.println("Please enter product id"); pID = sc.nextInt(); System.out.println("Please enter number of product"); noOfProduct = sc.nextInt(); if (isBook.equalsIgnoreCase("Y")) { System.out.println("Please enter book ISBN number"); bISBN = sc.next(); book = new Book(pID, bISBN, noOfProduct); inventory.add(book); } else if (isBook.equalsIgnoreCase("N")) { cd = new CD(pID, noOfProduct); inventory.add(cd); } else { dvd = new DVD(pID, noOfProduct); inventory.add(dvd); } System.out.println("Press Y if you want to add another item in the inventory"); System.out.println("Press N if you do not want to add another item in the inventory"); isBook = sc.next(); if (isBook.equalsIgnoreCase("N")) { break; }
  • 8. } } private static boolean findProduct(int pID) { for (Product p : inventory) { if (p.getProductID() == pID) { return true; } } return false; } private static boolean CheckInventory(int pID, int pCount) { for (Product p : inventory) { if (p.getProductID() == pID) { if (p.getNoOfProducts() >= pCount) { p.setNoOfProducts(p.getNoOfProducts() - pCount); return true; } else { System.out.println("There are not enough products in the inventory."); return false; } } } System.out.println("Product not found in inventory.");
  • 9. return false; } private static void DistributeItem() { int pID, pCount, id; String premium = null, paymentMethod = null; double fee = 0; PremiumMember member = null; System.out.println("Please enter product id"); pID = sc.nextInt(); if (findProduct(pID)) { System.out.println("Please enter number of products to distribute"); pCount = sc.nextInt(); if (CheckInventory(pID, pCount)) { System.out.println("Please enter member id"); id = sc.nextInt(); System.out.println("Please enter member first name"); String fName = sc.next(); System.out.println("Please enter member last name"); String lName = sc.next(); System.out.println("Press Y if the member is premium"); premium = sc.next(); member = new PremiumMember(id, fName, lName); if (premium.equalsIgnoreCase("Y")) {
  • 10. member.setFeeMonthly(fee); member.setPaymentMethod(paymentMethod); } } } } public static void main(String[] args) { // Create array of Product class CreateInventory(); while (true) { // Distribute item from inventory DistributeItem(); String check; System.out.println("Do you want to distribute more items? Press Y for Yes or any other key for No"); check = sc.next(); if (!check.equalsIgnoreCase("Y")) { break; } } } } *REVIEW THE 7 CLASSES SO THE CODE CAN RUN AND HAVE AN OUTPUT. THERE ARE ERRORS THAT DO NOT MAKE THE CODE RUN. PLEASE HELP.
  • 11. This grade is awarded for proper coding styles. This includes: Appropriate prompts and informative output Appropriate method, variable and object names Proper indentation Good commenting (explains what code is doing) Well-organized, elegant solution - MAKE SURE THE CODE CAN RUN!