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 5 of 5

Thread: [Y/N] Option

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Delete Post!
    Last edited by OOO; April 25th, 2011 at 03:06 PM.


  2. #2
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: [Y/N] Option

    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.

  3. #3
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: [Y/N] Option

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

  4. #4
    Member
    Join Date
    Feb 2011
    Posts
    55
    My Mood
    Tolerant
    Thanks
    1
    Thanked 16 Times in 15 Posts

    Default Re: [Y/N] Option

    Javapenguin, 'A' and 'a' are valid?

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

    javapenguin (March 25th, 2011)

  6. #5
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Red face Re: [Y/N] Option

    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.


  7. The Following User Says Thank You to javapenguin For This Useful Post:

    OOO (April 1st, 2011)

Similar Threads

  1. Conways Game of Life. Long Death option. Please help..
    By byako in forum What's Wrong With My Code?
    Replies: 8
    Last Post: March 9th, 2011, 08:49 AM
  2. Buffered Reader to J Option
    By jk_0821 in forum Collections and Generics
    Replies: 13
    Last Post: July 19th, 2010, 03:14 PM
  3. Is thread the best option?
    By 256mxr in forum Threads
    Replies: 1
    Last Post: May 22nd, 2010, 08:24 PM