Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!

Ilangovan Chandran

Greenhorn
+ Follow
since Sep 09, 2002
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ilangovan Chandran

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);

}
//================================================================================
}
//===============================
15 years ago
Local variables or automatic variables are declared in methods of a class.These variables are loaded when a objec method is called and destroyed when the method completed.
Thus it is called as automatic or local variable.
15 years ago