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

There are many ways of doing this lab. Go for the solution closer to your Java s

ID: 3875250 • Letter: T

Question

There are many ways of doing this lab. Go for the solution closer to your Java skills. The most basic way is a series of “if” statements.

Set 1 task(s): Create three students using the "Set 1" data shown below. Prefix this output with two lines. On line one, output "Set 1". On line two, output twenty hyphens. Then, display all class variables of each student. After ensuring desired results are present, apply a single-line comment to introduce the logic you wrote as: // Set 1 task(s)...

Set 2 task(s): Create three more students using the "Set 2" data shown below. Prefix this output with two lines. On line one, output "Set 2". On line two, output twenty hyphens. Then, find and display the name of the youngest of these three students.  After ensuring desired results are present, apply a single-line comment to introduce the logic you wrote as: // Set 2 task(s)...

Set 3 task(s): Create three more students using the "Set 3" data shown below. Prefix this output with two lines. On line one, output "Set 3". On line two, output twenty hyphens. Then, find and display the name of the oldest of these three students. After ensuring desired results are present, apply a single-line comment to introduce the logic you wrote as: // Set 3 task(s)...

By "find" above, I mean using the objects' data and doing calculations instead of you looking at the data and displaying John as the youngest and Fred as the oldest.

Test your solution with the following sets of data:

Set 1 Set 2 Set 3 John Smith 20
Zack Mills 21
Fred Fonz 44 John Smith 33
Zack Mills 22
Fred Fonz 20 John Smith 20
Zack Mills 40
Fred Fonz 30

Explanation / Answer

Hello, I have a solution for you. Implemented everything as per the requirements. Defined following things in this answer.

//Student.java class

public class Student {

      private String firstName;

      private String lastName;

      private int age;

      /**

      * Constructor to initialize variables

      */

      public Student(String firstName, String lastName, int age) {

            this.firstName = firstName;

            this.lastName = lastName;

            this.age = age;

      }

      public String getFirstName() {

            return firstName;

      }

      public void setFirstName(String firstName) {

            this.firstName = firstName;

      }

      public String getLastName() {

            return lastName;

      }

      public void setLastName(String lastName) {

            this.lastName = lastName;

      }

      public int getAge() {

            return age;

      }

      public void setAge(int age) {

            this.age = age;

      }

      /**

      * method to return a string containing all data

      */

      public String toString() {

            return firstName+", "+lastName+", "+age;

      }

     

}

//Test.java class

public class Test {

      public static void main(String[] args) {

            /**

            * creating 3 students (set1)

            */

            Student s1 = new Student("John", "Smith", 20);

            Student s2 = new Student("Zack", "Mills", 21);

            Student s3 = new Student("Fred", "Fonz", 44);

            /**

            * Displaying the set1 output

            */

            System.out.println("Set 1");

            for (int i = 0; i < 20; i++) {

                  System.out.print("-");

            }

            System.out.println(); /* line break */

            System.out.println(s1);

            System.out.println(s2);

            System.out.println(s3);

            /**

            * creating 3 students (set2)

            */

            Student s4 = new Student("John", "Smith", 33);

            Student s5 = new Student("Zack", "Mills", 22);

            Student s6 = new Student("Fred", "Fonz", 20);

            /**

            * Displaying the set2 output

            */

            System.out.println(" Set 2");

            for (int i = 0; i < 20; i++) {

                  System.out.print("-");

            }

            System.out.println(); /* line break */

            Student youngest = null;

            /**

            * Finding the youngest student in set2

            */

            if (s4.getAge() <= s5.getAge() && s4.getAge() <= s6.getAge()) {

                  youngest = s4;

            } else if (s5.getAge() <= s6.getAge()) {

                  youngest = s5;

            } else {

                  youngest = s6;

            }

            System.out.println(youngest.getFirstName() + " "

                        + youngest.getLastName() + " is the youngest in set2, age: "

                        + youngest.getAge());

            /**

            * creating 3 students (set3)

            */

            Student s7 = new Student("John", "Smith", 20);

            Student s8 = new Student("Zack", "Mills", 40);

            Student s9 = new Student("Fred", "Fonz", 30);

            /**

            * Displaying the set3 output

            */

            System.out.println(" Set 3");

            for (int i = 0; i < 20; i++) {

                  System.out.print("-");

            }

            System.out.println(); /* line break */

            Student eldest = null;

            /**

            * Finding the eldest student in set3

            */

            if (s7.getAge() >= s8.getAge() && s7.getAge() >= s9.getAge()) {

                  eldest = s7;

            } else if (s8.getAge() >= s9.getAge()) {

                  eldest = s8;

            } else {

                  eldest = s9;

            }

            System.out.println(eldest.getFirstName() + " "

                        + eldest.getLastName() + " is the eldest in set3, age: "

                        + eldest.getAge());

      }

}

/*OUTPUT*/

Set 1

--------------------

John, Smith, 20

Zack, Mills, 21

Fred, Fonz, 44

Set 2

--------------------

Fred Fonz is the youngest in set2, age: 20

Set 3

--------------------

Zack Mills is the eldest in set3, age: 40

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