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

Description

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

Implementation

For this assignment create the following classes.

class Sibling

Create a class Sibling with private instance variables for name, age and weight. Provide a constructor with parameters for initializing name, age and weight. Also provide accessor methods getName, getAge and getWeight for getting name, age and weight respectively.

class TestSibling

Create a class TestSibling containing the main method. In the main method, input the name, age and weight of each sibling and create a corresponding Sibling object containing the data.

After all Sibling objects are created, the main method will display the data for the lightest sibling followed by the youngest sibling. The data will include the sibling name, age and weight of the sibling. Use the object accessor methods for getting object data.

Notes:

Do the above assignment without using an array of objects.

The name of the method is formed by doing the following:

Capitalize the first letter of the instance variable name.

Pre-pend the instance variable name with the word get.

For example, for an instance variable age, the accessor method will be named getAge .

The accessor method does not receive any parameter. Its return type is always the same as the data type of the instance variable.

See the examples below:

instance variable declaration: private int age;

accessor method header: public int getAge ( )

instance variable declaration: private String name;

accessor method header: public String getName ( )

instance variable declaration: private double salary;

accessor method header: public double getSalary ( )

Modifier Methods

In a class, often the instance variables are declared private and are not directly accessible from outside the class or the object. For modifying the value of an instance variable, a public methods is provided. This method is called a modifier or a mutator or a setter method. For naming the modifier method, the following convention is used:

The name of the method is formed by doing the following:

Capitalize the first letter of the instance variable name.

Pre-pend the instance variable name with the word set.

Note

For doing this assignment, you need to provide only getter methods. You dont need to provide setter methods.

Testing:

For testing, use the following input data:

Jack 21 130

Judy 24 118

John 26 145

Note that in the above data Jack is 21 year old and weighs 130 lbs.

Output.

The program output will appear as below:

The Lightest Sibling: Judy 24 118

The Youngest Sibling: Jack 21 130

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!