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

1. Write a program to display the student information (First name, Study Major,

ID: 3737589 • Letter: 1

Question

1. Write a program to display the student information (First name, Study Major, and ID #) that you have just entered. For this problem, you need to create an ArrayList < xyz> with xyz as the StudentEntry type parameter. You will need to create a method ( getEntry ( ) ) to read in the three student information and return the StudentEntry type for the ArrayList < >. Within the package, create a separate file for the Student entry class. For exception handling, you need to provide a try-catch block and allow user to re-enter if the input format is not correct. For displaying the results, you will use both the for-each and Iterator method as shown in the following example

2. Write a generic ArrayList < > program to remove duplicates in ArrayList of different type. A program with three ArrayList of different data type is provided for this problem (attached with this assignment). You need to write the method (removeDuplicated( type) ) to return a proper type for ArrayList< >. Currently this program does not compile until you complete the removeDuplicates ( … ) method.

Your final result should be as the following:

Program Provided for #2

Please enter 3 Student name, study major, and registration number Enter an student's name: Mary Enter an student's Major subject: Computer Science Enter that student's registration number: 1234 Enter an student's name: Tom Enter an student's Major subject: Physics Enter that student's registration number: 5344 Enter an student's name: Matt Enter an student's Major subject: Engineering Enter that student's registration number: 9393 Here's the data you entered display using For Each loop---- Name and major subject: (Mary, Computer Science) ID numberr: 1234 Name and major subject: (Tom, Physics) ID numberr: 5344 Name and major subject: (Matt , Engineering ID numberr: 9393 display using Iterator type loop++ Name and major subject: (Mary, Computer Science) ID numberr: 1234 Name and major subject: (Tom, Physics) ID numberr: 5344 Name and major subject: (Matt , Engineering ID numberr: 9393

Explanation / Answer

Hi, As per the chegg Rule, Please post only ONE big question in one post.

I have answered Q1.

Please repost others in separate post.

Please rate my answer if it helped you!!

###################   StudentInformation.java      ###################


import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;
public class StudentInformation {
//Method to get arrayList of StudentEntry
public ArrayList<StudentEntry> getEntry(StudentEntry studentEntry){
ArrayList<StudentEntry> studentEntries=new ArrayList<StudentEntry>();
studentEntries.add(studentEntry);
return studentEntries;
}
public static void main(String[] args) {
@SuppressWarnings("resource")
Scanner sc=new Scanner(System.in);
System.out.println("Enter Student First Name :");
String fName=sc.next();
System.out.println("Enter student major :");
String studentMajor=sc.next();
System.out.println("Enter student id : ");
String id=sc.next();
Integer properID=null;
//Checking if input iss not integer format, prompting user to re-enter it.
while(properID==null){
try{
properID=Integer.parseInt(id);
}
catch(Exception e){
System.out.println("Incorrect id format. Integers only!");
System.out.println("Enter student id : ");
id=sc.next();
}
}
StudentEntry entry=new StudentEntry(fName, studentMajor, properID);
StudentInformation information=new StudentInformation();
ArrayList<StudentEntry> entries=information.getEntry(entry);
System.out.println();
if(entries!=null){
//Using foreach loop
System.out.println("Using foreach loop");
System.out.println("--------------------");
for(StudentEntry stEntry : entries){
System.out.println("Student First Name : "+stEntry.getFirstName());
System.out.println("Student Major : "+stEntry.getStudentMajor());
System.out.println("Student ID : "+stEntry.getId());
}
System.out.println();
//Using Iterators
System.out.println("Using Iterator");
System.out.println("--------------------");
@SuppressWarnings("rawtypes")
Iterator itr = entries.iterator();
while(itr.hasNext()) {
StudentEntry element = (StudentEntry) itr.next();
System.out.println("Student First Name : "+element.getFirstName());
System.out.println("Student Major : "+element.getStudentMajor());
System.out.println("Student ID : "+element.getId());
}
}
}
}

###################        StudentEntry.java      ###################


public class StudentEntry {
private String firstName;
private String studentMajor;
private Integer id;
//StudentEntry parameterized constructor
public StudentEntry(String firstName, String studentMajor, Integer id) {
super();
this.firstName = firstName;
this.studentMajor = studentMajor;
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getStudentMajor() {
return studentMajor;
}
public void setStudentMajor(String studentMajor) {
this.studentMajor = studentMajor;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}

Sample run :


Enter Student First Name :
David
Enter student major :
CIS
Enter student id :
12sk5
Incorrect id format. Integers only!
Enter student id :
11205
Using foreach loop
--------------------
Student First Name : David
Student Major : CIS
Student ID : 11205
Using Iterator
--------------------
Student First Name : David
Student Major : CIS
Student ID : 11205

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote