The Artima Developer Community
Sponsored Link

Java Answers Forum
HELP please!

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
John

Posts: 2
Nickname: won
Registered: Mar, 2002

HELP please! Posted: Mar 28, 2002 11:17 AM
Reply to this message Reply
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

Topic: Javascript to Servlet Previous Topic   Next Topic Topic: Data Bound Beans

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use