Written in java Write an application that creates a simple Grade class and then
ID: 3727600 • Letter: W
Question
Written in java
Write an application that creates a simple Grade class and then writes Grade Object data to a RandomAccessFile object.
Grade Class
Instance variables: studentID:byte (8 bit integer), grade:double
Constructors - two constructor: one default and one constructor with new student ID and new grade as parameters.
Accessor and mutator methods Use Eclipse's functionality to create these method quickly.
toString() - "Student 4's grade is 88.0"
RandomAccessDemo Class
Creates at least 8 Grade objects and write them to a RandomAccessFile, no need to store the objects after they are written to the file. Hint use a loop to create and store the objects. Make sure a record size is determined for each grade.
Develop user interface that:
Locates a grade record based on placement in the file, for example the user might want to see the 5th grade, or the 3rd grade.
Prints a statement identifying the grade and its location such as "The fourth grade is for 85.4 and belongs to student 25".
Ask the user if they wish to look up another grade or quit.
The program must catch and successfully handle (continue with out exiting)
NumberFormatException or InputMismatchException depending how you handle collection of the user input.
Any required checked exception.
Explanation / Answer
import java.util.Scanner;
public class JavaExample
{
public static void main(String args[])
{
/* This program assumes that the student has 6 subjects,
* thats why I have created the array of size 6. You can
* change this as per the requirement.
*/
int marks[] = new int[6];
int i;
float total=0, avg;
Scanner scanner = new Scanner(System.in);
for(i=0; i<6; i++) {
System.out.print("Enter Marks of Subject"+(i+1)+":");
marks[i] = scanner.nextInt();
total = total + marks[i];
}
scanner.close();
//Calculating average here
avg = total/6;
System.out.print("The student Grade is: ");
if(avg>=80)
{
System.out.print("1st");
}
else if(avg>=60 && avg<80)
{
System.out.print("2nd");
}
else if(avg>=40 && avg<60)
{
System.out.print("3rd");
}
else
{
System.out.print("4th");
}
}
}
Output:
Enter Marks of Subject1:40
Enter Marks of Subject2:80
Enter Marks of Subject3:80
Enter Marks of Subject4:40
Enter Marks of Subject5:60
Enter Marks of Subject6:60
The student Grade is: 2nd
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.