Share on Google+Share on Google+

Product Register System using Java

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.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) {
this.quantity= quantity;
this.price = price;;;
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(;
int menu = 0;
System.out.println("School Registration System Main Menu");
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;
System.out.print("Please enter your choice: ");
menu = scan.nextInt();

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));
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));
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));
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.getTotal());
System.out.println("Total= "+sum);

System.out.println("Invalid Entry!");
while (!quit);


Posted on: October 23, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.