Written for Java Write the program that allows users to enter the file name to s
ID: 3714215 • Letter: W
Question
Written for Java
Write the program that allows users to enter the file name to store the information of students then provides the menu to allow users to select the following tasks and only terminate the program when users select exit Each task has to be handle in a user-defined function 1. 2. 3. 0. GRADING STUDENTS Enter Information of Students in class Enter the scores of Students Grading Exit TASK 1: ENTER INFORMATION OF STUDENTS IN CLASS -Open the file with the above file name as output file Read information of one student that includes: student id, last name, first name, phone then create the object of class Student to have all information that need for one student. One student should hold the following information: Id, last name, first name, phone, list of quizzes scores, list of homework scores, list of labs scores, list of test scores, project score, discusssion score, team work score, extra credit scores, total score, percentage and letter grade. Store the information of this student by writing one line to the above output file with following format id,lastname,firstname,phone-list of quizzes scores-list of homeworks scores-list of labs scores-list of tests scores- project score-discussion score-team work score-extra credit score-total score-percentage-letter grade For example 1234567,Smith,James,4691234567-0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0-0.0,0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,0.0, 0.0-0.0, 0.0, 0.0,0.0, 0.0, 0.0, 0.0-0.0, 0.0, 0.0-0.0-0.0-0.0-0.0-0.0-X Where Quizzes scores: first 14 numbers 0.0 Homework scores: second 10 numbers 0.0 Lab scores: third 7 numbers 0.0 Test scores: fourth 3 numbers 0.0 Project: 0.0 Discussion: 0.0 Team work: 0.0 Extra credit: 0.0 Total score: 0.0 Percentage: 0.0 Letter grade: X The program should allow users to continue to enter the information of other students until they want to stopExplanation / Answer
Kindly see the following java files. Student class will have the details of all the students and the StudentGrade class will ask for the options from the user to store the data.
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class StudentGrades {
public static void main(String[] args) throws Exception {
System.out.println("Enter the filename : ");
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String filename = reader.readLine();
boolean exit = false;
while(!exit){
System.out.println("------------------------------");
System.out.println("Select the option");
System.out.println("1. Enter the Information of Students in Class");
System.out.println("2. Enter the Scores of Students");
System.out.println("3. Grading");
System.out.println("0. Exit");
System.out.println("------------------------------");
Scanner optionsreader = new Scanner(System.in);
System.out.println("Enter a number: ");
int n = optionsreader.nextInt();
Student s = new Student();
if(n==0){
exit = true;
}else if(n==1){
recordStudentDetails(filename,reader,s);
}else if(n==2){
recordStudentScores(filename, s, reader);
}else if(n==3){
grade(filename);
}
}
}
private static void grade(String filename) throws Exception {
String delim = ("\t|,|;|\.|\?|!|-");
BufferedReader br = new BufferedReader(new FileReader(new File(filename)));
String line = null;
while((line=br.readLine())!=null){
String[] arr = line.split(delim);
Student t = new Student();
t.setId(arr[0]);
t.setLname(arr[1]);
t.setFname(arr[2]);
t.setPhoneno(arr[3]);
t.setListofquizscores(arr[4]);
t.setListofhwscores(arr[5]);
t.setListoflabscores(arr[6]);
t.setListoftestscores(arr[7]);
t.setListofprojectscores(arr[8]);
t.setListofdiscussionscores(arr[9]);
t.setListofteamworkscores(arr[10]);
t.setListofextracreditscores(arr[11]);
t.setListoftotalscores(arr[12]);
t.setPercentage(arr[13]);
t.setLettergrade(arr[14]);
System.out.println(t.id+".) "+t.fname+"==>"+t.lettergrade);
String fname = "temp"+new File(filename).getName();
BufferedWriter bw = new BufferedWriter(new FileWriter(fname));
bw.write(t.toString()+" ");
bw.close();
}
}
private static void recordStudentDetails(String filename, BufferedReader reader, Student s) throws Exception {
System.out.println("Enter id");
s.setId(reader.readLine());
System.out.println("Enter lname");
s.setLname(reader.readLine());
System.out.println("Enter fname");
s.setFname(reader.readLine());
System.out.println("Enter phoneno");
s.setPhoneno(reader.readLine());
recordStudentScores(filename,s,reader);
}
private static void recordStudentScores(String filename, Student s, BufferedReader reader) throws Exception {
System.out.println("Enter listofquizscores");
s.setListofquizscores(reader.readLine());
System.out.println("Enter listofhwscores");
s.setListofhwscores(reader.readLine());
System.out.println("Enter listoflabscores");
s.setListoflabscores(reader.readLine());
System.out.println("Enter listoftestscores");
s.setListoftestscores(reader.readLine());
System.out.println("Enter listofprojectscores");
s.setListofprojectscores(reader.readLine());
System.out.println("Enter listofdiscussionscores");
s.setListofdiscussionscores(reader.readLine());
System.out.println("Enter listofteamworkscores");
s.setListofteamworkscores(reader.readLine());
System.out.println("Enter listofextracreditscores");
s.setListofextracreditscores(reader.readLine());
System.out.println("Enter listoftotalscores");
s.setListoftotalscores(reader.readLine());
System.out.println("Enter percentage");
s.setPercentage(reader.readLine());
System.out.println("Enter lettergrade");
s.setLettergrade(reader.readLine());
BufferedWriter bw = new BufferedWriter(new FileWriter(new File(filename)));
bw.write(s.toString()+" ");
bw.close();
}
}
public class Student {
String id;
String lname;
String fname;
String phoneno;
String listofquizscores;
String listofhwscores;
String listoflabscores;
String listoftestscores;
String listofprojectscores;
String listofdiscussionscores;
String listofteamworkscores;
String listofextracreditscores;
String listoftotalscores;
String percentage;
String lettergrade;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getLname() {
return lname;
}
public void setLname(String lname) {
this.lname = lname;
}
public String getFname() {
return fname;
}
public void setFname(String fname) {
this.fname = fname;
}
public String getPhoneno() {
return phoneno;
}
public void setPhoneno(String phoneno) {
this.phoneno = phoneno;
}
public String getListofquizscores() {
return listofquizscores;
}
public void setListofquizscores(String listofquizscores) {
this.listofquizscores = listofquizscores;
}
public String getListofhwscores() {
return listofhwscores;
}
public void setListofhwscores(String listofhwscores) {
this.listofhwscores = listofhwscores;
}
public String getListoflabscores() {
return listoflabscores;
}
public void setListoflabscores(String listoflabscores) {
this.listoflabscores = listoflabscores;
}
public String getListoftestscores() {
return listoftestscores;
}
public void setListoftestscores(String listoftestscores) {
this.listoftestscores = listoftestscores;
}
public String getListofprojectscores() {
return listofprojectscores;
}
public void setListofprojectscores(String listofprojectscores) {
this.listofprojectscores = listofprojectscores;
}
public String getListofdiscussionscores() {
return listofdiscussionscores;
}
public void setListofdiscussionscores(String listofdiscussionscores) {
this.listofdiscussionscores = listofdiscussionscores;
}
public String getListofteamworkscores() {
return listofteamworkscores;
}
public void setListofteamworkscores(String listofteamworkscores) {
this.listofteamworkscores = listofteamworkscores;
}
public String getListofextracreditscores() {
return listofextracreditscores;
}
public void setListofextracreditscores(String listofextracreditscores) {
this.listofextracreditscores = listofextracreditscores;
}
public String getListoftotalscores() {
return listoftotalscores;
}
public void setListoftotalscores(String listoftotalscores) {
this.listoftotalscores = listoftotalscores;
}
public String getPercentage() {
return percentage;
}
public void setPercentage(String percentage) {
this.percentage = percentage;
}
public String getLettergrade() {
return lettergrade;
}
public void setLettergrade(String lettergrade) {
this.lettergrade = lettergrade;
}
@Override
public String toString() {
return id +","+ lname +","+ fname +","+ phoneno +"-"+
listofquizscores+"-"+ listofhwscores + "-"+ listoflabscores + "-" +
listoftestscores + "-"+ listofprojectscores + "-" + listofdiscussionscores
+ "-"+ listofteamworkscores + "-" + listofextracreditscores + "-"
+ listoftotalscores + "-" + percentage + "-" + lettergrade;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.