Question

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

Contents

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
0 0
Add a comment Improve this question Transcribed image text
Answer #1

/* 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]+"\t"+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 \n"+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 \n"+b[n]+""+largest);

}

  

}

  

}   

}

Add a comment
Know the answer?
Add Answer to:
Contents There are many ways of doing this lab. Go for the solution closer to your...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Develop a set of classes for a college to use in various student service and personnel applications. Classes you need to design include the following: • Person — A Person contains the following fields...

    Develop a set of classes for a college to use in various student service and personnel applications. Classes you need to design include the following: • Person — A Person contains the following fields, all of type String: firstName, lastName, address, zip, phone. The class also includes a method named setData() that sets each data field by prompting the user for each value and a display method that displays all of a Person’s information on a single line at the...

  • import java.util.*; /** Description: This program determines the average of a list of (nonnegative) exam scores....

    import java.util.*; /** Description: This program determines the average of a list of (nonnegative) exam scores. Repeats for more exams until the user says to stop. Input: Numbers, sum, answer Output: Displays program description Displays instruction for user Displays average Algorithm: 1. START 2. Declare variables sum, numberOf Students, nextNumber, answer 3. Display welcome message and program description 4. DOWHILE user wants to continue 5. Display instructions on how to use the program 6. Inititalize sum and number of student...

  • Lab 2: (one task for Program 5): Declare an array of C-strings to hold course names,...

    Lab 2: (one task for Program 5): Declare an array of C-strings to hold course names, and read in course names from an input file. Then do the output to show each course name that was read in. See Chapter 8 section on "C-Strings", and the section "Arrays of Strings and C-strings", which gives an example related to this lab. Declare the array for course names as a 2-D char array: char courseNames[10] [ 50]; -each row will be a...

  • Lab Exercise #11 Assignment Overview You will work with a partner on this exercise during your la...

    help with cse problem Lab Exercise #11 Assignment Overview You will work with a partner on this exercise during your lab session. Two people should work at one computer. Occasionally switch the person who is typing. Talk to each other about what you are doing and why so that both of you understand each step Part A: Class Date . Download the files for this laboratory exercise, then run the Python shell and enter the following commands: >>>import date >>help(...

  • Tasks A. (20 po ints) In Lab 6, you defined and implemented a class called Date....

    Tasks A. (20 po ints) In Lab 6, you defined and implemented a class called Date. You will make some modific ation to the Date class so that it mccts the folowing specific ations: The Date class consists of three private member variables: Member Variable year month day Description An int variable that hokls the value of a year. An int variable that hokds the value of a month An int variable that hokis the value of a day. The...

  • Your task is to develop a large hexadecimal integer calculator that works with hexadecimal integers of...

    Your task is to develop a large hexadecimal integer calculator that works with hexadecimal integers of up to 100 digits (plus a sign). The calculator has a simple user interface, and 10 \variables" (n0, n1, ..., n9) into which hexadecimal integers can be stored. For example a session with your calculator might look like: mac: ./assmt1 > n0=0x2147483647 > n0+0x3 > n0? 0x214748364A > n1=0x1000000000000000000 > n1+n0 > n1? 0x100000000214748364A > n0? 0x214748364A > exit mac: Note: \mac: " is...

  • Overview This lab provides you the opportunity to insert and update data with the use of SQL comm...

    Overview This lab provides you the opportunity to insert and update data with the use of SQL commands. The lab will utilize the FLIX2YOU problem, the current schema. In order to start this lab, you must have successfully completed Lab # 6. In Lab # 6, you executed a script that was provided to you. This script created 7 of the FLIX2YOU tables as documented in the Entity Relationship Diagram in the FLIX2YOU problem document. The second part of lab...

  • please use python and provide run result, thank you! click on pic to make it bigger...

    please use python and provide run result, thank you! click on pic to make it bigger For this assignment you will have to investigate the use of the Python random library's random generator function, random.randrange(stop), randrange produces a random integer in the range of 0 to stop-1. You will need to import random at the top of your program. You can find this in the text or using the online resources given in the lectures A Slot Machine Simulation Understand...

  • If you’re using Visual Studio Community 2015, as requested, the instructions below should be exact but...

    If you’re using Visual Studio Community 2015, as requested, the instructions below should be exact but minor discrepancies may require you to adjust. If you are attempting this assignment using another version of Visual Studio, you can expect differences in the look, feel, and/or step-by-step instructions below and you’ll have to determine the equivalent actions or operations for your version on your own. INTRODUCTION: In this assignment, you will develop some of the logic for, and then work with, the...

  • #include <iostream> #include <iomanip> #include <vector> using namespace std; Part 1. [30 points] In this part,...

    #include <iostream> #include <iomanip> #include <vector> using namespace std; Part 1. [30 points] In this part, your program loads a vending machine serving cold drinks. You start with many foods, some are drinks. Your code loads a vending machine from foods, or, it uses water as a default drink. Create class Drink, make an array of drinks, load it and display it. Part 1 steps: [5 points] Create a class called Drink that contains information about a single drink. Provide...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT