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

JAVA QUESTION instructions: make something similar to the example output is give

ID: 3715161 • Letter: J

Question

JAVA QUESTION

instructions: make something similar to the example output is given below + JAVA DOC

Madlibs Lab:

Here are the input files examples

Tarzan txt :

One of the most <adjective> characters in fiction is named
"Tarzan of the <plural-noun> ." Tarzan was raised by a/an
<noun> and lives in the <adjective> jungle in the
heart of darkest <place> . He spends most of his time
eating <plural-noun> and swinging from tree to <noun> .
Whenever he gets angry, he beats on his chest and says,
" <funny-noise> !" This is his war cry. Tarzan always dresses in
<adjective> shorts made from the skin of a/an <noun>
and his best friend is a/an <adjective> chimpanzee named
Cheetah. He is supposed to be able to speak to elephants and
<plural-noun> . In the movies, Tarzan is played by <person's-name> .

Sample Output to screen

Please type a adjective:happy

Please type a plural-noun:roosters

Please type a noun:dog

Please type a adjective:green

Please type a place:Texas

Please type a plural-noun:cookies

Please type a noun:senator

Please type a funny-noise:burp

Please type a adjective:silly

Please type a noun:raisen

Please type a adjective:old

Please type a plural-noun:cats

Please type a person's-name:Tom

Sample Outputfile

One of the most happy characters in fiction is named "Tarzan of the roosters ." Tarzan was raised by a/an dog and lives in the green jungle in the heart of darkest Texas . He spends most of his time eating cookies and swinging from tree to senator . Whenever he gets angry, he beats on his chest and says, " burp !" This is his war cry. Tarzan always dresses in silly shorts made from the skin of a/an raisen and his best friend is a/an old chimpanzee named Cheetah. He is supposed to be able to speak to elephants and cats . In the movies, Tarzan is played by Tom .

Part 2

Write a Student class with these instance variables. The Student class implements the Comparable interface

String Name

String major

double gpa

int studentID

Write 3 constructors -

   A fully qualified

   A no argument

   A copy constructor

Write setter and getters for each variable

Write a toString, equals, compareTo

Students are equal if there studentID are the same they are equal

The compareTo should make them alphabetical by last name.

Write a driver that makes five Student objects - use each constructor.

Make an ArrayList of Students. Put the 5 Students you created in the ArrayList.

In the main method ask the user to enter a studentID. Pass this int to a static method that will search the ArrayList for this id and return true or false. You will have to pass the ArrayList and the entered studentID to the method.

Check if two students are equal. Sort the ArrayList. Print out all the student info using the toString.

Explanation / Answer

Part 2:

Student class:

public class Student implements Comparable<Student>

{

//instance variables

private String name,major;

private double gpa;

private int studentID;

  

//fully qualified constructor

public Student(String name, String major, double gpa, int studentID)

{

super();

this.name = name;

this.major = major;

this.gpa = gpa;

this.studentID = studentID;

}

//no constructor

public Student() {}

  

//copy constructor

public Student(Student student)

{

this.name = student.name;

this.major = student.major;

this.gpa = student.gpa;

this.studentID = student.studentID;

}

  

//Write setter and getters for each variable

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getMajor() {

return major;

}

public void setMajor(String major) {

this.major = major;

}

public double getGpa() {

return gpa;

}

public void setGpa(double gpa) {

this.gpa = gpa;

}

public int getStudentID() {

return studentID;

}

public void setStudentID(int studentID) {

this.studentID = studentID;

}

//toString()

public String toString()

{

return "Student [name=" + name + ", major=" + major + ", gpa=" + gpa + ", studentID=" + studentID + "]";

}

//equals() method

public boolean equals(Student obj)

{

Student other = (Student) obj;

if (Double.doubleToLongBits(gpa) != Double.doubleToLongBits(other.gpa))

return false;

if (major == null)

{

if (other.major != null)

return false;

} else if (!major.equals(other.major))

return false;

if (name == null) {

if (other.name != null)

return false;

} else if (!name.equals(other.name))

return false;

if (studentID != other.studentID)

return false;

return true;

}

//compareTo should make them alphabetical by name

public int compareTo(Student student)

{

return name.compareTo(student.name);

}

}

Test class:

import java.util.ArrayList;

import java.util.Collections;

import java.util.Iterator;

import java.util.Scanner;

//driver class

public class TestStudentApp

{

//driver method that makes five Student objects

public static void main(String[] args)

{

//ArrayList of Students

ArrayList<Student> studentList = new ArrayList<Student>();

//creating 5 student objects

Student s1=new Student("Jince","Computer scicence",4.5,12345);

Student s2=new Student("Luke","Micro biology",3.0,12131);

Student s3=new Student("Arone","Civil scicence",3.5,12105);

Student s4=new Student("Ray","Earth Scicence",4.0,12300);

Student s5=new Student("Root","Mechanical",3.0,12210);

// and keeping them in array list

studentList.add(s1);

studentList.add(s2);

studentList.add(s3);

studentList.add(s4);

studentList.add(s5);

//ask the user to enter a studentID.

Scanner scan = new Scanner(System.in);

System.out.print("Enter a studentID:");

int studentId=scan.nextInt();

//calling search() method

boolean found=searchStudentId(studentList,studentId);

System.out.println("Result="+found);

//calling equals() method in in the student class

boolean isStudentEqual=s1.equals(s3);

System.out.println("isEqual?:"+isStudentEqual);

//sorting the array list using Collections.sort() method

Collections.sort(studentList);

//iterator to traverse the list

Iterator<Student> it=studentList.iterator();

while(it.hasNext())

{

Student obj=it.next();

System.out.println(obj.toString());

}

}

//static method to find the student id

public static boolean searchStudentId(ArrayList<Student> studentList,int studentId)

{

//variable to hold the result

boolean result=false;

//iterator to traverse the list

Iterator<Student> it=studentList.iterator();

while(it.hasNext())

{

//getting student object

Student student= it.next();

//getting each student id from each student object

int sid=student.getStudentID();

//comparing studentID variable with each student id

if(studentId==sid)

{

//if found,return true and halt

result=true;

break;

}

}

//return result

return result;

}

}

Output:

Enter a studentID:12101
Result=false
isEqual?:false
Student [name=Arone, major=Civil scicence, gpa=3.5, studentID=12105]
Student [name=Jince, major=Computer scicence, gpa=4.5, studentID=12345]
Student [name=Luke, major=Micro biology, gpa=3.0, studentID=12131]
Student [name=Ray, major=Earth Scicence, gpa=4.0, studentID=12300]
Student [name=Root, major=Mechanical, gpa=3.0, studentID=12210]