There are many ways of doing this lab. Go for the solution closer to your Java s
ID: 3874784 • 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 20Zack 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 set1(String a[],int b[])
{
System.out.println("set1");
for(int k =0;k<3;k++)
{
System.out.println(""+a[k]+" "+b[k]);
}
System.out.println("-------------------");
}
public static void set2(String a[],int b[])
{
System.out.println("set2");
for(int m =0;m<3;m++)
{
System.out.println(""+a[m]+" "+b[m]);
}
System.out.println("-------------------");
int max = b[0]; // assume first elements as largest number
for (int i = 1; i < b.length; i++) // iterate for loop from arrays 1st index (second element)
{
if (b[i] > max)
{
max = b[i];
}
}
System.out.println("the max value is "+max);
}
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc = new Scanner(System.in);
String[] s = new String[100];
int age[] = new int[100];
for(int i =0;i<3;i++)
{
System.out.println("enter the set 1 age of "+i);
age[i] = sc.nextInt();
}
for(int j = 0;j<3;j++)
{
System.out.println("enter the set 1 name of "+j );
s[j] = sc.nextLine();
}
set1(s,age);
System.out.println("set2");
for(int k =0;k<3;k++)
{
System.out.println("enter the set 1 age of "+k);
age[k] = sc.nextInt();
}
for(int l = 0;l<3;l++)
{
System.out.println("enter the set 1 name of "+l );
s[l] = sc.nextLine();
}
set2(s,age);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.