John
Posts: 2
Nickname: won
Registered: Mar, 2002
|
|
HELP please!
|
Posted: Mar 28, 2002 11:17 AM
|
|
Advertisement
|
The program is missing some vital components to operate properly. Your task is to fill in the missing code.
// I got some of this working, but mostly not...can anyone help!?!?!?
public class DontStop{
static String STOP_WORD="stop";
static BufferedReader keyboard=new BufferedReader(new InputStreamReader(System.in));
public static void main(String arg[]) throws IOException {
System.out.println("This program calculates the average of numbers entered by the user");
System.out.println("After you have entered your last number, simply type STOP.");
doThis();
}
public static void doThis()throws IOException {
String choiceString = "a";
int choice = 0;
int count = 1;
double total=0;
double average=0;
//HERE YOU SHOULD FILL IN THE CODE FOR THE BEGINNING OF A WHILE LOOP THAT
//CONTINUES UNTIL THE USER TYPES THE STOPWORD
{
System.out.print("Please enter number "+ count+": ");
//TYPE IN THE CODE FOR READING THE INPUT FROM THE KEYBOARD
if(choiceString.equalsIgnoreCase(STOP_WORD))
{
count--;
System.out .println("You entered "+count+" numbers with an average of "+total/count);
System.exit(0);
}
//TYPE IN THE CODE TO GET THE NUMBERS and INCREASE THE COUNTER (2 lines of code)
}
}//close doThis
public static double getNumber(String n)throws IOException{
double number=0;
try{
//CODE TO PARSE THE NUMBER
}
catch(NumberFormatException e){
System.out.println("Wanted a number, starting over");
doThis();
}
//CODE TO RETURN THE NUMBER TO doThis();
}//close getNumber
}//close DontStop
|
|