Delete Post!
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.
Delete Post!
Last edited by OOO; April 25th, 2011 at 03:06 PM.
Consider a while loop for the options thing
while (!options.equalsIgnoreCase("N"))
and put that around all the stuff you want done till they hit N.
Also, get rid of if and else if at the end as they are not needed and just put
System.out.println("Exiting the program....");
after the while loop ends.
I'll post the code in a minute. Am working on the invalid type count thing right now.
Hmmmm...it seems the customer type thing could be dealt with with another while loop.
Am still working on code....
Last edited by javapenguin; March 24th, 2011 at 07:34 PM.
Here is the code, it appears to do what you want it to now:
import java.util.Scanner; public class phonebill { public static void main(String[] args) { char customertype = 't'; // R - for Regular, B - for Business String option = ""; // [Y/N] Option String phonenumber = ""; // R - for Regular, B - for Business int totalminutes; // R - for Regular, B - for Business double totalcharge=0; // R - for Regular, B - for Business double basepayment=0; // R - for Regular, B - for Business double stage1=0; // R - for Regular, B - for Business double stage2=0; // R - for Regular, B - for Business //FOR BUSINESS CUSTOMERS final double stage1BUSINESS=0.45; final double stage2BUSINESS=0.99; //FOR REGULAR CUSTOMERS final double stage1REGULAR=0.55; final double stage2REGULAR=0.88; Scanner scan = new Scanner(System.in); System.out.println("\t\t\tPHONE BILL GENERATION SOFTWARE"); System.out.println("\t\t\t=============================="); System.out.println("\n"); while (!option.equalsIgnoreCase("N")) { int invalidAttempts = 0; while (customertype != 'B' && customertype != 'b' && customertype != 'A' && customertype != 'a') { System.out.print("Please Enter the Customer Type(R for Regular,B for Business): "); customertype=scan.next().charAt(0); if (customertype !='B' && customertype !='b' && customertype!='R' && customertype!='r') { System.out.println("Invalid Customer Type. Please enter R, r for Regular and B, b for Business Customers: "); invalidAttempts++; } if (invalidAttempts >=3) { System.exit(0); } } System.out.print("Please Enter Customer Phone Number(###-###-####): "); phonenumber=scan.next(); System.out.print("Please Enter the Phone Usage in Minutes: "); totalminutes=scan.nextInt(); if (customertype =='R' || customertype =='r') { if (totalminutes>=0 || totalminutes<=200) { basepayment=29.99; totalcharge=basepayment; } else if (totalminutes>200 && totalminutes<=450) { basepayment=29.99; stage1=stage1REGULAR*(totalminutes-200); totalcharge=basepayment+stage1; } else if (totalminutes>450) { basepayment=29.99; stage1=stage1REGULAR*250; stage2=stage2REGULAR*(totalminutes-450); totalcharge=basepayment+stage1+stage2; } } if (customertype =='B' || customertype =='b') { if (totalminutes>=0 || totalminutes<=600) { basepayment=99.99; totalcharge=basepayment; } else if (totalminutes>600 && totalminutes<=700) { basepayment=99.99; stage1=stage1BUSINESS*(totalminutes-600); totalcharge=basepayment+stage1; } else if (totalminutes>700) { basepayment=99.99; stage1=stage1BUSINESS*100; stage2=stage2BUSINESS*(totalminutes-700); totalcharge=basepayment+stage1+stage2; } } System.out.println("\n"); System.out.println("\t\t\tPHONE BILL FOR: "+phonenumber); System.out.println("\t\t\t============================"); System.out.println("\n"); System.out.println("Total Minutes Used= "+totalminutes); System.out.println("Monthly Base Payment= $"+basepayment); System.out.println("Cost for Stage1 Units: $"+stage1); System.out.println("Cost for Stage2 Units: $"+stage2); System.out.println("Total Cost: $"+totalcharge); System.out.println("\n"); //[Y/N] OPTION System.out.print("More Bills? [Y/N]:"); option=scan.next(); } System.out.println("Exiting the program..."); } }
Javapenguin, 'A' and 'a' are valid?
javapenguin (March 25th, 2011)
I meant 'R' and 'r'.
I had 6 hours of sleep yesterday.
However, it will compile and, once it is changed to 'R' and 'r', should work.
I did compile and test this one.
Had a lot of things going on yesterday. Had been to a group meeting to a class, than another meeting at dinner, and went to yet another at 8:30. It was a typo. They happen sometimes.
OOO (April 1st, 2011)