Question: I want to add and delete products from ArrayList java package march11; public interface productlnterface { public double computeSalePrice(); public double getRegularPrice(); public void setRegularPrice(double
I want to add and delete products from ArrayList
java
package march11;
public interface productlnterface {
public double computeSalePrice();
public double getRegularPrice();
public void setRegularPrice(double regularPrice); public String toString(); }
////////////////////////////////////
package march11;
public abstract class product implements productlnterface {
private double regularPrice;
public product() { }
public product(double regularPrice) { this.regularPrice = regularPrice; }
@Override public double computeSalePrice() { double saleprice;
saleprice = regularPrice + (regularPrice * (10 / 100));
return saleprice; }
@Override public void setRegularPrice(double regularPrice) { this.regularPrice = regularPrice; }
@Override public double getRegularPrice() { return this.regularPrice; } public abstract String toString();
}
////////////////////////////////
package march11;
public class dd extends Book {
private int age;
public dd(double regularPrice, String publisher, int yearPublished) { super(regularPrice, publisher, yearPublished); this.age = age; }
public double computeSalePrice() {
double saleprice;
saleprice = this.getRegularPrice() + (this.getRegularPrice() * (15 / 100));
return saleprice; }
@Override public String toString() { return ".Publisher: " + getPublisher() + "\t Price: " + computeSalePrice()+"\t YearPublished: "+getYearPublished(); } }
////////////////////////////////
package march11;
public class TV extends Electronics {
private int size;
public TV(double regularPrice, String manufacturer, int size) { super(regularPrice, manufacturer); this.size = size; }
public double computeSalePrice() {
double saleprice;
saleprice = this.getRegularPrice() + (this.getRegularPrice() * (50 / 100));
return saleprice; }
@Override public String toString() { return ".Name: "+getManufacturer()+"\t Price: "+computeSalePrice()+"\t Size: "+size; } }
//////////////////////////////////////
package march11;
import java.util.ArrayList; import java.util.Scanner;
import march12.ProductInterface.*;
public class Main {
ArrayList
private int ch = 0; private int p = 0;
public Main() {
menu();
}
public void startScreen() {
System.out.println("Welcome to the market. ................................");
System.out.println("1. Display Store Products");
System.out.println("2. Display Cart");
System.out.println("0. Exit"); }
public void storeProductsMenu() {
System.out.println(" 1. Add to Cart");
System.out.println("2. Remove From Cart");
System.out.println("0. Exit");
}
private int getUserInput() {
Scanner in = new Scanner(System.in);
System.out.print("Your choice:");
ch = Integer.parseInt(in.nextLine()); System.out.println(" "); return ch;
}
public void TrLoop() { if (p == 2) { System.out.println("-----------------------BYE!----------------------- "); System.out.println("$$$$$$$$$$$$Newton passed from here$$$$$$$$$$$$"); System.exit(0); } else { p++; System.out.println("************************ " + "Invalid c1`hoica"); System.out.println("Try again :( " + (p) + " ) " + "************************ "); } }
private void displayStoreProducts() {//????? ???????
product TV1 = new TV(1000, "Samsung", 30); product TV2 = new TV(2000, "Sony", 50);
product MP3Player = new MP3Player(250, "Apple", "blue");
product ChildrenBook = new ChildrenBook(15, "Pee Wee press", 1987, 8);
product Cartoon = new Cartoon(14, "Pee Wee press", 1924, "Batman");
product[] pa = {TV1, TV2, MP3Player, ChildrenBook, Cartoon};
int i = 1; for (product pr : pa) { System.out.println(i + pr.toString()); i++; } }
public void menu() {
do {
startScreen();
getUserInput();
switch (ch) {
case 1:
displayStoreProducts(); storeProductsMenu();
getUserInput();
// innerChoice1(); break;
case 2:
// showCart(); break;
case 0:
System.exit(0);
break;
default: TrLoop(); break;
}
} while (ch != 0); } // ???? ????? ???????? ??????
private void innerChoice1() {
switch (ch) {
case 1:
// addProductToCart(); // showCart(); break;
case 2:
// removeProductFromCart(); break;
default:
break;
}
}
private void addProductToCart() { int pid = getUserInput() - 1; // market.add(1); }
}
////////////////////////////////////
package march11;
public class MP3Player extends Electronics {
String color;
public MP3Player(double regularPrice, String manufacturer, String color) { super(regularPrice, manufacturer); this.color = color; }
public double computeSalePrice() {
double saleprice;
saleprice = this.getRegularPrice() + (this.getRegularPrice() * (40 / 100));
return saleprice; }
public String getColor() { return color; }
public void setColor(String color) { this.color = color; }
@Override public String toString() { return ".Name: "+getManufacturer()+"\t Price: "+computeSalePrice()+"\t Color: "+color; } }
////////////////////////////////
package march11;
public interface ElectronicsInterface extends productlnterface {
public String getManufacturer(); }
///////////////
package march11;
public abstract class Electronics extends product implements ElectronicsInterface {
private String manufacturer;
public Electronics(double regularPrice, String manufacturer) {// ??? ?????? ? ????? super(regularPrice); this.manufacturer = manufacturer; }
@Override public String getManufacturer() {//?????? return manufacturer; }
public void setManufacturer(String manufacturer) {// this.manufacturer = manufacturer; }
@Override public abstract String toString();
}
/////////////////////////////////
package march11;
public class ChildrenBook extends Book {
private int age;
public ChildrenBook(double regularPrice, String publisher, int yearPublished, int age) { super(regularPrice, publisher, yearPublished); this.age = age; }
public double computeSalePrice() {
double saleprice;
saleprice = this.getRegularPrice() + (this.getRegularPrice() * (15 / 100));
return saleprice; }
@Override public String toString() { return ".Publisher: " + getPublisher() + "\t Price: " + computeSalePrice()+"\t YearPublished: "+getYearPublished(); } }
//////////////////////////////
package march11;
public class Cartoon extends Book {
private String characterName;
public Cartoon(double regularPrice, String publisher, int yearPublished, String characterName) { super(regularPrice, publisher, yearPublished); this.characterName = characterName; }
public double computeSalePrice() { double saleprice;
saleprice = this.getRegularPrice() + (this.getRegularPrice() * (5 / 100));
return saleprice; }
@Override public String toString() { return ".Publisher: " + getPublisher() + "\t Price: " + computeSalePrice()+"\t YearPublished: "+getYearPublished()+"\t CharacterName: "+characterName; } }
//////////////////////////////
package march11;
public interface BookInterfacee extends productlnterface {//????? ??????
public String getPublisher();
public void setPublisher(String publisher);
public int getYearPublished();
public void setYearPublished(int yearPublished);
}
//////////////////////////////
package march11;
public abstract class Book extends product implements BookInterfacee {
private String publisher; private int yearPublished;
public Book(double regularPrice, String publisher, int yearPublished) { super(regularPrice); this.publisher = publisher; this.yearPublished = yearPublished; }
@Override public String getPublisher() { return publisher; }
@Override public void setPublisher(String publisher) { this.publisher = publisher; }
public int getYearPublished() { return yearPublished; }
public void setYearPublished(int yearPublished) { this.yearPublished = yearPublished; }
public double computeSalePrice() {
double saleprice;
saleprice = this.getRegularPrice() + (this.getRegularPrice() * (20 / 100));
return saleprice; }
@Override public abstract String toString() ;
}
///////////////////////////////////
package march11;
public class Application {
public static void main(String[] args) { new Main(); }
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
