Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- public class TeleBill {
- public static void main(String[]args){
- String accountID, accountType, rTime, pDayTime, pNightTime;
- int rTimeI, pDayTimeI, pNightTimeI;
- double amount, usagePrice, usagePriceDay, usagePriceNight, usagePricePremium, amountPremium;
- final double regularBasePrice = 10.00;
- final double premiumBasePrice = 25.00;
- accountID = JOptionPane.showInputDialog(null,
- "Enter your account ID","Account ID",JOptionPane.QUESTION_MESSAGE);
- accountType = JOptionPane.showInputDialog(null,
- "Enter your Account Type 'R' for regular or 'P' for premium","Account Type",JOptionPane.QUESTION_MESSAGE);
- char type = accountType.toUpperCase().charAt(0);
- if(type=='R'){
- rTime = JOptionPane.showInputDialog(null,
- "Please enter your minute used: ", "Phone Bill Regular", JOptionPane.QUESTION_MESSAGE);
- rTimeI = Integer.parseInt(rTime);
- if(rTimeI < 50){
- amount = regularBasePrice;
- }else{
- usagePrice = (rTimeI - 50) * 0.20;
- amount = regularBasePrice + usagePrice;
- }
- JOptionPane.showMessageDialog(null,"Account ID = " + accountID + "\nAccount Type = Regular" +
- "\nMinutes used = " + rTime +
- "\nAmount Due = RM" + amount);
- }
- else if(type=='P'){
- pDayTime = JOptionPane.showInputDialog(null,
- "Please enter your minute used during the Day: ", "Phone Bill Premium Day", JOptionPane.QUESTION_MESSAGE);
- pDayTimeI = Integer.parseInt(pDayTime);
- pNightTime = JOptionPane.showInputDialog(null,
- "Please enter your minute used during the Night: ", "Phone Bill Premium Night", JOptionPane.QUESTION_MESSAGE);
- pNightTimeI = Integer.parseInt(pNightTime);
- if(pDayTimeI <= 75 && pNightTimeI <= 100){
- amountPremium = premiumBasePrice;
- }else {
- usagePriceDay = pDayTimeI * 0.10;
- usagePriceNight = pNightTimeI * 0.050;
- usagePricePremium = ((pDayTimeI - 75)+(pNightTimeI - 100)*0.20);
- amountPremium = premiumBasePrice + usagePricePremium;
- }
- JOptionPane.showMessageDialog(null,"Account ID = " + accountID +
- "\nService Type = Premium" +
- "\nMinutes Used During The Day = " + pDayTimeI +
- "\nMinutes Used During The Night = " + pNightTimeI +
- "\nAmount Due = RM" + amountPremium);
- }
- }
Add Comment
Please, Sign In to add comment