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

DTN

The word business is for them who use it in a efficient way to make a better way for their earning but now a days we don't consider a business who don't have their online presence because the people prefer online shopping rather then to go out for shopping because it requires time.So, that's why customers who do online shopping are more considerable to make your market better. In the same context   DTN founded to sell a quality authentic jadeite bangles now moving to digital landscape of shopping. Below are the details of their initiative which was initiated in 2004 DTN is found just recently, a merger between DDJADE and DTN . They sell good quality authentic jadeite bangles since 2014. Now, they are expanding it to technology products. Their vision and motto is selling good quality and authentic goods at fractional cost compared to big companies DDJADE was founded in 2014 with the mind set of providing authentic jade bangle, bracelet, silver and...

Graphic designing

Adobe Photoshop: The Best thing in this software is this it is a Collection of built in features and has more editor effect to use in its own way. You can also edit 2D and 3D animation in it and make it easy for Editing you can make Logos , Flyers , header all sort of things you have grip on.. Its has a proper suit for its users. The Adobe Photoshop is the Best app for editing Pictures either they are simple or high definition. Adobe Suit has more features more than we think and assume. The Best Graphic designer is used to from this that he or she will have much work for them they are in finding that SOFTWARE which make them easy to work for many hours. Are you curious to know about more ? https://blog.retouchmypic.com/professional/2017/09/19/5-ways-how-photoshop-changed-the-world/  Do Visit this Blog to know about the Photoshop Hacks  Keep Sharing !

Circle Square and Triangle in Java for GUI

Java Code of Shapes for Graphical User Interface: For Circle: import java.awt.*; import java.awt.geom.*; /**  * A circle that can be manipulated and that draws itself on a canvas.  *   * @author  Michael Kšlling and David J. Barnes  * @version 2011.07.31  */ public class Circle {     private int diameter;     private int xPosition;     private int yPosition;     private String color;     private boolean isVisible;          /**      * Create a new circle at default position with default color.      */     public Circle()     {         diameter = 68;         xPosition = 230;         yPosition = 90;         color = "blue";     }     /**      * Make...