Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: How can I pull the input from a variable to display the totalMinutes without disrupting the calculation in the following program?

  1. #1
    Junior Member
    Join Date
    Jun 2019
    Posts
    2
    My Mood
    Where
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How can I pull the input from a variable to display the totalMinutes without disrupting the calculation in the following program?

    ...
    Last edited by Count10101; June 8th, 2019 at 06:38 AM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How can I pull the input from a variable to display the totalMinutes without disrupting the calculation in the following program?

    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jun 2019
    Posts
    2
    My Mood
    Where
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How can I pull the input from a variable to display the totalMinutes without disrupting the calculation in the following program?

    ...
    Last edited by Count10101; June 8th, 2019 at 06:38 AM.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How can I pull the input from a variable to display the totalMinutes without disrupting the calculation in the following program?

    Why did you delete the code?
    For anyone interested, here is the code:
    import javax.swing.JOptionPane;
     
    public class CellPhoneBill 
    {
     
        public static int accountNum, dayMinutes, nightMinutes, totalMinutes,
            acctCall;
        public static char serviceCode, serviceCall;
        public static double amountDue;
        public static String outputStr, acctStr, serviceStr;
     
        public static void main(String[] args) 
        {
            getAccountNum(accountNum);
            getServiceCode(serviceCode);
            serviceSwitch(serviceCode);
            System.exit(0);
        }
     
        public static double calculateRegBill(int a) 
        {
            amountDue = 10;
            if (a > 50)
            amountDue = 10 + (a - 50) * .2;
            return amountDue;
        }
     
        public static double calculatePremBill(int a, int b) 
        {
            double dayCost = 0, nightCost = 0;
            if (a > 75)
                dayCost = (a - 75) * .1;
            if (b > 100)
                nightCost = (b - 100) * .05;
            amountDue = 25 + (nightCost + dayCost);
            return amountDue;    
        }
     
        public static int getAccountNum(int a) 
        {
            a = Integer.parseInt(JOptionPane.showInputDialog("Enter account number"));
            accountNum = a;
            return accountNum;
        }
     
        public static char getServiceCode(char b) 
        {
            b = JOptionPane.showInputDialog("Enter service code").charAt(0);
            serviceCode = b;
            return serviceCode;
        }
     
        public static void serviceSwitch(char a) 
        {
            switch (a) 
            {
            case 'r':
                case 'R':
                    amountDue = calculateRegBill(Integer.parseInt(JOptionPane.showInputDialog("Enter amount of " +
                    " minutes used in billing period")));
                    outputStr = "Account Num: " + accountNum + "\n Account Type" +
                    ": Regular" + "\nAccount Minutes Used: " + totalMinutes + "\nAmount Due: $" + String.format("%.2f", amountDue);
                    JOptionPane.showMessageDialog(null, outputStr, "Account" +
                    " Information", JOptionPane.INFORMATION_MESSAGE);
                    break;
                    case 'p':
                      case 'P':
                          dayMinutes = Integer.parseInt(JOptionPane.showInputDialog("Enter amount" +
                      "of minutes used between 6:00 a.m. to 6:00 p.m."));
                          nightMinutes = Integer.parseInt(JOptionPane.showInputDialog("Enter amount" +
                      "of minutes used between 6:00 p.m. to 6:00 a.m."));
                          amountDue = calculatePremBill(dayMinutes, nightMinutes);
                          outputStr = "Account Num: " + accountNum + "\n Account Type" + ": Premium" + 
                          "\nAccount Minutes Used: " + totalMinutes +
                          "\nAmount Due: $" + String.format("%.2f", amountDue);
                          JOptionPane.showMessageDialog(null, outputStr, "Account" +
                          " Information", JOptionPane.INFORMATION_MESSAGE);
                          break;
                          default:
                              JOptionPane.showMessageDialog(null, "Invalid Account type",
                                      "Account Information", JOptionPane.INFORMATION_MESSAGE);
                              }
            }
        }
    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    John Joe (June 9th, 2019)

Similar Threads

  1. Display a variable in exception catch
    By ebolisa in forum Exceptions
    Replies: 4
    Last Post: September 3rd, 2018, 05:12 PM
  2. Why can't I get my variable to display?
    By geovanniluna in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 24th, 2014, 10:04 AM
  3. [SOLVED] Tax calculation program
    By howardderamus1111 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 12th, 2014, 05:44 PM
  4. Replies: 2
    Last Post: February 28th, 2014, 09:39 AM
  5. GPA Calculation Program using an input file
    By ddk1992 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 6th, 2011, 06:28 AM

Tags for this Thread