RunStudent java程序辅导、讲解RunStudent java英文设计
- 首页 >> Java编程Programming and Logic I
Project 2 - Student Assignment
In this project, you will
-input student data from a file
-create a student object
-write the student object data to standard output.
Download the input text file studentInput.txt. This file contains four lines with a student’s data. The first line is the student’s first and last name, the second line is the student’s id number, the third is the student’s year and the fourth containing the student’s major.
Create a java file called<yourLastName>Student.java. This file will contain the Student class. My program would be ConwayStudent.java and my class name would be ConwayStudent.
In the class Student, code the following methods and data:
Fields (all should be private):
- String name
- int idNumber
- char year
- String major
Methods (all should be public):
- No argument constructor
- Constructor with 4 parameters: name, idNumber, year, major
- Accessors and mutators for fields
- a display method that nicely displays the values in the student object: name, id number, year and major
Modify your RunStudent program from project 1 to read a set of data from an input file and create a Student object. Instead of asking the user for the student data, the program will open the input file for reading (hard code the name of the input file – studentInput.txt) and read the four lines of data from the file. Make sure to remove the prompts to the user. You can use the File and Scanner classes to read from the file and you can assume the file exists.
Store the inputted values in appropriate variables. As in the previous project, store the name and major as Strings, the id number as an int, and the year as a char (F/O/J/S where F is for freshman, O is for sophomore, J is for junior, S is for senior).
Use the values obtained from the input file to create a student object. Finally, use the student object to call the display method. The only output should be a formatted display of the four values in the student object.
Upload <yourName>Student.java and <yourName>RunStudent.java