Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 3: PARTI: Define a Java class named \"Student\" in a package named \"STU

ID: 3908871 • Letter: P

Question

Problem 3: PARTI: Define a Java class named "Student" in a package named "STUDENT". This class has three attributes 1. Student ID (an integer of 10 digits) 2. Full name (first last - of String type) 3. Major (a string) Class Student definition provides a default constructor, get-method and set-method for each attribute, and a public method to print out all information of the student in one line PART II: Write a Java program that can store data of three students in an array and display their data, each student in one line. The user enters all three student's data from the console. It is assumed that the user does not mak The Java program should be another Java class named "StudentDisplayer in the same package, i.e. STUDENT. The program creates an array of three elements of class Student type. After reading every piece of data of each student from the console, the program assigns the input to the corresponding element of the array. When all the data of the three students have been entered and correctly stored into the array, the program displays their data, each in one line, by invoking a public method of class Student. Important Notes: e any mistake while entering students' data To submit PARTI, students copy all the code of the class Student into a Notepad file named "hw2Student" (the file should have the suffix .txt) To submit PART II, students copy all the code of the program StudentDisplayer into a Notepad file named "hw2 StudentDisplayer" (the file should have the suffix .txt) . . Oxample Output in the Console Enter a student ID of Student #1: Enter a student's fuïï name - first ïast - of Student #1: X Y Enter a student's major of Student #1: ITM Enter a student ID of Student #2: 2 Enter a student's full name - first last - of Student #2 : Enter a student's major of Student #2: ITM Enter a student ID of Student #3: 3 Enter a student's full name - first last - of student #3: Enter a student's major of Student #3: arketinn StudentID: Name: XY Major: ITM StudentID: 2 Name: 2 Z Major: ITM StudentTD: 3 Name: YY ; Major: Maketinng

Explanation / Answer

package STUDENT;

public class Student
{
private int id;
private String firstName,lastName;
private String major;

public Student(int id,String firstName,String lastName,String major) // constructor
{
  this.id = id;
  this.firstName = firstName;
  this.lastName = lastName;
  this.major = major;
}
// set and get methods
public void setId(int id)
{
  this.id = id;
}
public int getId()
{
  return id;
}

public void setFirstName(String firstName)
{
  this.firstName = firstName;
}
public String getFirstName()
{
  return firstName;
}

public void setLastName(String lastName)
{
  this.lastName = lastName;
}
public String getLastName()
{
  return lastName;
}

public void setMajor(String major)
{
  this.major = major;
}
public String getMajor()
{
  return major;
}

public String toString()
{
  return "STUDENTID: "+id+" ; "+"NAME: "+firstName+" "+lastName+" ; "+" MAJOR: "+major;
}
}

package STUDENT;

import java.util.*;
public class StudentDisplayer
{
public static void main (String[] args)
{
  Scanner input = new Scanner(System.in);
  
  Student[] student = new Student[3]; //array of 3 objects
  int id;
  String firstName,lastName,major;
  
  for(int i=0;i<3;i++)
  {
   System.out.println("Enter a student ID of Student #"+(i+1));
   id = input.nextInt();
   
   System.out.println("Enter a student's Full Name - first-last - ID of Student #"+(i+1));
   firstName = input.next();
   
   lastName = input.next();
   
   System.out.println("Enter a student's major of Student #"+(i+1));
   major = input.next();
   
   student[i] = new Student(id,firstName,lastName,major);
   
  }
  
  for(int i=0;i<3;i++)
  {
   System.out.println(student[i]);
  }
}
}

Output:

Enter a student ID of Student #1 1
Enter a student's Full Name - first-last - ID of Student #1 X Y
Enter a student's major of Student #1 ITM
Enter a student ID of Student #2 2
Enter a student's Full Name - first-last - ID of Student #2 Z Z
Enter a student's major of Student #2 ITM
Enter a student ID of Student #3 3
Enter a student's Full Name - first-last - ID of Student #3 Y Y
Enter a student's major of Student #3 Marketing
STUDENTID: 1 ; NAME: X Y ; MAJOR: ITM
STUDENTID: 2 ; NAME: Z Z ; MAJOR: ITM
STUDENTID: 3 ; NAME: Y Y ; MAJOR: Marketing

Do ask if any doubt. Please upvote.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote