Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am having trouble with this Java program. Please include comments to your code so I can understand your implementation. I. General Description In this

I am having trouble with this Java program. Please include comments to your code so I can understand your implementation.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

I. General Description In this assignment, you will create a Java program to read undergraduate and graduate students from an input file, and write them in reverse order to an output file. 1. The input file name and the output file name are passed in as the first and second arguments at command line, respectively. For example, assume your package name is FuAssign5 and your main class name is FuAssignment5, and your executable files are in "C:\Users 2734848\eclipse-workspace CIS 265 Assignments bin". The following command line will read from a local file "students.txt" and write to a local file "students reversed.txt": C:\Users\2734848\eclipse-workspace\CIS 265 Assignments\bin > java FuAssign5. FuAssignments students.txt students_reversed.txt 2. You need to specify the command line arguments if you use jGrasp or Eclipes. I will show you on jGrasp on Wed. during the lab. 3. The parameter String[] args in the main method contains the command line arguments, where args[0] contains the first argument. For example, in the previous command, args[0] contains students.txt. 4. If the program is run with incorrect number of arguments, your program must print an error message and exit. The error message must show correct format to run your program, e.g., "Usage: FuAssign5.FuAssignment5 input_file output_file where FuAssign5 is the package and FuAssignment5 is the main class. 5. Each line in the input file represents a student. There are 5 fields in each line: name, id, gpa, "graduate" or "undergraduate", is Transfer (for undergraduate) or college (for graduate). The fields are separated by comma, ,. For example, the input file students.txt file may contain: Michelle Chang, 200224,3.3, graduate, Cleveland State University Tayer Smoke, 249843,2.4, undergraduate, false David Jones, 265334,2.7, undergraduate, true Abby Wasch, 294830,3.6, graduate, West Virginia 6. The program will read the lines and create undergraduate students or graduate students accordingly. The students are added to an ArrayList. 7. The program then writes the list of students in reserve order to the output file. 8. Given the previous input file students.txt, the output file, students reserved.txt, will be: Abby Wasch, 294830,3.6, graduate, West Virginia David Jones, 265334,2.7, undergraduate, true Tayer Smoke, 249843,2.4, undergraduate, false Michelle Chang, 200224,3.3,graduate, Cleveland State University II. Implementation Requirements The program must implement a main class and three student classes (Student, Undergrad Student, GradStudent You may reuse the code from previous assignments. However, the Student class must be declared as an abstract class now. It must also have an overloaded printStudent(Print Writer output) method. The method will write student's information to the output file using the output Print Writer. Accordingly, the UnderGradStudent and GradStudent classes must also have an overloaded printStudent(Print Writer output) method. They must use the superclass' method to write student's information. The UnderGradStudent's printStudent(Print Writer output) writes "undergraduate" and is Transfer after that. The GradStudent's printStudent (Print Writer output) writes "graduate and college after that. The UML class diagram should be as follows. Student -name: String -id: int -gpa: float +Student +Student(name,id, gpa) +pringStudent():void +getIDO:int +printStudent(Print Writer output):void UndegradStudent GradStudent -boolean: is Transfer -college:String +UndergradStudent(name,id,gpa, is Transfer) +GradStudent(name,id,gpa,college) +pringStudent():void +pring Student():void +printStudent(Print Writer output):void +printStudent(Print Writer output):void All classes must be in the same package. The package name must start with your last name. For example, if your last name is Trump, your package name must start with Trump such as TrumpCIS265AS3, "TrumpAS3, etc. You main class file name must start with your last name. For example, if your last name is Fu, your main class file name must start with "Fu" such as FuAssignment5.java. Since 1/0 exceptions are checked exceptions, your program must handle exceptions. You may use the try/catch or throw IOException. To throw exceptions, you declare it as: public static void main(String[] args) throws IOException { You must create an ArrayList of Students in the main class: import java.util.ArrayList; ArrayList students = new ArrayList(); The ArrayList students will store all Student objects created, both undergraduate students and graduate students. The Student class must have a constructor that takes a name, an id, and a gpa, to create a Student object. The UndergradStudent class must have a constructor that takes a name, an id, a gpa, and a transfer status to create an UndergradStudent object. The constructor must call the Student's constructor using super. The GradStudent class should must a constructor that takes a name, an id, a gpa, and a college to create a GradStudent object. The constructor must call the Student's constructor using super. The Student class must have a public method printStudent(Print Writer output) that writes the student's name, id, and gpa to the Print Writer output. The UndergradStudent class must override the printStudent(Print Writer output) method. It must write the student's name, id, gpa, and transfer status to the Print Writer output. It should call the Student's printStudent(Print Writer output) to write student's name, id, and gpa. The gradStudent class must override the printStudent(Print Writer output) method. It must write the student's name, id, gpa, and college to the Print Writer output. It should call the Student's printStudent(Print Writer output) to write student's name, id, and gpa. Your program must use dynamic binding to invoke the correction printStudent(Print Writer output) method. Your program must close both input and output files after they are done. You can assume that input file has the correct format. You will earn bonus points for handling incorrect input formats. I. General Description In this assignment, you will create a Java program to read undergraduate and graduate students from an input file, and write them in reverse order to an output file. 1. The input file name and the output file name are passed in as the first and second arguments at command line, respectively. For example, assume your package name is FuAssign5 and your main class name is FuAssignment5, and your executable files are in "C:\Users 2734848\eclipse-workspace CIS 265 Assignments bin". The following command line will read from a local file "students.txt" and write to a local file "students reversed.txt": C:\Users\2734848\eclipse-workspace\CIS 265 Assignments\bin > java FuAssign5. FuAssignments students.txt students_reversed.txt 2. You need to specify the command line arguments if you use jGrasp or Eclipes. I will show you on jGrasp on Wed. during the lab. 3. The parameter String[] args in the main method contains the command line arguments, where args[0] contains the first argument. For example, in the previous command, args[0] contains students.txt. 4. If the program is run with incorrect number of arguments, your program must print an error message and exit. The error message must show correct format to run your program, e.g., "Usage: FuAssign5.FuAssignment5 input_file output_file where FuAssign5 is the package and FuAssignment5 is the main class. 5. Each line in the input file represents a student. There are 5 fields in each line: name, id, gpa, "graduate" or "undergraduate", is Transfer (for undergraduate) or college (for graduate). The fields are separated by comma, ,. For example, the input file students.txt file may contain: Michelle Chang, 200224,3.3, graduate, Cleveland State University Tayer Smoke, 249843,2.4, undergraduate, false David Jones, 265334,2.7, undergraduate, true Abby Wasch, 294830,3.6, graduate, West Virginia 6. The program will read the lines and create undergraduate students or graduate students accordingly. The students are added to an ArrayList. 7. The program then writes the list of students in reserve order to the output file. 8. Given the previous input file students.txt, the output file, students reserved.txt, will be: Abby Wasch, 294830,3.6, graduate, West Virginia David Jones, 265334,2.7, undergraduate, true Tayer Smoke, 249843,2.4, undergraduate, false Michelle Chang, 200224,3.3,graduate, Cleveland State University II. Implementation Requirements The program must implement a main class and three student classes (Student, Undergrad Student, GradStudent You may reuse the code from previous assignments. However, the Student class must be declared as an abstract class now. It must also have an overloaded printStudent(Print Writer output) method. The method will write student's information to the output file using the output Print Writer. Accordingly, the UnderGradStudent and GradStudent classes must also have an overloaded printStudent(Print Writer output) method. They must use the superclass' method to write student's information. The UnderGradStudent's printStudent(Print Writer output) writes "undergraduate" and is Transfer after that. The GradStudent's printStudent (Print Writer output) writes "graduate and college after that. The UML class diagram should be as follows. Student -name: String -id: int -gpa: float +Student +Student(name,id, gpa) +pringStudent():void +getIDO:int +printStudent(Print Writer output):void UndegradStudent GradStudent -boolean: is Transfer -college:String +UndergradStudent(name,id,gpa, is Transfer) +GradStudent(name,id,gpa,college) +pringStudent():void +pring Student():void +printStudent(Print Writer output):void +printStudent(Print Writer output):void All classes must be in the same package. The package name must start with your last name. For example, if your last name is Trump, your package name must start with Trump such as TrumpCIS265AS3, "TrumpAS3, etc. You main class file name must start with your last name. For example, if your last name is Fu, your main class file name must start with "Fu" such as FuAssignment5.java. Since 1/0 exceptions are checked exceptions, your program must handle exceptions. You may use the try/catch or throw IOException. To throw exceptions, you declare it as: public static void main(String[] args) throws IOException { You must create an ArrayList of Students in the main class: import java.util.ArrayList; ArrayList students = new ArrayList(); The ArrayList students will store all Student objects created, both undergraduate students and graduate students. The Student class must have a constructor that takes a name, an id, and a gpa, to create a Student object. The UndergradStudent class must have a constructor that takes a name, an id, a gpa, and a transfer status to create an UndergradStudent object. The constructor must call the Student's constructor using super. The GradStudent class should must a constructor that takes a name, an id, a gpa, and a college to create a GradStudent object. The constructor must call the Student's constructor using super. The Student class must have a public method printStudent(Print Writer output) that writes the student's name, id, and gpa to the Print Writer output. The UndergradStudent class must override the printStudent(Print Writer output) method. It must write the student's name, id, gpa, and transfer status to the Print Writer output. It should call the Student's printStudent(Print Writer output) to write student's name, id, and gpa. The gradStudent class must override the printStudent(Print Writer output) method. It must write the student's name, id, gpa, and college to the Print Writer output. It should call the Student's printStudent(Print Writer output) to write student's name, id, and gpa. Your program must use dynamic binding to invoke the correction printStudent(Print Writer output) method. Your program must close both input and output files after they are done. You can assume that input file has the correct format. You will earn bonus points for handling incorrect input formats

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_2

Step: 3

blur-text-image_3

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

Advances In Databases And Information Systems 22nd European Conference Adbis 2018 Budapest Hungary September 2 5 2018 Proceedings Lncs 11019

Authors: Andras Benczur ,Bernhard Thalheim ,Tomas Horvath

1st Edition

3319983970, 978-3319983974

More Books

Students also viewed these Databases questions