Question
Java program
Program: Grade Stats In this program you will create a utility to calculate and display various statistics about the grades of a class. In particular, you will read a CSV file (comma separated value) that stores the grades for a class, and then print out various statistics, either for the whole class, individual assignments, or individual students Things you will learn Robustly parsing simple text files Defining your own objects and using them in a program Handling multiple input commands Specification When your program starts, it should print the program title and your name, then load the file given as a command line argument similar to the sorting assignment). If no file is given, or if file does not the exist, the program should print a usage message and exit. After loading the input file, the program should go into command mode, which allows the user to type in various commands and get results from the system. This is similar to the calculator assignment. You should show some kind of a prompt, such as to the user, and wait for commands. The commands that your system must process are as follows: 1. exit Causes the program to exit. 2. help Causes the program to print a list of commands accepted by the system. This same message should be printed if the user types an unrecognized command. The program must not crash in this case. 3. roll Prints out a list of students from the class (first and last name along with total points, and final grades (A, B, C, D, F) for each student. These should be properly aligned in columns, so that the grades line up above one another, and the student first name and student last name are left aligned. 4. search [partial name]
media%2Fe40%2Fe40b38bd-57c2-41af-8994-18
media%2F369%2F3694af77-8a83-4d88-9bb0-49
media%2F08b%2F08b1bc57-3c1f-4f27-9937-43
media%2F0aa%2F0aaf23a9-ccb3-4d45-ae8a-5e
media%2F9ca%2F9cac4b8d-49e4-484a-a1a4-2f
0 0
Add a comment Improve this question Transcribed image text
Answer #1

I HAVE DONE THIS JOB IN ECLIPSE, HERE IS THE CODE:

//ProgramSeven.java


import java.util.*;
import java.io.*;

public class ProgramSeven
{
public static List<student> students = new ArrayList<student>();
public static HashMap<String, Double> assignments = new HashMap<String, Double>();
public static Scanner keyboard = new Scanner(System.in);

public static String course = "", section = "";
public static double total;

public static void main(String[] args) throws IOException
{
System.out.println("--------------------------------"+"\n"+
"| Grade Stats, by Tanner Heape |"+"\n"+
"--------------------------------");
// User input
String file = "";

// Checks for initial input
if (args.length > 0)
{
file = args[0];
}

// Varifies file
while(true)
{
File fileI = new File("./"+file);
if(fileI.exists() && fileI.isFile())
{
toList(fileI);
break;
}
System.out.print("Enter the file name: ");
file = keyboard.nextLine();
}

while(true)
{
System.out.print("\n> ");

// splits user input into readable sections (ArrayList)
List<String> input = new ArrayList<String>(Arrays.asList(keyboard.nextLine().split(" ")));

if(input.get(0).equalsIgnoreCase("exit")) // runs quit
{
System.exit(0);
}
else if(input.get(0).equalsIgnoreCase("help")) // runs help
{
System.out.println(" Accepted commands:\n" +
" exit\n" +
" help\n" +
" students\n" +
" search [partial name]\n" +
" assignments\n" +
" report\n" +
" student [student name]\n" +
" assignment [assignment name]");
}
else if(input.get(0).equalsIgnoreCase("students")) // runs students
{
System.out.println(" Student Grades for " + course + ", " + section + "\n" +
" Total points possible: " + total + "\n");

System.out.printf(" %-10s %-10s %6s %5s%n ---------- --------- ------ -----%n", "First Name", "Last Name", "Points", "Grade");

for(student st : students)
{
System.out.printf(" %-10s %-10s %6.0f %s%n", st.getFirstName(), st.getLastName(), st.getPoints(), st.getLetterGrade());
}
}
else if(input.get(0).equalsIgnoreCase("search")) // runs search [input]
{
if(input.size() > 1)
{
String subString = input.get(1);

System.out.printf(" %-10s %-10s %6s %5s%n ---------- --------- ------ -----%n", "First Name", "Last Name", "Points", "Grade");

for(student st : students)
{
if(st.getFirstName().toLowerCase().contains(subString.toLowerCase()) || st.getLastName().toLowerCase().contains(subString.toLowerCase()))
{
System.out.printf(" %-10s %-10s %6.0f %s%n", st.getFirstName(), st.getLastName(), st.getPoints(), st.getLetterGrade());
}
}
}
else
{
System.out.println(" Invalid input");
}
}
else if(input.get(0).equalsIgnoreCase("assignments")) // runs assignments
{
System.out.println(" Assignments for " + course + ", " + section + "\n");

System.out.printf(" %-12s %6s%n %-12s %6s%n", "Assignment", "Points", "----------", "------");
for(String key : assignments.keySet())
{
System.out.printf(" %-12s %6.0f%n", key, assignments.get(key));
}
}
else if(input.get(0).equalsIgnoreCase("student")) // runs student [first] [last]
{
if(input.size() > 2)
{
String first = input.get(1);
String last = input.get(2);

for(student st : students)
{
if(st.getFirstName().equalsIgnoreCase(first) && st.getLastName().equalsIgnoreCase(last))
{
System.out.println(" Grades for " + st.getFirstName() + " " + st.getLastName() + "\n");
System.out.printf(" %-12s %6s %8s%n %-12s %6s %8s%n", "Assignment", "Points", "Possible", "----------", "------", "--------");

for(String key : assignments.keySet())
{
System.out.printf(" %-12s %6.0f %8.0f%n", key, st.getAssignment(key), assignments.get(key));
}
System.out.printf(" %-12s %6.0f %8.0f%n%n", "total", st.getNumberGrade(), total);
System.out.println(" Final Grade: " + st.getLetterGrade());
}
}
}
else
{
System.out.println(" Invalid input");
}
}
else if(input.get(0).equalsIgnoreCase("assignment")) // runs assignment [assignment name]
{
if(input.size() > 1)
{
String search = "";
for(int i = 1; i < input.size(); i++)
{
if(i == input.size()-1)
{
search += input.get(i);
}
else
{
search += input.get(i) + " ";
}
}

if(assignments.containsKey(search))
{
System.out.println(" " + search + ": " + assignments.get(search) + " points\n grade breakdown");

int a = 0, b = 0, c = 0, d = 0, f = 0;
double points = assignments.get(search);
for(student st : students)
{
if(st.getAssignment(search)/points >= 0.90)
{
a++;
}
else if(st.getAssignment(search)/points >= 0.80)
{
b++;
}
else if(st.getAssignment(search)/points >= 0.70)
{
c++;
}
else if(st.getAssignment(search)/points >= 0.60)
{
d++;
}
else if(st.getAssignment(search)/points < 0.60)
{
f++;
}
}
System.out.println("\n A: " + a);
System.out.println(" B: " + b);
System.out.println(" C: " + c);
System.out.println(" D: " + d);
System.out.println(" F: " + f);

}
else
{
System.out.println(" Invalid input");
}
}
else
{
System.out.println(" Invalid input");
}
}
else if(input.get(0).equalsIgnoreCase("report")) // runs report
{
System.out.println(" Grade breakdown for " + course + ", " + section);

int a = 0, b = 0, c = 0, d = 0, f = 0;
double high = 0, low = 100, average = 0, i = 0;
for(student st : students)
{
if(st.getLetterGrade().equals("A"))
{
a++;
}
else if(st.getLetterGrade().equals("B"))
{
b++;
}
else if(st.getLetterGrade().equals("C"))
{
c++;
}
else if(st.getLetterGrade().equals("D"))
{
d++;
}
else if(st.getLetterGrade().equals("F"))
{
f++;
}

if(st.getNumberGrade() > high)
{
high = st.getNumberGrade();
}
if(st.getNumberGrade() < low)
{
low = st.getNumberGrade();
}
average += st.getNumberGrade();
i++;
}
average /= i;

System.out.println("\n Low: " + low + "%\n High: " + high + "%\n Avg: " + average + "%\n");
System.out.println(" A: " + a);
System.out.println(" B: " + b);
System.out.println(" C: " + c);
System.out.println(" D: " + d);
System.out.println(" F: " + f);
}
}
}

// converts .txt file to values
public static void toList(File fileI) throws IOException
{
// Scanner for reading the file
Scanner textI = new Scanner(fileI);
boolean setup = true;
String[] titles = new String[10];

// Loop to read each textI line
while(textI.hasNext())
{
String[] ln = textI.nextLine().split(",");

if(setup)
{
String[] ln2 = textI.nextLine().split(",");

course = ln[0];
section = ln[1];

for(int i = 2; i < ln2.length; i++)
{
titles[i] = ln[i];
assignments.put(titles[i], Double.parseDouble(ln2[i]));
}

for(String key : assignments.keySet())
{
total += assignments.get(key);
}

setup = false;
}
else
{
HashMap<String, Double> temp = new HashMap<String, Double>();

for(int i = 2; i <= ln.length - 1; i++)
{
temp.put(titles[i], Double.parseDouble(ln[i]));
}

students.add(new student(ln[0], ln[1], temp, total));
}
}
}
}

//student.java

import java.util.*;

// class for object student
public class student
{
// student's variables
private String firstName, lastName, letterGrade;
private double numberGrade, points;
private HashMap<String, Double> assignments = new HashMap<String, Double>();
  
// constructor
public student(String firstName, String lastName, HashMap<String, Double> assignments, double total)
{
this.firstName = firstName;
this.lastName = lastName;
  
this.assignments = assignments;

for(String key : this.assignments.keySet())
{
this.points += this.assignments.get(key);
}

this.numberGrade = 100*(this.points/total);

if(numberGrade >= 90.0)
{
this.letterGrade = "A";
}
else if(numberGrade >= 80.0)
{
this.letterGrade = "B";
}
else if(numberGrade >= 70.0)
{
this.letterGrade = "C";
}
else if(numberGrade >= 60)
{
this.letterGrade = "D";
}
else
{
this.letterGrade = "F";
}
}
  
// getter/setter for firstName
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
public String getFirstName()
{
return this.firstName;
}

// getter/setter for lastName
public void setLastName(String lastName)
{
this.lastName = lastName;
}
public String getLastName()
{
return this.lastName;
}

// getter/setter for assignments
public void setAssignment(String assignment, double score)
{
assignments.put(assignment, score);
}
public Double getAssignment(String assignment)
{
return this.assignments.get(assignment);
}

// getter for numberGrade
public double getNumberGrade()
{
return this.numberGrade;
}

// getter for letterGrade
public String getLetterGrade()
{
return this.letterGrade;
}

public double getPoints()
{
return this.points;
}
}

//Philosophy.txt
Philosophy 101,Section 1,red essay,test 1,green leaf,test 2,presentation
firstName,lastName,5,20,5,20,50
Aristotle,Ofathens,4,18,3,15,40
Euclid,Elements,3,15,2,10,35
Immanuel,Kant,4,18,4,20,48
Ben,Franklin,5,20,4,19,49
Khalil,Gibran,4,18,3,18,47
Noam,Chomsky,5,19,1,18,49
Garrison,Keeler,3,18,4,16,41
Amy,Schumer,2,11,3,14,39
Hamurabi,Lawgiver,5,19,4,20,50
Fred,Flintstone,2,15,3,14,42

output:

M ProgramSeven.java D student.java- Philosophy.txt 1 //ProgramSeven.java 2 import java.util.*; 5 import java.io.*; 6 7 public

Add a comment
Know the answer?
Add Answer to:
Java program Program: Grade Stats In this program you will create a utility to calculate and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program in Java according to the following specifications: The program reads a text file...

    Write a program in Java according to the following specifications: The program reads a text file with student records (first name, last name and grade on each line). Then it prompts the user to enter a command, executes the command and loops. The commands are the following: "print" - prints the student records (first name, last name, grade). "sortfirst" - sorts the student records by first name. "sortlast" - sorts the student records by last name. "sortgrade" - sorts the...

  • Write a program that performs the following: 1. Presents the user a menu where they choose...

    Write a program that performs the following: 1. Presents the user a menu where they choose between:              a. Add a new student to the class                           i. Prompts for first name, last name                           ii. If assignments already exist, ask user for new student’s scores to assignments              b. Assign grades for a new assignment                           i. If students already exist, prompt user with student name, ask them for score                           ii. Students created after assignment will need to...

  • PYTHON PROGRAMMING Instructions: You are responsible for writing a program that allows a user to do...

    PYTHON PROGRAMMING Instructions: You are responsible for writing a program that allows a user to do one of five things at a time: 1. Add students to database. • There should be no duplicate students. If student already exists, do not add the data again; print a message informing student already exists in database. • Enter name, age, and address. 2. Search for students in the database by name. • User enters student name to search • Show student name,...

  • using C# Write a program which calculates student grades for multiple assignments as well as the...

    using C# Write a program which calculates student grades for multiple assignments as well as the per-assignment average. The user should first input the total number of assignments. Then, the user should enter the name of a student as well as a grade for each assignment. After entering the student the user should be asked to enter "Y" if there are more students to enter or "N" if there is not ("N" by default). The user should be able to...

  • You are to write a program which will ask the user for number of students (dynamic...

    You are to write a program which will ask the user for number of students (dynamic array of class Student). For each student, you will ask for first name and number of grades (dynamic array of grades as a variable in Student). **The program should give the student random grades from 0-100** Find the averages of each student and display the information. **Display name, grades, and average neatly in a function in the Student class called Display()** Sort the students...

  • You are to write a program which will ask the user for number of students (dynamic...

    You are to write a program which will ask the user for number of students (dynamic array of class Student). For each student, you will ask for first name and number of grades (dynamic array of grades as a variable in Student). **The program should give the student random grades from 0-100** Find the averages of each student and display the information. **Display name, grades, and average neatly in a function in the Student class called Display()** Sort the students...

  • In this assignment you are asked to write a python program to maintain the Student enrollment...

    In this assignment you are asked to write a python program to maintain the Student enrollment in to a class and points scored by him in a class. You need to do it by using a List of Tuples What you need to do? 1. You need to repeatedly display this menu to the user 1. Enroll into Class 2. Drop from Class 3. Calculate average of grades for a course 4. View all Students 5. Exit 2. Ask the...

  • Java Program: In this project, you will write a program called GradeCalculator that will calculate the...

    Java Program: In this project, you will write a program called GradeCalculator that will calculate the grading statistics of a desired number of students. Your program should start out by prompting the user to enter the number of students in the classroom and the number of exam scores. Your program then prompts for each student’s name and the scores for each exam. The exam scores should be entered as a sequence of numbers separated by blank space. Your program will...

  • Create a C++ program to calculate grades as well as descriptive statistics for a set of...

    Create a C++ program to calculate grades as well as descriptive statistics for a set of test scores. The test scores can be entered via a user prompt or through an external file. For each student, you need to provide a student name (string) and a test score (float). The program will do the followings: Assign a grade (A, B, C, D, or F) based on a student’s test score. Display the grade roster as shown below: Name      Test Score    ...

  • Java - In NetBeans IDE: • Create a class called Student which stores: - the name...

    Java - In NetBeans IDE: • Create a class called Student which stores: - the name of the student - the grade of the student • Write a main method that asks the user for the name of the input file and the name of the output file. Main should open the input file for reading . It should read in the first and last name of each student into the Student’s name field. It should read the grade into...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT