Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

(1a)

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.

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 don't 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

-----------------------------------------

(1b)

Topics

Inheritance

Discussion

Inheritance involves creating a class by extending another class. The extended class is called a child class and the original class is called the parent class. For creating a child class, we need the .class file of the parent class.

The child class is created by adding an extends clause in the child class header.

Once created, an object of the child class contains all the instance variables and constructors and instance methods of child, parent and parents parent (ancestor) classes.

The object of the child class is created by using a child class constructor. Java requires that a child class constructor call parent class constructor as its first statement using reserved word super.

Description

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

This program will be an enhancement of a previous exercise that did the same. However, this program will additionally provide for inputting height and displaying the tallest sibling.

Do this assignment using inheritance as described in implementation section below.

Implementation

For this assignment create the following classes.

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 for getting name, age and weight.

The content of this class will be identical to the one in the previous exercise. You may copy the contents of this class from the previous exercise.

SiblingExt

Create a class SiblingExt that will extend the class Sibling above and will provide a private instance variable for keeping height. It will provide a constructor with parameters for initializing name, age, weight and height. This constructor will call the parent constructor for initializing name, age and weight and will initialize the height by itself. The class will also provide an accessormethod for getting height. (Since this class extends the Sibling class, the accessor methods from the Sibling class for getting name, age and weight will be part of an object of this class).

TestSiblingExt

Write a class TestSiblingExt containing the main method. In the main method, input the name, age, weight and height of each sibling and create a corresponding SiblingExt object containing the data.

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

This class can be created by modifying the TestSibling class in the previous exercise. You may copy the contents of TestSiblingclass from a previous exercise and then modify them to create this class.

INSTRUCTIONS

Do the above assignment without using an array of objects.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Murach's SQL Server 2012 For Developers

Authors: Bryan Syverson, Joel Murach, Mike Murach

1st Edition

1890774693, 9781890774691

More Books

Students also viewed these Databases questions