I need to loop this program help please.......

HI i'm trying to loop this specific program with a yes/no question at the end of the program like:

" do you want to continue with the program yes/no "

please, really i will appreciate a lot your help

import cs1.Keyboard;

public class Salary

{

public static void main (String[] args)

{

double currentSalary;

double rating;

double raise;

System.out.print ("Enter the current salary: ");

currentSalary = Keyboard.readDouble();

System.out.print ("Enter the performance rating: ");

rating = Keyboard.readDouble();

if (rating==1);

raise = (currentSalary*0.06);

if (rating==2);

raise = (currentSalary*0.04);

if (rating==3);

raise = (currentSalary * 0.015);

System.out.println ("Amount of your raise: $" + raise);

System.out.println ("Your new salary: $" + (currentSalary + raise));

}

}

[935 byte] By [J-Da] at [2007-10-3 3:08:37]
# 1

If you really want help, you will stop making new topics for the same question (that was answered), use code tags to post your source (there's a button "code"...) and try some things yourself. Now...

As a first step, you should put the functionality of your program (what you have in main) in a separate method, call it runOnce() of whatever you want.

Then, inside your main, you call this method in a do-while loop where you use another keyboard query to determine when to break out of it (you should also make a separate method for that). As a first step, Your program should look like this:

import cs1.Keyboard;

public class Salary {

public static void main (String[] args) {

do {

runOnce();

} while ( shouldContinue() );

}

private static void runOnce() {

double currentSalary;

//... (what you have in main)

//...

System.out.println ("Your new salary: $" + (currentSalary + raise));

}

private static boolean shouldContinue() {

//query the user like you ask for the current salary etc;

//you will want to read a char; your KeyBoard class probably has a method for that, so

//assuming you ask for 'y' or 'n'

if (userChoiceChar == 'y') {

return true;

} else {

return false;

}

}

}

Try this. If you run into a problem, post back with the exact code (in tags) and exact and full error message and someone will help you on.

Lokoa at 2007-7-14 20:59:08 > top of Java-index,Java Essentials,Java Programming...