Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  PurchaseBill.java
Language: JAVA
Code:
 import java.util.Scanner;

class PurchaseBill
{
int billId,pno,i,pid;
//String Cust;
float billAmount,pc,sum;
String typeofCustomer;
//public void Purchase(String c,float b,String t)
//{
//     Customer=c;
//     billAmount=b;
//     typeofCustomer=t;

//} 

public void enterdata()
{     
     Scanner sc=new Scanner(System.in);
     
     //billid enter only once
     System.out.println("enter billId id:\n");
     pid=sc.nextInt();

     System.out.println("enter customer name:\n");
      typeofCustomer=sc.nextLine();

     System.out.println("enter number of products:\n ");
     pno=sc.nextInt();
     for(i=0;i<pno;i++)
     {
     System.out.println("enter product id:\n");
     pid=sc.nextInt();

     System.out.println("enter product price:\n");
      pc=sc.nextFloat();
     
     
     }
}
public int getBillid()
     {
     System.out.println("billId:=%d"+billId);
     }

public void getCustomer()
     {
     System.out.println("customer name:=%s"+typeofCustomer);
     }

public void calculateBillAmount()
     {
     for(i=0;i<pno;i++)
     {
      sum=sum+pc;
     }
     }

public void billDisplay()
     {
     getBillid();
     getCustomer();     
     calculateBillAmount();
     System.out.println("customer name:%s"+typeofCustomer);
     System.out.println("total price:=%d"+sum);
}
public static void main(String ars[])
{
     PurchaseBill p1=new PurchaseBill();
     p1.enterdata();
     p1.billDisplay();
}

}
Comments: