Guest User

Untitled

a guest
Jul 21st, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.06 KB | None | 0 0
  1. import javax.swing.JOptionPane;
  2. import java.text.*;
  3. public class MunKit{
  4. public static void main(String[] args){
  5. DecimalFormat df = new DecimalFormat("#.00");
  6. int decision = JOptionPane.YES_OPTION;
  7. double paymentDay, paymentNight, amountRegular;
  8. do{
  9. String accountNo = JOptionPane.showInputDialog(
  10. null,"Please Enter Your Account Number.","Bill Calculator",
  11. JOptionPane.QUESTION_MESSAGE);
  12. if(accountNo == null)break;
  13. String serviceCode = JOptionPane.showInputDialog(
  14. null,"Please Enter Your Service Code:" + "\nPremium = P / p" +
  15. "\nRegular = R / r","Bill Calculator",JOptionPane.QUESTION_MESSAGE);
  16. char charServiceCode = serviceCode.toUpperCase().charAt(0);
  17. if(charServiceCode == 'P'){
  18. String serviceType = "Premium";
  19. String calltimeDay = JOptionPane.showInputDialog(
  20. null,"Please Enter Minutes Called During The Day This Month?",
  21. "Bill Calculator (PREMIUM)",JOptionPane.QUESTION_MESSAGE);
  22. double dblCalltimeDay = Double.parseDouble(calltimeDay);
  23. if(dblCalltimeDay < 75 ){
  24. paymentDay = 0;
  25. }else{
  26. paymentDay = (dblCalltimeDay - 75)*0.1;
  27. }
  28. String calltimeNight = JOptionPane.showInputDialog(
  29. null,"Please Enter Minutes Called During The Night This Month?",
  30. "Bill Calculator (PREMIUM)",JOptionPane.QUESTION_MESSAGE);
  31. double dblCalltimeNight = Double.parseDouble(calltimeNight);
  32. if(dblCalltimeNight < 100 ){
  33. paymentNight = 0;
  34. }else{
  35. paymentNight = (dblCalltimeNight - 100)*0.05;
  36. }
  37. double amountPremium = 25 + paymentNight + paymentDay;
  38. JOptionPane.showMessageDialog(null,"Here Is Your Bill Information:" +
  39. "\nAccount No: " + accountNo + "\nService Type: " + serviceType +
  40. "\nCall Time (Day): " + calltimeDay + " minutes" +
  41. "\nCall Time (Night): " + calltimeNight +" minutes" +
  42. "\nAmount Due: RM" + df.format(amountPremium),
  43. "Bill Calculator (PREMIUM)",JOptionPane.INFORMATION_MESSAGE);
  44. }else if(charServiceCode == 'R'){
  45. String serviceType = "Regular";
  46. String calltime = JOptionPane.showInputDialog(
  47. null,"Please Enter Minutes Called This Month",
  48. "Bill Calculator (REGULAR)",JOptionPane.QUESTION_MESSAGE);
  49. double dblCalltime = Double.parseDouble(calltime);
  50. if(dblCalltime > 50){
  51. amountRegular = 10 + ((dblCalltime - 50)*0.2);
  52. }else{
  53. amountRegular = 10;
  54. }
  55. JOptionPane.showMessageDialog(null,"Here Is Your Bill Information:" +
  56. "\nAccount No: " + accountNo + "\nService Type: " + serviceType +
  57. "\nCall Time : " + calltime + " minutes" +
  58. "\nAmount Due: RM" + df.format(amountRegular),
  59. "Bill Calculator (REGULAR)",JOptionPane.INFORMATION_MESSAGE);
  60. }else{
  61. JOptionPane.showMessageDialog(null,"The Service Code Entered Is Invalid.",
  62. "Bill Calculator (ERROR)",JOptionPane.ERROR_MESSAGE);
  63. }
  64. decision = JOptionPane.showConfirmDialog(
  65. null,"Would You Like To Restart The Program?","Bill Calculator",
  66. JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
  67. }while(decision == JOptionPane.YES_OPTION);
  68. }
  69. }
Add Comment
Please, Sign In to add comment