I'm trying long distance learning & I'm having many issues. I was able to write a program that runs well using an IF loop. but now I am to use that same exact program with a WHILE loop & I just can't understand any explanation I receive from the instructor. I asked "The directions say to use "sentinel method". I went through Ch.05-07 and cannot find this term. I also looked in the index & key terms for these chapters. Please direct me to where I can find an explanation of this method.
-Response: It's in the repetition powerpoint attached to the 1st repetition lab (6).
So I again asked "I see it on the ppt but that doesn't define what it is or what it does. Please explain WHAT it is or what it does."
-Response:Ok, sentinel method (or trailer method) is when instead of asking the user if they want to keep going, the user enters a certain value for an input that is being processed anyway. So for the example, the user enters a radius, then the computer tests to see if it's the sentinel value, if not, it processes it".

Any guidance would be GREATLY appreciated. Below is my code that works well with the IF Loop, but I totally don't understand the concept/difference between If & WHILE, especially with the term SENTINEL thrown in.

import javax.swing.*;
import java.text.*;// enables DecimalFormat.
public class Electric61
{
public static void main (String args[])
{
double newUsage, amtDue, over1, over2; //Over1 is for KWH >300 but <1001 and Over2
// is for KWH>1000
int again;
String oldMtrStr, newUsageStr, cnameStr, newMtrStr;
do
{
cnameStr = JOptionPane.showInputDialog(null, "Enter Customer Name");
//bnameStr = JOptionPane.showInputDialog(null, "Enter Business Name"); if & when
//applicable this can be activated


String oldMtrString = JOptionPane.showInputDialog(null, "Enter Old Meter Reading");
String newMtrString = JOptionPane.showInputDialog(null, "Enter New Meter Reading");
String acctString = JOptionPane.showInputDialog(null, "Enter Account Number");
Double oldMtr = Double.valueOf(oldMtrString);// Old Meter Reading
Double newMtr = Double.valueOf(newMtrString);// New Meter Reading
Double acct = Double.valueOf(acctString); //Account Number
newUsage = (newMtr - oldMtr); // This calculates NEW Usage by subtracting your old
//meter reading from your new reading
DecimalFormat Due = new DecimalFormat("$,###.00"); //This formats Amount Due
//to 2 decimal places
// Here is where the calculations begin AND it now needs to be changed from IF/Else to
//  WHILE/FOR & I don't even know how to begin the change
if(newUsage < 301)                           // If new meter reading less old meter reading > 301
// you're charged a flat rate of $5.00
{amtDue=5.00;}
else
if(newUsage < 1001)        // If you used more than 300 & less than 1000, 300 is
//subtracted from the New reading
{over1 = newUsage - 300;             // The difference is taken and...
amtDue=(over1 * .03) + 5.00;}  //then multiplied by 3 cents. This figure is added to
//the 5.00 for the total due
else                 //If you used over 1000 Kwh            {over2 = newUsage - 1000;          // The difference is taken and it's
amtDue = (over2 * 0.02) + 35.00;} //then multiplied by 2 cents. $35.00 then
//added for your total due
JOptionPane.showMessageDialog(null,"Company Name (if applicable)" + //This confirms the
// Company Name if applicable
//This can replace the previous line if we decide to enter business names: (null,"Company
// Name " + bnameStr+
"\nYour Account number is " + acctString +  // This confirms your Previous Acct # Input
"\nCustomer Name is " + cnameStr +      //This confirms your Name
"\nNew Meter Reading is " + newMtrString +  //This confirms your NEW METER Reading
"\nOld Meter Reading was" + oldMtrString +  //This confirms your Old Meter Reading
"\nKwh Used is: " + newUsage +      //This shows your Billable Usage of Kwhs
"\nThe TOTAL Amount Due is " + Due.format(amtDue));// This shows how much is due


again = JOptionPane.showConfirmDialog(null,"Another Customer to Enter? ");
}
while(again == JOptionPane.YES_OPTION);  //displays the dialog box to put YES/NO


System.exit(0);
}
}

I was able to find some documentation on this. However I am still fighting with 2 errors at lines 51 & 52. This began in Ch.05, modified to an IF loop in Ch.06 & now I must modify to a WHILE loop.
If anyone can direct me to the resolution it'll be much appreciated.
Thanks

I was able to find some documentation on this. However I am still fighting with 2 errors at lines 51 & 52. This began in Ch.05, modified to an IF loop in Ch.06 & now I must modify to a WHILE loop.
If anyone can direct me to the resolution it'll be much appreciated.
Thanks

Your ending braces are incorrect. Use an IDE, and double check your braces for your loops.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.