Tuesday, July 28, 2009

Java programming help. This should use BufferedReader, look at the comments please?

import java.io.*;


public class asg4 {


public static void main(String [] args) {


int integer;


int sumA = 0;


int sumB = 0;


int sumC = 0;


int sumD = 0;


int sumF = 0;











//Prompt user using system.out.println and then create your buffered reader here


System.out.println( "Please enter your score");


BufferedReader br;


br = new BufferedReader( new InputStreamReader( System.in ) );


//String line = br.readline();


input = Integer.parseInt(br.readline());


//pass the buffered reader into a Integer.parseInt method here and call the readline()








if(input==-99) System.exit(1);





while(input != -99){





if(input%26gt;=90){


sumA++;


System.out.println(new Integer(input) + " A");


}


else if(input %26gt;= 70){


sumB++;


System.out.println(new Integer(input) + " B");


}


else if(input %26gt;= 50){


sumC++;


System.out.println(new Integer(input) + " C");


}


else if(input %26gt;= 35){


sumD++;


System.out.println(new Integer(input) + " D");


}


else{


sumF++;


System.out.println(new Integer(input) + " F");


}





System.out.println("Please enter your score22");





//put a prompt (IM THINKING THIS IS NOT A PRINTLINE, MAYBE A TRY CATCH?) here (dont have to re-create a buffered reader, use the one above)


input = Integer.parseInt(br.readline());


//and a integer.parseINT method here and call the readline() method off of it








}





System.out.println("The total number of A's is " + new Integer(sumA ));


System.out.println("The total number of B's is " + new Integer(sumB ));


System.out.println("The total number of C's is " + new Integer(sumC ));


System.out.println("The total number of D's is " + new Integer(sumD ));


System.out.println("The total number of F's is " + new Integer(sumF ));


}


}

Java programming help. This should use BufferedReader, look at the comments please?
not sure what you're looking for on the overall logic, but you just need to do the following and it appears to work good:


//1. br.readline should be br.readLine (couple places)


//2. surrounded everything w/ try/catch block (needed for io)





I was catching } catch (NumberFormatException e) {


// TODO Auto-generated catch block


e.printStackTrace();


} catch (IOException e) {


// TODO Auto-generated catch block


e.printStackTrace();





Good Luck.


No comments:

Post a Comment