Product Register System using Java


 

Product Register System using Java

In this section, you will learn how to create product register system using Java Program.

In this section, you will learn how to create product register system using Java Program.

Product Register System

In this section, you will learn how to create product register system. For this, we have categorized the products by code 1 (food), 2  (water), 3 (magazine), 4 (stationery) and 5  (toys).  We have given discount of  0% to product code 1 , 5% product code 2, 15% product code 3, 10% product code 4 and 0% product code 5. Then, we have used the switch case to allow the user to select  product category and enter quantity and price of that product. It will calculate the total price and display it.

Here is the code

import java.io.*;
import java.util.*;

class Register{
public String item;
public int quantity;
public double price;
public double discount;
public double total;

public Register(){}
public Register(String item,int quantity, double price,double discount,double total) {
super();
this.item=item;
this.quantity= quantity;
this.price = price;
this.discount=discount;
this.total=total;
}
public String getItem() {
return item;
}
public int getQuantity() {
return quantity;
}
public double getPrice() {
return price;
}
public double getDiscount() {
return discount;
}
public double getTotal() {
return total;
}
}
public class ProductRegisterSystem {
 
public static void main(String[] argsthrows Exception {
double sum=0.0;
List<Register> list = new ArrayList<Register>();
Scanner scan = new Scanner(System.in);
int menu = 0;
System.out.println("School Registration System Main Menu");
System.out.println();
System.out.println("1. Food");
System.out.println("2. Water");
System.out.println("3. Magazine");
System.out.println("4. Stationary");
System.out.println("5. Toys");
System.out.println("6. Exit");

boolean quit = false;
do{
System.out.print("Please enter your choice: ");
menu = scan.nextInt();
System.out.println();

switch(menu) {
case 1:
System.out.print("Quantity: ");
int q1 = scan.nextInt();
System.out.print("Price: ");
double p1 = scan.nextDouble();
double d1=0;
double t1=(p1-(d1*p1))*q1;
list.add(new Register("Food",q1,p1,d1,t1));
break;
case 2:
System.out.print("Quantity: ");
int q2 = scan.nextInt();
System.out.print("Price: ");
double p2 = scan.nextDouble();
double d2=0.05;
double t2=(p2-(d2*p2))*q2;
list.add(new Register("Water",q2,p2,d2,t2));
break;
case 3:
System.out.print("Quantity: ");
int q3 = scan.nextInt();
System.out.print("Price: ");
double p3 = scan.nextDouble();
double d3=0.15;
double t3=(p3-(d3*p3))*q3;
list.add(new Register("Magazine",q3,p3,d3,t3));
break;
case 4:
  System.out.print("Quantity: ");
int q4 = scan.nextInt();
System.out.print("Price: ");
double p4 = scan.nextDouble();
double d4=0.10;
double t4=(p4-(d4*p4))*q4;
list.add(new Register("Stationary",q4,p4,d4,t4));break;
case 5:
System.out.print("Quantity: ");
int q5 = scan.nextInt();
System.out.print("Price: ");
double p5 = scan.nextDouble();
double d5=0;
double t5=(p5-(d5*p5))*q5;
list.add(new Register("Toys",q5,p5,d5,t5));break;
case 6:
quit = true;
System.out.println("Items   Quantity   Price   Discount(%)   Total");
for (Register s : list){
System.out.println(s.getItem()+"        " +s.getQuantity()+"        "+s.getPrice()+"        " 
+s.getDiscount
()+"        " +s.getTotal());
 sum+=s.getTotal();
}
System.out.println("Total= "+sum);

break;
default:
System.out.println("Invalid Entry!");
 }
}
while (!quit);
}
}

Ads