Skip to main content

Java Program to make a Grocery Bill






The First Class is Discount which extends the Grocery Bill Class :-

public class Discount extends GroceryBill{
boolean preffered = true ;
private double d=0 ;

GroceryBill gb = new GroceryBill() ;

public Discount(Employee e ,boolean preffered)
{

}

// disc count amount percent ;

public void DiscountCount()
{
int a = 0 ;
for(Item i : al)
{
if(i.getdiscount()>0)
{
a++ ;
}
}
System.out.println("------------------------------------");
System.out.println("Total Discount Items : " + a);
// System.out.println("------------------------------------");
}

public void DiscountAmount()
{

for(Item i : al)
{
d+=(i.getprice()*i.getdiscount()) ;
}
System.out.println("------------------------------------");
System.out.printf("Total Discount Amount : %.2f", d);
System.out.println("");
}
public void DiscountPer()
{
double p=0 ,q ;

for(Item i : al)
{
p+=i.getdiscount() ;
}
q = d/total * 100 ;
System.out.println("----------------------------------");
System.out.printf("Total Percentage : %.2f" , q ) ;
System.out.println("%");
}

public void print(boolean b)
{
if(b)
{
DiscountAmount();
}
else
d = 0 ;
}

public void NetBill()
{
double n = total - d ;
System.out.println("------------------------------------");
System.out.printf("Net Amount Bill : %.2f" , n);
}
}






The Next Class is Employee :-


public class Employee {

private String EmpName ;
private String seat ;

public Employee(String n)
{
EmpName = n ;
// seat = s ;
}

public String getEmpName()
{
return EmpName ;
}
public String getseat()
{
return seat ;
}

}




The Next Class is GroceryBill :-

import java.util.ArrayList;

public class GroceryBill {
public double total ;
Employee e ;

ArrayList<Item> al = new ArrayList<Item>();
public GroceryBill() {

}

public GroceryBill(Employee e)
{
this.e = e ;
}

public void Add(Item i)
{
al.add(i);
}

public void gettotal()
{
total=0 ;
for(Item i : al)
{
total +=  i.getprice();
}
System.out.println("Total :             " + total);
}
public void printitem()
{
for(Item i : al)
{
System.out.println(i.getname()+"               "+i.getprice()+"             "+i.getdiscount());
}
}

public void printReciept()
{
System.out.print("NAME               " + "PRICE             " + "DISCOUNT     ");
System.out.println(" ");
printitem();
System.out.println("============================================");
gettotal();
System.out.println("*************************************************");
// System.out.print("");
}

}





The Next Class is item :-


public class Item {

private String name ;
private double price ;
private double discount ;

public Item(String n , double p , double d)
{
name = n ;
price = p ;
discount = d ;
}

public String getname()
{
return name ;
}
public double getprice()
{
return price;
}
public double getdiscount()
{
return discount ;
}


}

The Next Class is main Class to execute the code :-


public class Main {

public static void main(String[] args) {

boolean Preferred = true ;

Discount db=new Discount(new Employee("clerk"),!Preferred);
db.Add(new Item("Apple",15.0,0.20));
db.Add(new Item("Mango",10.0,0.00));
db.Add(new Item("Sugar",2.56,0.25));
db.Add(new Item("Flour",7.56,0.05));
db.Add(new Item("Scent",9.61,0.20));
db.Add(new Item("Wheat",11.0,0.00));
db.printReciept();
db.DiscountCount();
db.DiscountAmount();
db.DiscountPer();
db.print(!Preferred);
db.NetBill();

}

}







Keep Sharing !

Comments

Popular posts from this blog

a speculative study of bscs

BSCS STUDENTS AND A CONTEMPORARY FIELD: A SPECULATIVE STUDY TABLE OF CONTENTS EXECUTIVE SUMMARY……………………………………………………………………….4 HISTORY…………………………………………………………………………………………5-6 MODERN TRENDS………………………………………………………………………………7-8 INTRODUCTION…………………………………………………………………………………8 PROCEDURES……………………………………………………………………………………8 METHADOLOGY--------------------------------------------------------------------------------------------9 THEORY OF COMPUTER SCIENCE--------------------------------------------------------------------9 THEORY OF COMPUTATION----------------------------------------------------------------------------10 ALGORITHAM & DATA STRUCTURE-----------------------------------------------------------------10 PROGRAMMING LANGUAGE THEORY---------------------------------------------------------------10 FINDINGS…………………………………………………………………………………………11-14 ANALYSIS………………………………………………………………………………………..15 RECOMMENDATIONS………………………………………………………………………….15 CONCLU...

Technology

Virtual Reality The Next Upcoming Domain in Pakistan is VIRTUAL REALITY and people are making themselves obsessed with it because it takes your imagination to what you are seeing through VR gadget as we know the technology is going to boom in Pakistan through last few years.

Cricket Match

Finally International Cricket again hit the Grounds of Pakistan  Now in Pakistan the Best thing is to about the start of International cricket. Finally the cricket hits the Ground of Pakistan with this phase of  WORLD IX vs PAKISTAN. The schedule is for three days continuous 12 , 13 , 14 September 2017. The all matches will be play in Gaddafi Stadium Lahore , as a FINAL of PSL 02 was also held there.The recent picture is as shown below from Lahore Stadium Cricket is one of the most favourite game of Pakistani's and we love cricket more than our National game because all we like to say that         ↪ "YAR CRICKET LOVE HAI''  We Pakistani's consider to be the most craziest fan's of CRICKET. As we are also moving towards PSL 03 and all the matches are probably be going to Play in Pakistan. The more is coming to pakistan with the passage of time we are moving forward to Meet the International Cricket Standards. Wish All the Be...