Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please help with this assignment not getting desired output, below are the errors i recieved when submitting, and also the code plus the files necessary

please help with this assignment not getting desired output, below are the errors i recieved when submitting, and also the code plus the files necessary to complete

Input

lab5.txt out.txt

Your output

Unable to open file: input.txt Name ID Units Taken Units Completed Average Total number of Students: 0 Total Units completed by all students: 0 Total Units taken by all students: 0

Your output does not contain

Name Id Units Taken Units Completed Average Joe Smith Jr. 111-22-3333 13 9 2.46 Bill Jones 111-11-1111 15 15 3.60 Nancy Brown 222-11-1111 42 38 3.38 Total number of Students: 3 Total Units completed by all students: 62 Total Units taken by all students: 70

Input

student.txt out.txt

Your output

Unable to open file: input.txt Name ID Units Taken Units Completed Average Total number of Students: 0 Total Units completed by all students: 0 Total Units taken by all students: 0

Your output does not contain

Name Id Units Taken Units Completed Average John Smithson 111-99-3333 13 9 2.77 Bill Jonesville 111-99-1111 10 10 3.90 Nancy Brownsen 222-11-1111 39 35 3.26 Joe Smith Jr. 111-22-3333 13 9 2.46 Bill Jones 111-11-1111 15 15 3.60 Nancy Brown 222-11-1111 42 38 3.38 Total number of Students: 6 Total Units completed by all students: 116 Total Units taken by all students: 132

Input

blank.txt out.txt

Your output

Unable to open file: input.txt Name ID Units Taken Units Completed Average Total number of Students: 0 Total Units completed by all students: 0 Total Units taken by all students: 0

Your output does not contain

File has no data.

Input

abc.txt out.txt

Your output

Unable to open file: input.txt Name ID Units Taken Units Completed Average Total number of Students: 0 Total Units completed by all students: 0 Total Units taken by all students: 0

Your output does not contain

File does not exist

Write a Java program that prompts user for a file name, opens and reads the data, process, and store them in an array or ArrayList of students. A Student (you need to declare it) is a class defining a Student with information (such as name, id and a list of courses) and associated operations; Course is a class containing information (such as name, grade and number of units) and associated operations. The program calculates the total completed units and GPA for a student. The program then prints a table to the monitor and stops execution. (Refer to the sample below.)

Use the following table to assign points for a course:

Grade Points
A 4.0
B 3.0
C 2.0
D 1.0
F 0.0

To calculate the GPA multiply units by points for each course, and then add then together and divide the sum by total units. For example if course 1 has 5 units and the grade is A (4 points) and course 2 has 4 units and the grade is B (3 points), and course 3 has 4 units and the grade is F then (4 * 3 + 5 * 4 + 4 * 0)/13 = 2.462. Completed course are all the courses that have a passing grade (a, b, c, and d), Units taken is sum of all units registered for.

Completed courses are considered the ones with passing grade (A,B,C,D).

Input File Format: Input File Sample:
Last, First Smith Jr., Joe
ID numberofcourses 111-22-3333 3
Course 1 name Physics I
Grade Units A 5
Course 2 name English 1A
Grade Units B 4
Course 3 name English 1B
Grade Units F 4
Jones , Bill
111-11-1111 4
Physics I
A 5
Chemistry 1A
B 5
Computer Science 1
A 4
Chemistry 1 Lab
B 1

Requirements:

  • Develop a class to represent a Student (the following data members must be included, more is OK) :
    • Name (First, Last)
    • Id number
    • list of courses
    • number of units taken
    • units completed
    • units taken
    • average.
  • Develop a class to represent a Course(the following data members must be included, more is OK):
    • Course Name
    • Course Units
    • Course Grade
  • Program must be modular (all tasks must be done in methods)
  • Must include methods to process array of students
  • UML representation of classes
  • Prompt user for all input and output file names
  • Use attached data file to test your program.
  • Error check files
  • If you use an array, set array size to 20 for students and courses, but when adding elements check the size to make sure not to overflow the array.

Final report to the monitor and output file

Sample output:

Name Id Units Taken Units Completed Average Joe Smith Jr. 111-22-3333 13 9 2.46 Bill Jones 111-11-1111 15 15 3.60 Nancy Brown 222-11-1111 42 38 3.38 Total number of Students: 3 Total Units completed by all students: 62 Total Units taken by all students: 70 

Required files to submit:

  • Student.java
  • Course.java
  • MangeStudent.java

//students.txt

Smithson, John 111-99-3333 3 Chemistry I A 5 English ESL A 4 English 1B F 4 Jonesville, Bill 111-99-1111 3 Physics I A 5 Computer Science 1 A 4 Chemistry 1 Lab B 1 Brownsen, Nancy 222-11-1111 12 English 1A B 4 English 1B F 4 Physics II A 5 Geology 101 B 3 Chemistry 1A B 5 Computer Science 1 A 4 Chemistry 1A Lab B 1 Physics II Lab A 1 Physics III A 5 Physics III Lab A 1 Chemistry 1B A 5 Chemistry 1B Lab A 1 Smith Jr., Joe 111-22-3333 3 Physics I A 5 English 1A B 4 English 1B F 4 Jones, Bill 111-11-1111 4 Physics I A 5 Chemistry 1A B 5 Computer Science 1 A 4 Chemistry 1 Lab B 1 Brown, Nancy 222-11-1111 13 Physics I A 5 English 1A B 4 English 1B F 4 Physics II A 5 Chemistry 1A B 5 Computer Science 1 A 4 Chemistry 1A Lab B 1 Physics I Lab A 1 Physics II Lab A 1 Physics III A 5 Physics III Lab A 1 Chemistry 1B A 5 Chemistry 1B Lab A 1

//lab5.txt

Smith Jr., Joe 111-22-3333 3 Physics I A 5 English 1A B 4 English 1B F 4 Jones, Bill 111-11-1111 4 Physics I A 5 Chemistry 1A B 5 Computer Science 1 A 4 Chemistry 1 Lab B 1 Brown, Nancy 222-11-1111 13 Physics I A 5 English 1A B 4 English 1B F 4 Physics II A 5 Chemistry 1A B 5 Computer Science 1 A 4 Chemistry 1A Lab B 1 Physics I Lab A 1 Physics II Lab A 1 Physics III A 5 Physics III Lab A 1 Chemistry 1B A 5 Chemistry 1B Lab A 1

//blank.txt

  • import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; // Course.java class Course { private String name; private String grade; private int units; // default constructor public Course() {} // parameterized constructor public Course(String name, String grade, int units) { this.name = name; this.grade = grade; this.units = units; } // setters public void setName(String name) { this.name = name; } public void setGrade(String grade) { this.grade = grade; } public void setUnits(int units) { this.units = units; } // getters public String getName() { return name; } public String getGrade() { return grade; } public int getUnits() { return units; } // method to return grade points corresponding to the grade public double getGradePoints() { if (grade.equalsIgnoreCase("A")) return 4.0; else if ( grade.equalsIgnoreCase("B") ) return 3.0; else if (grade.equalsIgnoreCase("C")) return 2.0; else if ( grade.equalsIgnoreCase("D") ) return 1.0; else return 0.0; } } //end of Course.java // Student.java class Student { private String lastname; private String firstname; private String id; private int numCourses; private Course courses[]; private int unitsCompleted; private int unitsTaken; private double avg; // default constructor public Student() { courses = new Course[20]; numCourses = 0; unitsCompleted = 0; unitsTaken = 0; avg = 0; } // parameterized constructor public Student(String lastname, String firstname, String id) { this.lastname = lastname; this.firstname = firstname; this.id = id; courses = new Course[20]; numCourses = 0; unitsCompleted = 0; unitsTaken = 0; avg = 0; } // setters public void setLastname(String lastname) { this.lastname = lastname; } public void setFirstname(String firstname) { this.firstname = firstname; } public void setID(String id) { this.id = id; } // method to add course to the student public void addCourse(Course course) { // check if array is not full if (numCourses < courses.length) { // add the course at the end and update unitsTaken and unitsCompleted courses[numCourses] = course; numCourses++; unitsTaken += course.getUnits(); if (!course.getGrade().equalsIgnoreCase("F")) unitsCompleted += course.getUnits(); } } // method to calculate and return the GPA public double getAverage() { double totalPoints = 0; for (int i = 0; i < numCourses; i++) { totalPoints += (courses[i].getGradePoints() * courses[i].getUnits()); } if (unitsTaken > 0) avg = totalPoints / unitsTaken; return avg; } // getters public int getUnitsTaken() { return unitsTaken; } public int getUnitsCompleted() { return unitsCompleted; } public String getLastname() { return lastname; } public String getFirstname() { return firstname; } public String getID() { return id; } } //end of Student.java // ManageStudent.java class ManageStudent { // method to read student information from file into students array and return number of students read public static int loadStudents(Student students[], String filename) { int count = 0; try { // open the file Scanner fileScan = new Scanner(new File(filename)); String last, first, id, courseName, grade; int numCourses, units; // loop to read till the end of file while (fileScan.hasNext()) { // check that students array is not full if (count < students.length) { // read the name and extract it to last name and first name last = fileScan.nextLine(); first = last.substring(last.indexOf(",") + 1).trim(); last = last.substring(0, last.indexOf(",")).trim(); id = fileScan.next(); // read id numCourses = fileScan.nextInt(); // read number of courses fileScan.nextLine(); // ignore left by nextInt // create a Student object students[count] = new Student(last, first, id); // loop numCourses times to read the course details for (int i = 0; i < numCourses; i++) { courseName = fileScan.nextLine(); // read course name grade = fileScan.next(); // read grade units = fileScan.nextInt(); // read units if ( fileScan.hasNextLine() ) fileScan.nextLine(); // if not reached end of file, read and discard left by nextInt // create course object and add it to student's courses Course c = new Course(courseName, grade, units); students[count].addCourse(c); } count++; // increment number of students read } else break; // array is full, exit the loop } fileScan.close(); // close the file } catch (FileNotFoundException e) { // file error System.out.println("Unable to open file: " + filename); return count; } return count; } // method to display student details on screen public static void displayStudents(Student students[], int numStudents) { System.out.printf( "%-30s%-15s%-15s%-20s%15s", "Name", "ID", "Units Taken", "Units Completed", "Average" ); for (int i = 0; i < numStudents; i++) { System.out.printf( " %-30s%-15s%-15d%-20d%13.2f", students[i].getFirstname() + " " + students[i].getLastname(), students[i].getID(), students[i].getUnitsTaken(), students[i].getUnitsCompleted(), students[i].getAverage() ); } } // method to display summary data i.e number of students, total units completed and total units taken by all students and public static void displaySummary(Student students[], int numStudents) { System.out.println(" Total number of Students: " + numStudents); int totalTaken = 0, totalCompleted = 0; // loop to calculate total units completed and taken by all students in array for (int i = 0; i < numStudents; i++) { totalTaken += students[i].getUnitsTaken(); totalCompleted += students[i].getUnitsCompleted(); } System.out.println( "Total Units completed by all students: " + totalCompleted ); System.out.println("Total Units taken by all students: " + totalTaken); } public static void main(String[] args) { String filename = "input.txt"; // input filename Student students[] = new Student[20]; // create an array of 20 Student // load students data into array from input file int numStudents = loadStudents(students, filename); // display student information displayStudents(students, numStudents); // display summary data displaySummary(students, numStudents); } } //end of ManageStudent.java

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Optimization And Data Science Trends And Applications 5th Airoyoung Workshop And Airo Phd School 2021 Joint Event

Authors: Adriano Masone ,Veronica Dal Sasso ,Valentina Morandi

1st Edition

3030862887, 978-3030862886

More Books

Students also viewed these Databases questions