1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Paul [167]
3 years ago
13

Write a program that will input the names, ages and weights of three siblings and display the lightest followed by the youngest

of the siblings. Do the above assignment without using an array of objects. Implementation Create a project asSibling. In the above project, create a class Sibling not containing the main method. In the above project, create a class TestSibling containing the main method.

Computers and Technology
1 answer:
jekas [21]3 years ago
4 0

Answer:

Here is the JAVA program:

Sibling.java class:

import java.util.Scanner;  //to accept input from user

public class Sibling {  //class name

//private data members of class

   private String name;  // String type variable to hold the name of sibling

   private int age;  // int type variable to hold the age of sibling

   private int weight;  // int type variable to hold the weight of sibling

   public Sibling() {}     //constructor of class Sibling

   public Sibling (String n, int a, int w)  {  //parameterized constructor

       name = n;  // refers to name field

       age = a;  // refers to age field

       weight = w;    }   // refers to weight field

   public String getName ()    {   //accessor method to get the current name of sibling

       return name;    }   //returns the name field of the sibling

   public int getAge ()    {   //accessor method to get the current age of sibling

       return age;    }   //returns the age field of the sibling

   public int getWeight (){ //accessor method to get the current weight of sibling

    return weight;    } //returns the weight field of the sibling

   public void getInput() {    //to take input name,age and weight from user

 Scanner input = new Scanner(System.in);  //Scanner class object

 System.out.print("Enter the name:  ");  //prompts user to enter the name of sibling

 name = input.nextLine();  //scans and reads the input name from user

 System.out.print("Enter the age:  ");  //prompts user to enter the age of sibling

 age = input.nextInt();   //scans and reads the age from user

 System.out.print("Enter the weight:  ");  //prompts user to enter the weight of sibling

 weight = input.nextInt(); } }   //scans and reads the input weight from user

Explanation:

Here is the TestSibling class that contains main method:

public class TestSibling {   //class name

public static void main (String[] args) {   //main method

String name;  // to hold name of sibling

int age, weight;   // to hold age and weight of sibling

Sibling sib1, sib2, sib3;   // objects of Sibling class

sib1 = new Sibling ();  // creates object of class Sibling for sibling 1 and calls constructor

sib1.getInput();   // calls getInput method using sib1 object to get the name, age and weight of sibling 1

sib2 = new Sibling ();  // creates object of class Sibling for sibling 2 and calls constructor

sib2.getInput();   //calls getInput method using sib2 object to get the name, age and weight of sibling 2

sib3 = new Sibling ();  //creates object of class Sibling for sibling 3 and calls constructor

sib3.getInput();   //calls getInput method using sib3 object to get the name, age and weight of sibling 3

Sibling youngest=null, lightest=null;    //holds the youngest age and lightest weight of siblings

if (sib1.getAge( )<= sib2.getAge( ) && sib1.getAge( ) <= sib3.getAge( ) )   /*if condition checks if age of sibling 1 is less than or equals to that of sibling 2 and sibling 3,  using object of each sibling and getAge method to access age. the logical operator && AND is used so that if condition evaluates to true if sib1 is younger than both sib2 and sib3 */

{ youngest=sib1;}   //if the above condition is true then sets sib1 as youngest

else if (sib2.getAge( ) <= sib1.getAge( ) && sib2.getAge( ) <= sib3.getAge( ) )   // else if condition checks if age of sibling 2 is less than or equals to that of sibling 1 and sibling 3

{youngest=sib2;}   // if above condition is true then sets sib2 as the youngest

else   //if none of the above condition is true then this means that the third has the lowest age

{            youngest=sib3;    }    //sets sib3 as the youngest

if (sib1.getWeight( ) <= sib2.getWeight( ) && sib1.getWeight( ) <= sib3.getWeight( ) )   //if condition checks if weight of sibling 1 is less than or equals to that of sibling 2 and sibling 3,  using object of each sibling and getAge method to access weight of each sibling

          { lightest=sib1; }   //if the above condition is true then sets sib1 as having the lightest weight

else if (sib2.getWeight( ) <= sib1.getWeight( ) && sib2.getWeight( ) <= sib3.getWeight( ) )  // else if condition checks if weight of sibling 2 is less than or equals to that of sibling 1 and sibling 3

{lightest=sib2; }  //if the above condition is true then sets sib2 as the lightest

else  //if none of the above condition is true then this means that the third has the lightest weight

{ lightest=sib3;   }  //sets sib3 as the lightest

System.out.println("The lightest sibling: " + lightest.getName() +" " + lightest.getAge()+" "+ lightest.getWeight());  } } //calls the getName() getAge() and getWeight() method using object lightest to print the lightest of the siblings

System.out.println("The youngest sibling: " + youngest.getName() +" " + youngest.getAge()+" "+ youngest.getWeight());  //calls the getName() getAge() and getWeight() method using object youngest to print the youngest of the siblings

The screenshot of the output is attached.

You might be interested in
hi pls help me how to connect my imac to our wifi cause it’s not showing the wifi option (use pic for reference)
Ainat [17]
Your searching in Bluetooth not wifi you need to switch it
7 0
2 years ago
study the picture of the simulation and the graph above. based on the information obtained from your study of the simulation and
andreyandreev [35.5K]
This is how you know i’m def gonna fail my university class this year :/
6 0
2 years ago
Edhesive 6.8 lesson practice answers
FromTheMoon [43]

Answer:

1.) 25 ; 15 ; 15

2.) 50 ; 15 ; 50

Explanation:

In the first function written :

The variable val was initially decaled or assigned a value of 25 and that was what was printed first.

However, after the example function was written, the val variable was finally assiagned a value of 15 within the function. However, it was also declared that the global variable takes uonthe val value. Hence, the val variable initially assigned a value, of 25 changes to 15 globally.

For the second code :

From the top:

Val was assigned a value of 50 ;

Hence,

print(val) gives an output of 50

Within the function definition which prints the value of val that is assigned a value of 25 within the function.

Since tbe global variable isnt reset.

Printing Val again outputs 50;since ito is outside the function.

6 0
2 years ago
What is the basic purpose of the International Space Station that will be completed in 2010?
frosja888 [35]
The best and most correct answer among the choices provided by the question is the third choice "It will be a space laboratory for scientists"<span>

The main purpose of the International Space Station<span> is to provide an </span>international<span> laboratory for experiments within the </span>space<span> environment. Which, despite all our technological advances, is nearly impossible to replicate here on Earth.
</span>
I hope my answer has come to your help. God bless and have a nice day ahead!</span>
6 0
3 years ago
How do you add a simple header that will appear in a single column on the left of a document
malfutka [58]

When adding a header, you need to double tap the top of the document.

4 0
2 years ago
Read 2 more answers
Other questions:
  • How old is the oldest asian
    14·2 answers
  • How do I download the Microsoft word on my Hp probook
    8·2 answers
  • Which of the following identifies the patterns used for each data series in a chart?
    13·1 answer
  • Three variables, x, y and z, supposedly hold strings of digits, suitable for converting to integers. Write code that converts th
    7·1 answer
  • Briefly explain five measures you have undertaken to protect your confidential
    12·1 answer
  • Write a function that, given an array A of N integers, of which represents loads caused by successive processes, the function sh
    15·1 answer
  • When are bar charts most commonly used
    10·1 answer
  • A student registers for a course in a university. Courses may have limited enrollment i.e a student must
    5·1 answer
  • Rideshare companies like Uber or Lyft track the x,y coordinates of drivers and customers on a map. If a customer requests a ride
    5·1 answer
  • Avi does not want to save his internet browsing details on his computer. What should he do?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!