8 Replies - 385 Views - Last Post: 24 March 2012 - 01:39 PM Rate Topic: -----

#1 sukhil88  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 24-March 12

Sentinel Method Question

Posted 24 March 2012 - 11:34 AM

Hello Team,

My code works completely right, but My instructor looking for Sentinel Method looping with while. I dot't understand the difference between my code and the code(sentinel method) my instructor looking for.

*Edited: topic title renamed to be more meaningful
Please use descriptive topic title

This post has been edited by pbl: 24 March 2012 - 12:45 PM

Is This A Good Question/Topic? 0
  • +

Replies To: Sentinel Method Question

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2197
  • View blog
  • Posts: 5,224
  • Joined: 10-September 10

Re: Sentinel Method Question

Posted 24 March 2012 - 11:37 AM

Neither do we understand the difference, because we can't see your code.

And please write better thread titles. Everyone has a question. Usually they are questions about Java, and sometimes there are noobs asking questions about Java. All of those descriptors don't help someone identify what the post is about.
Was This Post Helpful? 0
  • +
  • -

#3 sukhil88  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 24-March 12

Re: Sentinel Method Question

Posted 24 March 2012 - 11:40 AM

View PostGregBrannon, on 24 March 2012 - 11:37 AM, said:

Neither do we understand the difference, because we can't see your code.

And please write better thread titles. Everyone has a question. Usually they are questions about Java, and sometimes there are noobs asking questions about Java. All of those descriptors don't help someone identify what the post is about.


here is my code
import java.text.*;//DecimalFormat
import javax.swing.*; //JOptionPane

public class Lab7_w
{
	public static void main(String[] args)
	 {
	  String accountNumber; // account nubmer
	  String name; //customer name
	  String inOld; //inputting old meter reading
	  String inNew; //inputting new meter reading
	  String output; //outputting data
	  double TEB; //total electic bill
	  double UKWH; //used Kwh
	  double NR;   //new meter reading
	  double OR;   //old meter reading
	  int repeat=0; //for reapting customer entry again and again
	  String cName1, AC, newAC; // New customer entry as Name
		
	  
	while (repeat==JOptionPane.YES_OPTION)
	{
		AC = JOptionPane.showInputDialog("Enter New Account # : ");//New customer Account
		cName1 = JOptionPane.showInputDialog("New Customer Name: ");// New customer Entry
		newAC = "New Customer added to the billing system." + "\n A/c # : " + AC + "\n Name: " + 

cName1;//New Customer info output
		JOptionPane.showMessageDialog(null, newAC, "New Customer INFO", JOptionPane.INFORMATION_MESSAGE); 

//confirmation of New customer entry
			
		
 	 DecimalFormat num = new DecimalFormat("$,###.00");  //creates format for named num

	 accountNumber = JOptionPane.showInputDialog("Enter the account number:");
	 name = JOptionPane.showInputDialog("Enter customer name:");
	 inOld = JOptionPane.showInputDialog("Enter Old meter reading:");
	 inNew = JOptionPane.showInputDialog("Enter new meter reading:");
	 NR = Double.parseDouble(inNew);//convert inNew string to numeric value 
	 OR = Double.parseDouble(inOld);//coverrt inOld string to numeric value
 
	
  	
         
         UKWH = NR-OR;
	if(UKWH >= 0 && UKWH <= 300)
	    TEB = 5;
	 else
	     if(UKWH >= 301 && UKWH <= 1000)
	       TEB = 5 + ((UKWH - 300)*0.3);
             else 
	       TEB = 35 + ((UKWH - 1000)*0.2); 	
	  


	output =  "Account #: "+ accountNumber + "\nCustomer Name: " + name + "\nOld meter reading: " + OR + "\nNew 

meter reading: " + NR + "\nElectricity used: " + UKWH + " kwh"+ "\nTotal amount due: " + num.format(TEB);
	JOptionPane.showMessageDialog(null, output, "PECO Electric Bill", JOptionPane.INFORMATION_MESSAGE);

       repeat= JOptionPane.showConfirmDialog(null, "More Customers?");// option for add more customers to system
	
	}

System.exit(0);	
	}


}



*Edited: Please :code:
Or select your code and click the CODE icon on the task bar

This post has been edited by pbl: 24 March 2012 - 12:48 PM

Was This Post Helpful? 0
  • +
  • -

#4 Crockeo  Icon User is offline

  • D.I.C Head

Reputation: 44
  • View blog
  • Posts: 247
  • Joined: 21-June 11

Re: Sentinel Method Question

Posted 24 March 2012 - 11:42 AM

(Try surrounding it in [code] tags)
Was This Post Helpful? 0
  • +
  • -

#5 Cavemanpi  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 5
  • Joined: 20-April 09

Re: Sentinel Method Question

Posted 24 March 2012 - 12:06 PM

If I were in your position, I would ask your professor if they are expecting the sentinel variable to be accountNumber. If so the control value could be something like (accountNumber <= 0 ).
Was This Post Helpful? 0
  • +
  • -

#6 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 822
  • View blog
  • Posts: 2,529
  • Joined: 29-July 11

Re: Sentinel Method Question

Posted 24 March 2012 - 01:07 PM

It looks like he wants something like:

while(moreCustomers)
   //add customer account to database...



More customers could easily be a boolean that you toggle with your yes/no JOPtionPane.
Was This Post Helpful? 0
  • +
  • -

#7 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Sentinel Method Question

Posted 24 March 2012 - 01:14 PM

farrell2k this is already what the OP does

 while (repeat==JOptionPane.YES_OPTION)


Was This Post Helpful? 0
  • +
  • -

#8 Cavemanpi  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 5
  • Joined: 20-April 09

Re: Sentinel Method Question

Posted 24 March 2012 - 01:35 PM

When I think of a sentinel variable, I usually think of it as a variable that will hold either valid data or a defined value indicating that it is the end of the data. That is the thought behind using accountNumber as the sentinel variable.

While what OP does is a way to loop until all the data is captured, it may not fit the paradigm of using sentinel variables.
Was This Post Helpful? 0
  • +
  • -

#9 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Sentinel Method Question

Posted 24 March 2012 - 01:39 PM

Fully agreed.
So to implement the "sentinel concept" you should switch from:

while user say he wants to add an other entry {
   enter account
   enter name
   ...
}


to
while(true) {
   enter account
      if account == 000000
         break;
   enter name
   ...
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1