Guest User

Untitled

a guest
Jul 21st, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. import javax.swing.JOptionPane;
  2.  
  3. public class TeleBill {
  4. public static void main(String[]args){
  5.  
  6. String accountID, accountType, rTime, pDayTime, pNightTime;
  7. int rTimeI, pDayTimeI, pNightTimeI;
  8. double amount, usagePrice, usagePriceDay, usagePriceNight, usagePricePremium, amountPremium;
  9. final double regularBasePrice = 10.00;
  10. final double premiumBasePrice = 25.00;
  11.  
  12. accountID = JOptionPane.showInputDialog(null,
  13. "Enter your account ID","Account ID",JOptionPane.QUESTION_MESSAGE);
  14. accountType = JOptionPane.showInputDialog(null,
  15. "Enter your Account Type 'R' for regular or 'P' for premium","Account Type",JOptionPane.QUESTION_MESSAGE);
  16. char type = accountType.toUpperCase().charAt(0);
  17.  
  18. if(type=='R'){
  19. rTime = JOptionPane.showInputDialog(null,
  20. "Please enter your minute used: ", "Phone Bill Regular", JOptionPane.QUESTION_MESSAGE);
  21.  
  22. rTimeI = Integer.parseInt(rTime);
  23.  
  24. if(rTimeI < 50){
  25. amount = regularBasePrice;
  26. }else{
  27. usagePrice = (rTimeI - 50) * 0.20;
  28. amount = regularBasePrice + usagePrice;
  29. }
  30. JOptionPane.showMessageDialog(null,"Account ID = " + accountID + "\nAccount Type = Regular" +
  31. "\nMinutes used = " + rTime +
  32. "\nAmount Due = RM" + amount);
  33. }
  34.  
  35. else if(type=='P'){
  36. pDayTime = JOptionPane.showInputDialog(null,
  37. "Please enter your minute used during the Day: ", "Phone Bill Premium Day", JOptionPane.QUESTION_MESSAGE);
  38. pDayTimeI = Integer.parseInt(pDayTime);
  39. pNightTime = JOptionPane.showInputDialog(null,
  40. "Please enter your minute used during the Night: ", "Phone Bill Premium Night", JOptionPane.QUESTION_MESSAGE);
  41. pNightTimeI = Integer.parseInt(pNightTime);
  42. if(pDayTimeI <= 75 && pNightTimeI <= 100){
  43. amountPremium = premiumBasePrice;
  44. }else {
  45.  
  46. usagePriceDay = pDayTimeI * 0.10;
  47. usagePriceNight = pNightTimeI * 0.050;
  48. usagePricePremium = ((pDayTimeI - 75)+(pNightTimeI - 100)*0.20);
  49. amountPremium = premiumBasePrice + usagePricePremium;
  50. }
  51. JOptionPane.showMessageDialog(null,"Account ID = " + accountID +
  52. "\nService Type = Premium" +
  53. "\nMinutes Used During The Day = " + pDayTimeI +
  54. "\nMinutes Used During The Night = " + pNightTimeI +
  55. "\nAmount Due = RM" + amountPremium);
  56. }
  57.  
  58. }
Add Comment
Please, Sign In to add comment