7 Replies - 232 Views - Last Post: 02 April 2013 - 05:12 PM Rate Topic: -----

#1 camen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-April 13

sentinel while loop not executing

Posted 02 April 2013 - 04:48 PM

import java.text.*;
import java.io.*;
import java.util.Scanner; //allows keyboard entry in code
public class Lab7
{
	public static void main(String[]args) throws Exception
	{
		String CustomerFirstName, CustomerLastName, CompanyName, MoreCust;
	   int AccountNum;
		double OldMeterRdg, NewMeterRdg, DiffOfRdgs, AmountDue;
		
		DecimalFormat num = new DecimalFormat("$,###.00"); //Changes Amount Due to Dollar Amount
		Scanner scan = new Scanner (System.in);
		CompanyName = ("PPL Electric");
		
		System.out.print ("Please Enter your First Name or stop to exit: ");
		CustomerFirstName = scan.next();
			
			while(!"stop".equals(CustomerFirstName))
			{System.out.print ("Please enter your First name: "); //Prints out to screen
			CustomerFirstName = scan.next(); //Stores keyboard input as "CustomerFirstName"
			System.out.print ("Please enter your Last name: "); //Prints out to screen
			CustomerLastName = scan.next(); //Stores keyboard input as "CustomerLastName"
		
			System.out.print ("Please enter your account number: "); //Prints out to screen
			AccountNum = scan.nextInt(); //Stores keyboard input as "AccountNum"
			System.out.print ("Please enter your old meter reading: "); //Prints out to screen
			OldMeterRdg = scan.nextDouble(); //Stores keyboard input as "OldMeterRdg"
			System.out.print ("Please enter your new meter reading: "); //Prints out to screen
			NewMeterRdg = scan.nextDouble(); //Stores keyboard input as "OldMeterRdg"
			DiffOfRdgs = NewMeterRdg - OldMeterRdg;
		
			if(DiffOfRdgs > 0 && DiffOfRdgs < 301) //If NewMeterRdg is Less than 301
				{ 
					AmountDue = 5.00; //Print this
				}				 	 
			else if(DiffOfRdgs > 300 && DiffOfRdgs < 1001) //If NewMeterRdg is Great than 301 and Less than 1000
				{
					AmountDue = (DiffOfRdgs * 0.03) + 5.00; //Print This
				}
			else
				{
					AmountDue = (DiffOfRdgs * 0.02) + 35.00; //Anything great than 1001 Prints this
				}			
			
			System.out.println ("*/*/*/" + CompanyName + "*/*/*/");
			System.out.println ("Account Number: " + AccountNum);
			System.out.println ("Customer Name: " + CustomerFirstName + " " + CustomerLastName);
			System.out.println ("Old Meter Reading: " + OldMeterRdg + " Kwh");
			System.out.println ("New Meter Reading: " + NewMeterRdg + " Kwh");
			System.out.println ("Total Kwh Used: " + DiffOfRdgs + " Kwh");
			System.out.println ("Total Amount Due: " + num.format(AmountDue)); //Prints Amount Due to Screen
			System.out.print ("Please enter your First name or stop to exit: "); //Prints out to screen
			CustomerFirstName = scan.next(); //Stores keyboard input as "CustomerFirstName"
			}	
			
	}
}


I've tried pretty much everything, but I cannot get my code to execute past the first prompt. I've tried the loop with curly braces, without curly braces, with a semicolon, without. I've never coded a sentinel loop before, but I've searched all outlets an am doing what is suggested. I apologize if the code is a bit choppy as I was constantly cutting and pasting in hastiness to try and get this thing to run! Any help would be much obliged!

Is This A Good Question/Topic? 0
  • +

Replies To: sentinel while loop not executing

#2 Flukeshot  Icon User is offline

  • A little too OCD
  • member icon

Reputation: 415
  • View blog
  • Posts: 1,030
  • Joined: 14-November 12

Re: sentinel while loop not executing

Posted 02 April 2013 - 04:52 PM

I copied your code to my IDE and ran it. Worked fine aside from asking my first name twice.
Was This Post Helpful? 0
  • +
  • -

#3 camen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-April 13

Re: sentinel while loop not executing

Posted 02 April 2013 - 04:56 PM

I use JGrasp - could it be my compiler? I tried it again, and it freezes after I input my first name.

I just tried running the code in Command Prompt and that pauses as well.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3354
  • View blog
  • Posts: 11,360
  • Joined: 12-December 12

Re: sentinel while loop not executing

Posted 02 April 2013 - 04:57 PM

It works for me..
Was This Post Helpful? 1
  • +
  • -

#5 Flukeshot  Icon User is offline

  • A little too OCD
  • member icon

Reputation: 415
  • View blog
  • Posts: 1,030
  • Joined: 14-November 12

Re: sentinel while loop not executing

Posted 02 April 2013 - 04:59 PM

The compiler will be the same across all IDEs, it will always be javac, perhaps there is something wrong with your JDK/JVM?
Was This Post Helpful? 1
  • +
  • -

#6 camen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-April 13

Re: sentinel while loop not executing

Posted 02 April 2013 - 05:06 PM

Well now I feel like a dummy :( I'm sorry for wasting your time. I'll try to download another JVM and hope that it works!! Thank you all for checking.
Was This Post Helpful? 0
  • +
  • -

#7 Flukeshot  Icon User is offline

  • A little too OCD
  • member icon

Reputation: 415
  • View blog
  • Posts: 1,030
  • Joined: 14-November 12

Re: sentinel while loop not executing

Posted 02 April 2013 - 05:08 PM

Don't worry about it, even if we can run your code, you still have a problem. We're happy to help.
Was This Post Helpful? 0
  • +
  • -

#8 LawlessBaron  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 115
  • Joined: 07-February 13

Re: sentinel while loop not executing

Posted 02 April 2013 - 05:12 PM

looks like it compiles it fine maybe the beginning of the while loop has no valid return method what i mean is it sees it as being fine and can read it just the start while loop maybe skipping it because its not seeing it as being valid and then thinks its finished if that makes sense
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1