6 Replies - 281 Views - Last Post: 08 June 2019 - 04:22 AM Rate Topic: -----

#1 count1010   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 07-June 19

How can I pull the input from a variable to display the totalMinutes w

Posted 07 June 2019 - 04:46 PM

Any assistance would be greatly appreciated, because I'm stumped.

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);
	            			}
		}
	}


Is This A Good Question/Topic? 0
  • +

Replies To: How can I pull the input from a variable to display the totalMinutes w

#2 count1010   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 07-June 19

Re: How can I pull the input from a variable to display the totalMinutes w

Posted 07 June 2019 - 04:54 PM

How can I pull the input from a variable to display the totalMinutes without disrupting the calculation in the following program?
Was This Post Helpful? 0
  • +
  • -

#3 NormR   User is offline

  • D.I.C Lover
  • member icon

Reputation: 775
  • View blog
  • Posts: 5,836
  • Joined: 25-December 13

Re: How can I pull the input from a variable to display the totalMinutes w

Posted 07 June 2019 - 05:14 PM

What variable has the value? Where in the program does the code want to get the value?
When is the desired value available in the variable?

Quote

disrupting the calculation in the following program?

What does that mean?

Note: The variable names: a and b are a very poor choice.
Please rename them to have names that describe the values that they contain.

This post has been edited by NormR: 07 June 2019 - 05:17 PM

Was This Post Helpful? 0
  • +
  • -

#4 count1010   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 07-June 19

Re: How can I pull the input from a variable to display the totalMinutes w

Posted 08 June 2019 - 03:28 AM

In this block of code I want the following output:
Account Num: (#)
Account Type: (Regular or Premium) - Assignment calls to compare R & r o P & p.
Account Minutes Used: (#) - Regular should show one # and Premium should show day and night number.
Amount Due: (#)
All outputs work except (Account Minutes Used:)
I'm very new to asking for assistance and wasn't aware of how to ask this. Thank you all for the coaching.
public static void serviceSwitch(char serviceType) 
	{
		switch (serviceType) 
		{
		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);
	            			}
		}

Was This Post Helpful? 0
  • +
  • -

#5 NormR   User is offline

  • D.I.C Lover
  • member icon

Reputation: 775
  • View blog
  • Posts: 5,836
  • Joined: 25-December 13

Re: How can I pull the input from a variable to display the totalMinutes w

Posted 08 June 2019 - 04:08 AM

Quote

All outputs work except (Account Minutes Used:)

What does "work except" mean? What does the program do or not do that you want to change?
Was This Post Helpful? 0
  • +
  • -

#6 count1010   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 07-June 19

Re: How can I pull the input from a variable to display the totalMinutes w

Posted 08 June 2019 - 04:15 AM

View PostNormR, on 08 June 2019 - 04:08 AM, said:

Quote

All outputs work except (Account Minutes Used:)

What does "work except" mean? What does the program do or not do that you want to change?


Minutes used does not output.

Regular should give a total minutes used and premium should show day and night minutes used.
Was This Post Helpful? 0
  • +
  • -

#7 NormR   User is offline

  • D.I.C Lover
  • member icon

Reputation: 775
  • View blog
  • Posts: 5,836
  • Joined: 25-December 13

Re: How can I pull the input from a variable to display the totalMinutes w

Posted 08 June 2019 - 04:22 AM

Quote

Minutes used does not output.

What is the name of the variable you are talking about?
Are you saying that the contents of a variable is not shown?
Or are you saying that the contents of a variable that is shown is wrong?
If its value is shown, what is that value?

Where is that variable assigned a value?

This post has been edited by NormR: 08 June 2019 - 04:23 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1