| Author |
code help
|
sare bear
Greenhorn
Joined: Sep 08, 2002
Posts: 2
|
|
i have just started out and am having trouble getting my program to work, i am having a problem calling a method from the extractAllNumbers, method and with my return in my calculateFinalMark method. Any help would be apreciated. } }
|
 |
Anirban dutta
Ranch Hand
Joined: Aug 08, 2002
Posts: 89
|
|
|
Please specify your problem exactly.
|
 |
Ilangovan Chandran
Greenhorn
Joined: Sep 09, 2002
Posts: 2
|
|
pl.find the working code of urs. //=========================== import java.io.*; public class StudentMark { public static double reduction=0.05; //================================================================================ public static int calculateFinalMark(int inAssignMark, int inDaysLate) //This methos checks dayslate.Where the assignment was late the new mark is calculated { double mark; //5% deduction per day late mark =0.0; if (inDaysLate>0) mark=inAssignMark-(inAssignMark*reduction*inDaysLate); else if (inDaysLate<=0) mark=inAssignMark-0; return (int)Math.round(mark); //This states that it needs to be an integer and not a double } //================================================================================ public static int extractAllNumbers(String inNumber) throws IOException //this method converts the string to an integer { int value; try{ value=Integer.parseInt(inNumber); } catch(NumberFormatException e) { System.out.println("Please Enter a valid number "); BufferedReader reader = new BufferedReader (new InputStreamReader (System.in)); value=Integer.parseInt(reader.readLine()); } return value; //return adjusted mark } //================================================================================ public static void main (String[] args) throws IOException { int total, numstudents,inAssignMark,inDaysLate,inNumber; double average,mark, adjustment; String name; total=0; numstudents=0; BufferedReader reader = new BufferedReader (new InputStreamReader (System.in)); System.out.println("Please enter students given name and family name or x to quit"); name=reader.readLine(); while (!name.equals("x")) { System.out.println("Please enter student mark:"); //inAssignMark=Integer.parseInt(inNumber); //this method is ment to be called from extractAllNumbers inAssignMark =extractAllNumbers(reader.readLine()); System.out.println("Please enter days late:"); inDaysLate =extractAllNumbers(reader.readLine()); // inDaysLate =Integer.parseInt(inNumber); mark=calculateFinalMark(inAssignMark,inDaysLate); adjustment = reduction - inDaysLate*100; System.out.println(name+"mark:"+mark+"(adjusted by"+adjustment+"%)"); numstudents++; total+=mark; System.out.println("Please enter students given name and family name or x to quit"); name=reader.readLine(); } System.out.println("Total number of students:"+numstudents); average=(double)total/numstudents; average=Math.round((double)total/numstudents); System.out.println("Average mark is:"+average); } //================================================================================ } //===============================
|
 |
sare bear
Greenhorn
Joined: Sep 08, 2002
Posts: 2
|
|
|
thankyou for your help that has fixed it
|
 |
 |
|
|
subject: code help
|
|
|