Milk Men Bill Calculator
/**
* This is the Computer Applications Project for the year 2021-2022
* This is a small billing application done using basic java. In this
* application the values are accepted from the user and then bill is
* generated.
*
* @author Mr. Sumit Kole
* @version 03-09-2021
*/
import java.util.*;
import java.io.*;
class MilkMenBillCalculator
{
// instance variables
private final String DAIRYNAME="MILK SHAKTI", DAIRYADDRESS="Solapur Maharashtra";
private double milkPerLtr, totalBill, noOfLtrs, customerMobileNo;
private String customerName, customerAddress, month;
private int userChoice = 0,billingMonth;
private Scanner sc = new Scanner(System.in);
/**
* Constructor for objects of class MilkMenBillCalculator
*/
public MilkMenBillCalculator()
{
// initialise instance variables
customerName="";
customerAddress="";
customerMobileNo=0.0;
totalBill = 0.0;
noOfLtrs = 0.0;
milkPerLtr = 0.0;
}
public void displayProjectTitle()
{
System.out.println("\t\t\t\t\t **************** MILK SHAKTI ************** ");
}
public void displayMenu()
{
System.out.println("\t\t\t\t\t ================ MAIN MENU ================ ");
System.out.println("\t\t\t\t\t Press 1 For To Set The Milk Rate");
System.out.println("\t\t\t\t\t Press 2 For To Set The Billing Month");
System.out.println("\t\t\t\t\t Press 3 For To Calculate Bill");
System.out.println("\t\t\t\t\t Press 4 For To Exit");
System.out.println("\t\t\t\t\t ========================================== ");
System.out.print("\t\t\t\t\t Enter Your Choice = ");
userChoice = sc.nextInt();
if(userChoice>4 || userChoice<1){
System.out.println("\n\t\t\t\t\t Incorrect Choice ");
displayMenu();
}
else{
operateMenu(userChoice);
}
}
public void operateMenu(int userChoice){
switch(userChoice){
case 1 : setMilkRate();
displayMenu();
break;
case 2 : setBillingMonth();
displayMenu();
break;
case 3 : calculateBill();
displayMenu();
break;
case 4 : exitMessage();
}
}
public void setMilkRate()
{
System.out.print("\t\t\t\t\t Please Enter Milk Rate Per Liter :");
milkPerLtr = sc.nextDouble();
System.out.println("\n\t\t\t\t\t Milk Rate Per Liter Set Successfully ");
}
public void setBillingMonth()
{
System.out.print("\n\t\t\t\t\t Please Enter Billing Month : ");
billingMonth = sc.nextInt();
switch(billingMonth){
case 1: month="January";
break;
case 2: month="February";
break;
case 3: month="March";
break;
case 4: month="April";
break;
case 5: month="May";
break;
case 6: month="June";
break;
case 7: month="July";
break;
case 8: month="August";
break;
case 9: month="September";
break;
case 10: month="October";
break;
case 11: month="November";
break;
case 12: month="December";
break;
default:System.out.println("\t\t\t\t\t Please Enter Valid Billing Month");
setBillingMonth();
}
System.out.println("\t\t\t\t\t Billing Month Set Successfully");
}
public void calculateBill()
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try{
System.out.print("\t\t\t\t\t Enter Customer Name :");
customerName = br.readLine();
System.out.print("\n\t\t\t\t\t Enter Customer Mobile Number :");
customerMobileNo = sc.nextDouble();
System.out.print("\n\t\t\t\t\t Enter Customer Address :");
customerAddress=br.readLine();
System.out.print("\n\t\t\t\t\t Enter Number Of Liters :");
noOfLtrs = sc.nextDouble();
totalBill = noOfLtrs * milkPerLtr;
System.out.print("\n\n");
displayBill();
}
catch(IOException ioe){
System.out.println("\n \t\t\t\t\t Please Enter Valid Data ");
exitMessage();
}
catch(InputMismatchException ime){
System.out.println("\n \t\t\t\t\t Please Enter Nubers Only For Number Of Liters ");
exitMessage();
}
}
public void displayBill(){
System.out.print("\n\t\t\t\t\t ________________ "+DAIRYNAME+" _______________");
System.out.print("\n\t\t\t\t\t _______________"+DAIRYADDRESS+" ________");
System.out.print("\n\t\t\t\t\t ____________________________________________");
System.out.print("\n\t\t\t\t\t Bill For The Month : "+month);
System.out.print("\n\t\t\t\t\t Customer Name : "+customerName);
System.out.print("\n\t\t\t\t\t Customer Mobile No : "+customerMobileNo);
System.out.print("\n\t\t\t\t\t Address : "+customerAddress);
System.out.print("\n\t\t\t\t\t Total Liter : "+noOfLtrs);
System.out.print("\n\t\t\t\t\t Milk Per Liter : "+milkPerLtr);
System.out.print("\n\t\t\t\t\t Total Amount : "+totalBill);
System.out.println("\n\t\t\t\t\t ____________________________________________");
System.out.print("\t\t\t\t\t ____________________________________________");
System.out.print("\n\t\t\t\t\t Do You Want To Continue Y / N :");
char yesNo = sc.next().charAt(0);
System.out.print("\n");
if(yesNo == 'Y' || yesNo == 'y'){
displayMenu();
}
else{
exitMessage();
}
}
public void exitMessage(){
System.out.print("\n\t\t\t\t\t ____________________________________________");
System.out.print("\n\t\t\t\t\t _______________ Thank You! ____________");
System.out.print("\n\t\t\t\t\t ____________________________________________");
System.exit(1);
}
public static void main(String args[]){
MilkMenBillCalculator ob = new MilkMenBillCalculator();
ob.displayProjectTitle();
ob.displayMenu();
}
}
No comments:
New comments are not allowed.