Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- import java.text.*;
- public class MunKit{
- public static void main(String[] args){
- DecimalFormat df = new DecimalFormat("#.00");
- int decision = JOptionPane.YES_OPTION;
- double paymentDay, paymentNight, amountRegular;
- do{
- String accountNo = JOptionPane.showInputDialog(
- null,"Please Enter Your Account Number.","Bill Calculator",
- JOptionPane.QUESTION_MESSAGE);
- if(accountNo == null)break;
- String serviceCode = JOptionPane.showInputDialog(
- null,"Please Enter Your Service Code:" + "\nPremium = P / p" +
- "\nRegular = R / r","Bill Calculator",JOptionPane.QUESTION_MESSAGE);
- char charServiceCode = serviceCode.toUpperCase().charAt(0);
- if(charServiceCode == 'P'){
- String serviceType = "Premium";
- String calltimeDay = JOptionPane.showInputDialog(
- null,"Please Enter Minutes Called During The Day This Month?",
- "Bill Calculator (PREMIUM)",JOptionPane.QUESTION_MESSAGE);
- double dblCalltimeDay = Double.parseDouble(calltimeDay);
- if(dblCalltimeDay < 75 ){
- paymentDay = 0;
- }else{
- paymentDay = (dblCalltimeDay - 75)*0.1;
- }
- String calltimeNight = JOptionPane.showInputDialog(
- null,"Please Enter Minutes Called During The Night This Month?",
- "Bill Calculator (PREMIUM)",JOptionPane.QUESTION_MESSAGE);
- double dblCalltimeNight = Double.parseDouble(calltimeNight);
- if(dblCalltimeNight < 100 ){
- paymentNight = 0;
- }else{
- paymentNight = (dblCalltimeNight - 100)*0.05;
- }
- double amountPremium = 25 + paymentNight + paymentDay;
- JOptionPane.showMessageDialog(null,"Here Is Your Bill Information:" +
- "\nAccount No: " + accountNo + "\nService Type: " + serviceType +
- "\nCall Time (Day): " + calltimeDay + " minutes" +
- "\nCall Time (Night): " + calltimeNight +" minutes" +
- "\nAmount Due: RM" + df.format(amountPremium),
- "Bill Calculator (PREMIUM)",JOptionPane.INFORMATION_MESSAGE);
- }else if(charServiceCode == 'R'){
- String serviceType = "Regular";
- String calltime = JOptionPane.showInputDialog(
- null,"Please Enter Minutes Called This Month",
- "Bill Calculator (REGULAR)",JOptionPane.QUESTION_MESSAGE);
- double dblCalltime = Double.parseDouble(calltime);
- if(dblCalltime > 50){
- amountRegular = 10 + ((dblCalltime - 50)*0.2);
- }else{
- amountRegular = 10;
- }
- JOptionPane.showMessageDialog(null,"Here Is Your Bill Information:" +
- "\nAccount No: " + accountNo + "\nService Type: " + serviceType +
- "\nCall Time : " + calltime + " minutes" +
- "\nAmount Due: RM" + df.format(amountRegular),
- "Bill Calculator (REGULAR)",JOptionPane.INFORMATION_MESSAGE);
- }else{
- JOptionPane.showMessageDialog(null,"The Service Code Entered Is Invalid.",
- "Bill Calculator (ERROR)",JOptionPane.ERROR_MESSAGE);
- }
- decision = JOptionPane.showConfirmDialog(
- null,"Would You Like To Restart The Program?","Bill Calculator",
- JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
- }while(decision == JOptionPane.YES_OPTION);
- }
- }
Add Comment
Please, Sign In to add comment