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

Set 1 task(s): Create three students using the \"Set 1\" data shown below. Prefi

ID: 3875339 • Letter: S

Question

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

/* package codechef; // don't place package name! */

import java.util.*;

import java.lang.*;

import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */

class Codechef

{

public static void main (String[] args) throws java.lang.Exception

{

// your code goes here

Scanner sc = new Scanner(System.in);

int a[] = new int[3];

String b[] = new String[3];

int smallest = Integer.MAX_VALUE;

int largest = Integer.MIN_VALUE;

int count = 0;

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

for(int i =0;i<3;i++)

{

System.out.println("enter the age");

a[i] = sc.nextInt();

System.out.println("enter the name");

b[i] = sc.next();

}

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

System.out.println("------------------");

for(int j = 0;j<3;j++)

{

  

System.out.println(""+a[j]+" "+b[j]);

  

}

for(int k =0;k<3;k++)

{

  

System.out.println("enter the age for set 2");

a[k] = sc.nextInt();

System.out.println("enter the name for set 2");

b[k] = sc.next();

}

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

System.out.println("------------------");

for(int l =0;l<a.length;l++) {

  

if(smallest > a[l]) {

smallest = a[l];

}

}

for(int m =0;m<3;m++)

{

if(a[m] == smallest)

{

System.out.println("the name and age of youngest of three member is "+b[m]+""+smallest);

}

  

}

for(int r =0;r<3;r++)

{

  

System.out.println("enter the age for set 2");

a[r] = sc.nextInt();

System.out.println("enter the name for set 2");

b[r] = sc.next();

}

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

System.out.println("------------------");

for(int p =0;p<a.length;p++) {

  

if(largest < a[p]) {

largest = a[p];

}

}

for(int n =0;n<3;n++)

{

if(a[n] == largest)

{

System.out.println("the name and age of oldest of three member is "+b[n]+""+largest);

}

  

}

  

}   

}

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