import java.util.Scanner;
public class CellPhoneBillGenerator
{
public static void main (String[] args)
{
int minutesUsed;
double totalCharge, rateR = 39.95, extra1R = 0.55, extra2R = .88;
double rateB = 69.95, extra1B = 0.45, extra2B = 0.99;
char customerType; // R - for residential, B - for business
char phoneNumber;
System.out.println ("\t\t Phone Bill Generation Software");
System.out.println ("\t\t ============================ ");
Scanner scan = new Scanner(System.in); //Creates a Scanner
System.out.println ("Enter minutes used: ");
minutesUsed = scan.nextInt();
System.out.println ("Please enter Customer Type: ");
System.out.println ("For example, R - for residential, or B - for business");
customerType = scan.nextChar();
System.out.println ("Please enter the customer phone number: ");
phoneNumber = scan.nextChar();
System.out.println ("Enter the phone usage in minutes: ");
minutesUsed = scan.nextInt();
}
}
7 Replies - 5843 Views - Last Post: 28 February 2009 - 08:31 PM
#1
I need help writing a phone number in format ###-###-####
Posted 28 February 2009 - 03:59 PM
Replies To: I need help writing a phone number in format ###-###-####
#2
Re: I need help writing a phone number in format ###-###-####
Posted 28 February 2009 - 04:04 PM
Save the phone number as a String not a char, as phone numbers are typically bigger than 1 digit.
You will have to elborate more to what you want, the user to enter in this format, print in this format, etc.
Also post your code like:
You can edit your post to do this.
You will have to elborate more to what you want, the user to enter in this format, print in this format, etc.
Also post your code like:
You can edit your post to do this.
#3
Re: I need help writing a phone number in format ###-###-####
Posted 28 February 2009 - 04:40 PM
This is my assignment. I'm pretty sure I can figure it out. I just need help with the phone format, getting the dashes of hyphens in between the numbers. I may need help later with the if/else statements or maybe I have to use case/break statements. Not sure yet. Anyway, below is the assignment with the output and printouts. Thanks
Suppose you are given a contract to develop a system that generates bills for a cellular phone company. Company has two types of customers: Regular ®, Business (
.
For business customers:
Monthly base payment is $99.99 and the first 600 minutes are free. For next 100 minutes (stage1), company charges $0.45 per minute. Other remaining minutes (stage2) cost $0.99 per minute.
For regular customers:
Monthly base payment is $ 29.99 and the first 200 minutes are free. For next 250 units (stage 1), cost $0.55 per minute. Other remaining units (stage 2) cost $ 0.88 per unit.
Develop a program that reads customer information (as shown below) including the phone usage (in minutes) from the keyboard and produces the phone bill according to the criteria given above. Please see the sample system input/output given below for a Regular Customer. Similar output will be produced for Business Customers.
Read data from the keyboard:
Phone Bill Generation Software
Pleas Enter the Customer Type (R for Regular, B for Business): R [enter]
Pleas Enter the Customer Phone Number: 480-897-8978 [enter]
Enter the phone usage in minutes: 476 [enter]
Bill as appears in the screen:
Power Bill for: 480-897-8978
= = = = = = = = = = =
Total Minutes Used= 476
I Monthly base payment : $ 29.99
Cost for stage1 units: $ 137.50
Cost for stage2 units: $ 22.88
Total Cost: $190.37
[ import java.util.Scanner;
public class CellPhoneBillGenerator
{
public static void main (String[] args)
{
int minutesUsed;
double totalCharge, rateR = 39.95, extra1R = 0.55, extra2R = .88;
double rateB = 69.95, extra1B = 0.45, extra2B = 0.99;
char customerType; // R - for residential, B - for business
String phoneNumber;
System.out.println ("\t\t Phone Bill Generation Software");
System.out.println ("\t\t ============================ ");
Scanner scan = new Scanner(System.in); //Creates a Scanner
System.out.println ("Enter minutes used: ");
minutesUsed = scan.nextInt();
System.out.println ("Please enter Customer Type: ");
System.out.println ("For example, R - for residential, or B - for business");
customerType = scan.nextChar();
System.out.println ("Please enter the customer phone number: ");
phoneNumber = scan.nextString();
System.out.println ("Enter the phone usage in minutes: ");
minutesUsed = scan.nextInt();
}
} ]
Suppose you are given a contract to develop a system that generates bills for a cellular phone company. Company has two types of customers: Regular ®, Business (
For business customers:
Monthly base payment is $99.99 and the first 600 minutes are free. For next 100 minutes (stage1), company charges $0.45 per minute. Other remaining minutes (stage2) cost $0.99 per minute.
For regular customers:
Monthly base payment is $ 29.99 and the first 200 minutes are free. For next 250 units (stage 1), cost $0.55 per minute. Other remaining units (stage 2) cost $ 0.88 per unit.
Develop a program that reads customer information (as shown below) including the phone usage (in minutes) from the keyboard and produces the phone bill according to the criteria given above. Please see the sample system input/output given below for a Regular Customer. Similar output will be produced for Business Customers.
Read data from the keyboard:
Phone Bill Generation Software
Pleas Enter the Customer Type (R for Regular, B for Business): R [enter]
Pleas Enter the Customer Phone Number: 480-897-8978 [enter]
Enter the phone usage in minutes: 476 [enter]
Bill as appears in the screen:
Power Bill for: 480-897-8978
= = = = = = = = = = =
Total Minutes Used= 476
I Monthly base payment : $ 29.99
Cost for stage1 units: $ 137.50
Cost for stage2 units: $ 22.88
Total Cost: $190.37
[ import java.util.Scanner;
public class CellPhoneBillGenerator
{
public static void main (String[] args)
{
int minutesUsed;
double totalCharge, rateR = 39.95, extra1R = 0.55, extra2R = .88;
double rateB = 69.95, extra1B = 0.45, extra2B = 0.99;
char customerType; // R - for residential, B - for business
String phoneNumber;
System.out.println ("\t\t Phone Bill Generation Software");
System.out.println ("\t\t ============================ ");
Scanner scan = new Scanner(System.in); //Creates a Scanner
System.out.println ("Enter minutes used: ");
minutesUsed = scan.nextInt();
System.out.println ("Please enter Customer Type: ");
System.out.println ("For example, R - for residential, or B - for business");
customerType = scan.nextChar();
System.out.println ("Please enter the customer phone number: ");
phoneNumber = scan.nextString();
System.out.println ("Enter the phone usage in minutes: ");
minutesUsed = scan.nextInt();
}
} ]
#4
Re: I need help writing a phone number in format ###-###-####
Posted 28 February 2009 - 04:51 PM
Quote
Read data from the keyboard:
Phone Bill Generation Software
Pleas Enter the Customer Type (R for Regular, B for Business): R [enter]
Pleas Enter the Customer Phone Number: 480-897-8978 [enter]
Enter the phone usage in minutes: 476 [enter]
Bill as appears in the screen:
Power Bill for: 480-897-8978
= = = = = = = = = = =
Total Minutes Used= 476
I Monthly base payment : $ 29.99
Cost for stage1 units: $ 137.50
Cost for stage2 units: $ 22.88
Total Cost: $190.37
Phone Bill Generation Software
Pleas Enter the Customer Type (R for Regular, B for Business): R [enter]
Pleas Enter the Customer Phone Number: 480-897-8978 [enter]
Enter the phone usage in minutes: 476 [enter]
Bill as appears in the screen:
Power Bill for: 480-897-8978
= = = = = = = = = = =
Total Minutes Used= 476
I Monthly base payment : $ 29.99
Cost for stage1 units: $ 137.50
Cost for stage2 units: $ 22.88
Total Cost: $190.37
It appears as if the user is suppossed to input the number in this format, do you wish to make sure it is entered in this format through some sort of validation?
#5
Re: I need help writing a phone number in format ###-###-####
Posted 28 February 2009 - 04:59 PM
Well, when I run the program and it asks the user to Enter a phone number, I want to enter it like (333-333-3333) but it just gives me an error message. I want the user to be able to enter it as 333-333-3333 not 3333333333 and also display the print out in the format 333-333-3333 not 3333333333. I know I'm kind of dumb but this is very much appreciated.
#6
Re: I need help writing a phone number in format ###-###-####
Posted 28 February 2009 - 05:52 PM
did you change the type from char to String? and also need to modify nextChar
#7
Re: I need help writing a phone number in format ###-###-####
Posted 28 February 2009 - 07:43 PM
Yes, here is what I have so far.
import java.util.Scanner;
public class CellPhoneBillGenerator
{
public static void main (String[] args)
{
int minutesUsed;
double totalCharge, rateR = 39.95, extra1R = 0.55, extra2R = .88;
double rateB = 69.95, extra1B = 0.45, extra2B = 0.99;
char customerType; // R - for residential, B - for business
String phoneNumber;
System.out.println ("\t\t Phone Bill Generation Software");
System.out.println ("\t\t ============================ ");
Scanner scan = new Scanner(System.in); //Creates a Scanner
System.out.println ("Enter minutes used: ");
minutesUsed = scan.nextInt();
System.out.println ("Please enter Customer Type: ");
System.out.println ("For example, R - for residential, or B - for business");
customerType = scan.nextChar();
System.out.println ("Please enter the customer phone number: ");
phoneNumber = scan.nextString();
System.out.println ("Enter the phone usage in minutes: ");
minutesUsed = scan.nextInt();
}
}
#8
Re: I need help writing a phone number in format ###-###-####
Posted 28 February 2009 - 08:31 PM
What error message does this give you?
Also why do you prompt twice for the minutes used?
Also why do you prompt twice for the minutes used?
Page 1 of 1

New Topic/Question
Reply



MultiQuote



|