Delete Post!
Printable View
Delete Post!
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....
Here is the code, it appears to do what you want it to now:
Code java: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?
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.
:o:o:o:o