# Question & Answer: rogramming and Logic I Project 3 – Student Assignment In this project, you will – input student data…..

Don't use plagiarized sources. Get Your Custom Essay on
Question & Answer: rogramming and Logic I Project 3 – Student Assignment In this project, you will – input student data…..
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS \$13/PAGE

Solution===============================================

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

//Barebone student class
class Student{
String firstName;
String lastName;
int ID;
char year;
String major;

public void display(){
System.out.println(“Student: “+firstName+” “+lastName+”, Id: “+ID+”, Year:”+year+”, Major: “+major);
}
}

public class RunStudent {
private Student students[];

public RunStudent(){
//Allocating memory for 4 students
students=new Student[4];
}

public void printStudentArray(Student[] s){
//Only one instance is so created, as requirement
//Instance named student
for(Student student:s){
student.display();
}
}

public void populateDataFromFile() throws FileNotFoundException{
Scanner in = new Scanner(new File(“studentInput3.txt”));
//Getting data from file to objects
for(int i=0;i<4;i++){
//Creating an object
Student student = new Student();
//Assigning values from file
String[] names=in.nextLine().split(” “);
student.firstName=names[0];
student.lastName=names[1];
student.ID=Integer.parseInt(in.nextLine());
student.year=in.nextLine().charAt(0);
student.major=in.nextLine().trim();

//Putting the object inside the array
students[i]=student;

}

in.close();
}

public static void main(String[] args) throws FileNotFoundException {
RunStudent run = new RunStudent();
run.populateDataFromFile();
run.printStudentArray(run.students);

}

}

SnapShot==================================================

Input File Used:==========================================