For this lab assignment, you will be writing a few classes that can be used by an educator to grade multiple choice exams. It will give you experience using some Standard Java Classes (Strings, Lists, Maps), which you will need for future projects. The following are the required classes:
AllExam.txt
Tobacco Christian A B C D D C B A A B Russo James D A C B A C A D A A Smith John A A A A A A A A A A Henderson James B B B B B B B B B B Russo Michael C C C C C C C C C C DeMartino John A B C D D C B A C D Scafuri Frank A B C D A C B A A D
Answer.txt
A B C D D C B A A B
Student.java
public class Student {
String lastName;
String firstName;
double average;
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public double getAverage() {
return average;
}
public void setAverage(double average) {
this.average = average;
}
public Student() {
}
public Student(String lastName, String firstName)
{
this.lastName=lastName;
this.firstName=firstName;
this.average=0;
}
}
UnitTest.java
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;
public class UnitTest {
Scanner input;
ArrayList<String> answers;
public UnitTest() {
answers = new
ArrayList<>();
String[] fields;
FileInputStream filestream;
String path = "Answers.txt";
try {
filestream = new FileInputStream(path);
BufferedReader br = new BufferedReader(new
InputStreamReader(filestream));
String str = br.readLine();
fields = str.split(" ");
for(int i=0;i<10;i++)
answers.add(fields[i]);
br.close();
} catch
(FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch
(IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public double calculateGrade(ArrayList<String>
answer) {
int count=0;
for(int
i=0;i<answers.size();i++) {
if(answers.get(i).compareTo(answer.get(i))==0)
++count;
}
return
count*100/answer.size();
}
}
UnitTestRunner.java
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
public class UnitTestRunnner {
public static void main(String[] args) {
// TODO Auto-generated method
stub
UnitTest unit = new
UnitTest();
String name ;
ArrayList<String>
grades;
ArrayList<Student> students =
new ArrayList<>();
HashMap<String,ArrayList<String>> map = new
HashMap<>();
String[] fields;
FileInputStream filestream;
String path = "AllExams.txt";
try {
filestream = new FileInputStream(path);
BufferedReader br = new BufferedReader(new
InputStreamReader(filestream));
String str = br.readLine();
while (str != null) {
name = new String();
grades=new
ArrayList<String>();
fields = str.split("
");
name=
fields[1]+fields[0];
students.add(new
Student(fields[0],fields[1]));
for(int i=0;i<10;i++)
{
grades.add(fields[i+2]);
}
map.put(name, grades);
str =
br.readLine();
}
br.close();
} catch
(FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch
(IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ArrayList<ArrayList<String>> values = new
ArrayList<>(map.values());
for(int i=0;
i<students.size();i++) {
System.out.println(students.get(i).getFirstName()+" " +
students.get(i).getLastName()+ " " +
unit.calculateGrade(values.get(i)));
}
}
}
Output
Christian Tobacco 30.0
James Russo 30.0
John Smith 80.0
James Henderson 20.0
Michael Russo 100.0
John DeMartino 80.0
Frank Scafuri 30.0
Screenshot
Feel free to ask any doubts, if you face any difficulty in understanding.
Please upvote the answer if you find it helpful
For this lab assignment, you will be writing a few classes that can be used by...
Introduction In this lab, you will be working with three classes: Person, Student, and Roster. Person and Student represent individuals with a first and last name as String class variables, and Student has an additional int class variable that represents a ID number. The Roster class represents a group of people that are objects of either the Person or Student class. It contains an ArrayList. The Person class has been completed for you with class variables, a constructor, and a...
Hi, I am writing Java code and I am having a trouble working it out. The instructions can be found below, and the code. Thanks. Instructions Here are the methods needed for CIS425_Student: Constructor: public CIS425_Student( String id, String name, int num_exams ) Create an int array exams[num_exams] which will hold all exam grades for a student Save num_exams for later error checking public boolean addGrade( int exam, int grade ) Save a grade in the exams[ ] array at...
Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class should contain the following data fields and methods (note that all data and methods are for objects unless specified as being for the entire class) Data fields: A String object named firstName A String object named middleName A String object name lastName Methods: A Module2 constructor method that accepts no parameters and initializes the data fields from 1) to empty Strings (e.g., firstName =...
In Java: Executable Class create an array of Employee objects. You can copy the array you made for Chapter 20. create an ArrayList of Employee objects from that array. use an enhanced for loop to print all employees as shown in the sample output. create a TreeMap that uses Strings for keys and Employees as values. this TreeMap should map Employee ID numbers to their associated Employees. process the ArrayList to add elements to this map. print all employees in...
( Object array + input) Write a Java program to meet the following requirements: 1. Define a class called Student which contains: 1.1 data fields: a. An integer data field contains student id b. Two String data fields named firstname and lastname c. A String data field contains student’s email address 1.2 methods: a. A no-arg constructor that will create a default student object. b. A constructor that creates a student with the specified student id, firstname, lastname and email_address...
Java: student directory GUI You need to implement three classes: Person Student StudentDirectory StudentMain Start by implementing Person and Student classes. Once you are sure you can serialize and deserialize and ArrayList of Students to and from a file, move on to building the GUI application. Person: The Person class should implement serializable interface. It contains the following: Person's first name (String) Person's last name (String) Person's id number Person's date of birth (Date) public String toString(): This method method...
This is the question: These are in Java format. Comments are required on these two Classes (Student.java and StudentDemo.java) all over the coding: Provide proper comments all over the codings. --------------------------------------------------------------------------------------------------------------- import java.io.*; import java.util.*; class Student { private String name; private double gradePointAverage; public Student(String n , double a){ name = n; gradePointAverage = a; } public String getName(){ return name; } public double getGradePointAverage(){ return gradePointAverage; } ...
How could I separate the following code to where I have a gradebook.cpp and gradebook.h file? #include <iostream> #include <stdio.h> #include <string> using namespace std; class Gradebook { public : int homework[5] = {-1, -1, -1, -1, -1}; int quiz[5] = {-1, -1, -1, -1, -1}; int exam[3] = {-1, -1, -1}; string name; int printMenu() { int selection; cout << "-=| MAIN MENU |=-" << endl; cout << "1. Add a student" << endl; cout << "2. Remove a...
help please Program Requirements You are given 1 file: Lab1Tests.java. You need to complete 1 file: UWECPerson.java uWECPerson.java UWECPerson uwecld: int firstName: String lastName : String +UWECPerson(uwecld: int, firstName : String, lastName: String) +getUwecid): int setUwecld(uwecld: int): void +getFirstName): String +setFirstName(firstName: String): void getLastName): String setLastName(lastName: String): void +toString): String +equals(other: Object): boolean The constructor, accessors, and mutators behave as expected. The equals method returns true only if the parameter is a UWECPerson and all instance variables are equal. The...
using C++ language!! please help me out with this homework In this exercise, you will have to create from scratch and utilize a class called Student1430. Student 1430 has 4 private member attributes: lastName (string) firstName (string) exams (an integer array of fixed size of 4) average (double) Student1430 also has the following member functions: 1. A default constructor, which sets firstName and lastName to empty strings, and all exams and average to 0. 2. A constructor with 3 parameters:...