Answer to Question #238290 in Web Development for Princess

Question #238290
Q.1.11
When the user selects to view a report, display the product report generated from the

arrays in your application. You must create a class called ReportData which will contain get and set methods for each item required in the report

Sample Report Screenshot

PRODUCT REPORT

PRODUCT 1

PRODUCT CODE>> PRODUCT NAME>>

PRODUCT PRODUCT

CATEGORY >> WARRANTY >>

PRODUCT PRICE >>

PRODUCT LEVEL >>

PRODUCT SUPPLIER >>

FRODUCT 3

PRODUCT CODE>>

PRODUCT

CATEGORY >>

PRODUCT VARAMITY >>

PRODUCT PRICE >>

PRODUCT LEVEL

>>

PRODUCT SUPPLIER

PRODUCT 3

PRODUCT CODE: >>>

PRODUCT KAME>>

PRODUCT CATEGORY PRODUCT WARRANTY >>

PRODUCT PRICE >>

PRODUCT LEVEL

PRODOCT SUPPLIER >>

2 years

14500.0

Q.1.11

2 years

22500.0

3

IT 4 Africa

ASS

2 years

8600 0

Gaming 4 Africa

TOTAL PRODUCT COUNT: 1

TOTAL PRODUCT VALUE: 15600.0 AVERAGE PRODUCT VALUZ a 11933

Intez (1) to launch nenu or any other key to exis
1
Expert's answer
2021-09-17T02:04:55-0400
import java.util.ArrayList;
import java.util.Scanner;

class Product{
private String code;
private String name;
private String categeory;
private int warranty;
private int price;
private int stockLevels;
private String supplier;

public Product() {
}

public Product(String code, String name, String categeory, int warranty, int price, int stockLevels, String supplier) {
this.code = code;
this.name = name;
this.categeory = categeory;
this.warranty = warranty;
this.price = price;
this.stockLevels = stockLevels;
this.supplier = supplier;
}

public void setCode(String code) {
this.code = code;
}

public void setName(String name) {
this.name = name;
}

public void setCategeory(String categeory) {
this.categeory = categeory;
}

public void setWarranty(int warranty) {
this.warranty = warranty;
}

public void setPrice(int price) {
this.price = price;
}

public void setStockLevels(int stockLevels) {
this.stockLevels = stockLevels;
}

public void setSupplier(String supplier) {
this.supplier = supplier;
}

public String getCode() {
return code;
}

public String getName() {
return name;
}

public String getCategeory() {
return categeory;
}

public int getWarranty() {
return warranty;
}

public int getPrice() {
return price;
}

public int getStockLevels() {
return stockLevels;
}

public String getSupplier() {
return supplier;
}

@Override
public String toString() {
  
return "Product{" + "code=" + code + ", name=" + name + ", categeory=" + categeory + ", warranty=" + warranty + ", price=" + price + ", stockLevels=" + stockLevels + ", supplier=" + supplier + '}';
}
  
  
}

public class NewClass2 {
static ArrayList<Product> list;
public static void main(String str[]){
int choice;
// Declaring the ArrayList
list = new ArrayList<Product>();
do{
displayMenu();
Scanner sc = new Scanner(System.in);
System.out.print("Enter choice : ");
choice = sc.nextInt();
  
switch(choice){
case 1:
Product newProduct = createProduct();
list.add(newProduct);
break;
case 2:
serachProduct();
break;
case 3:
updateProduct();
break;
case 4:
deleteProduct();
break;
}
System.out.print("Enter (1) to lanch menu or any other key to exit : ");
choice = sc.nextInt();
  

}while(choice==1);
  
}
public static void displayMenu(){
System.out.println(" 1-> Insert Item ");
System.out.println(" 2-> Serach Item ");
System.out.println(" 3-> Update Item ");
System.out.println(" 4-> Delate Item ");
}

private static Product createProduct() {
Product newProduct = new Product();
Scanner sc = new Scanner(System.in);
System.out.print("Enter the Product code : ");
newProduct.setCode(sc.next());
System.out.print("Enter the Product Name : ");
newProduct.setName(sc.next());
System.out.print("Enter the Product category : ");
newProduct.setCategeory(sc.next());
System.out.print("Enter the Product warranty : ");
newProduct.setWarranty(sc.nextInt());
System.out.print("Enter the Product price : ");
newProduct.setPrice(sc.nextInt());
System.out.print("Enter the Product Stock Levels : ");
newProduct.setStockLevels(sc.nextInt());
System.out.print("Enter the Product suppiler : ");
newProduct.setSupplier(sc.next());
  
return newProduct;
}

private static void serachProduct() {
Scanner sc = new Scanner(System.in);
String code;
int productFound =0;
System.out.print("Please enter the code to search : ");
code = sc.next();
for(int i = 0;i<list.size();i++){
if(list.get(i).getCode().equalsIgnoreCase(code)){
productFound++;
System.out.println("***************************************************************************************");
System.out.println("PRODUCT SERACH RESULTS");
System.out.println("***************************************************************************************");
System.out.println("PRODUCT CODE : "+list.get(i).getCode()) ;
System.out.println("PRODUCT NAME : "+list.get(i).getName());
System.out.println("PRODUCT CATEGEORY : "+list.get(i).getCategeory());
System.out.println("PRODUCT WARRANTY : "+list.get(i).getWarranty()+" years");
System.out.println("PRODUCT PRICE : R "+list.get(i).getPrice());
System.out.println("PRODUCT STOCK LEVELS : "+list.get(i).getStockLevels());
System.out.println("PRODUCT SUPPILER : "+list.get(i).getSupplier());
System.out.println("***************************************************************************************");
}
}
if( productFound == 0){
System.out.println("The product cannot be located. Invalid product");
}

}

private static void deleteProduct() {
Scanner sc = new Scanner(System.in);
String code;
String confirm;
System.out.print("Please enter the code for delete the product : ");
code = sc.next();
int productFound =0;
for(int i = 0;i<list.size();i++){
if(list.get(i).getCode().equalsIgnoreCase(code)){
productFound++;
System.out.print("Confirm that you want to delete the product(Yes/No) : ");
confirm = sc.next();
if(confirm.equalsIgnoreCase("YES")){
list.remove(i);
System.out.println("The product code "+ code+ " has been successfully deleted.");
}else{
System.out.println("The product code "+ code+ " can not deleted.");
}
}
}
if( productFound == 0){
System.out.println("The product cannot be located. Invalid product");
}

}

private static void updateProduct() {
Scanner sc = new Scanner(System.in);
String code;
int productFound =0;
String confirm;
System.out.print("Please enter the code to update the product : ");
code = sc.next();
for(int i = 0;i<list.size();i++){
if(list.get(i).getCode().equalsIgnoreCase(code)){
productFound++;
System.out.print("Updtae the product warranty(Yes/No): ");
confirm = sc.next();
if(confirm.equalsIgnoreCase("YES")){
System.out.print("Updated warranty : ");
list.get(i).setWarranty(sc.nextInt());
System.out.println("The warranty of product code "+ code+ " has been successfully updated.");
}

System.out.print("Updtae the product price(Yes/No) : ");
confirm = sc.next();
if(confirm.equalsIgnoreCase("YES")){
System.out.print("Updated price : ");
list.get(i).setPrice(sc.nextInt());
System.out.println("The price of product code "+ code+ " has been successfully updated.");
}
System.out.print("Updtae the product stock level(Yes/No) : ");
confirm = sc.next();
if(confirm.equalsIgnoreCase("YES")){
System.out.print("Updated stock level : ");
list.get(i).setStockLevels(sc.nextInt());
System.out.println("The stock level of product code "+ code+ " has been successfully updated.");
}
}
}
if( productFound == 0){
System.out.println("The product cannot be located. Invalid product");
}

}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS