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
Which of the following cameras is a high-end digital camera that has interchangeable lenses and uses a mirror to display on its
katovenus [111]
The camera that <span>is a high-end digital camera that has interchangeable lenses and uses a mirror to display on its screen an exact replica of the image to be photographed is called an SLR. Hope this answers the question. Have a nice day.</span>
5 0
2 years ago
A Python data model defining the state of a game for Tic-Tac-Toe. You must fully describe the notion of a state of the game, lim
Artist 52 [7]

Answer:

Check the explanation

Explanation:

Here in this game of Tic-Tac-Toe, it is using the TPGE engine which is a Tiny Python Game Engine. Let's talk about its functions like:-

def image_type(img): In this function, it is simply taking image as a parameter and returning its object type like DISC if the image is in graphical form, TEXT if it is a string, and LINE if it is other than the mentioned object.

def convert_image(img):  In this function, it is simply taking image as a parameter and returning an equivalent graphical object as understood by John Zelle's. Mainly comparing for three things in this function and those are: if image equals to DISC then it is calling convert_circle(function), if image equals to LINE then it is calling convert_line(function), and if image equals to TEXT then it is calling convert_text(function),

def convert_circle(x): This function takes a list( a group of values) and makes a circle at the center of the window and the circle's radius is coming from the list.

convert_text, convert_line, convert_circle are only creating text, line, and circle and then returning it.

def graphical_elements(images): This function is taking image as a parameter and then extracting shape and color from the image and then calling convert_image(shape) and convert_type(shape) and it gives us graphic and kind respectively. Now it is checking whether kind equals to DISC If yes then filling color on the window else, setting the outline of the window

def run(): Here it is finally running the game with required parameters, the whole game is continously running under the while loop.

That's all

8 0
3 years ago
A developer wants to take existing code written by another person and add some features specific to their needs. Which of the fo
anzhelika [568]

Answer:

open-source

Explanation:

open-souce software allows any user to submit modifications of the source code

7 0
2 years ago
Which term is used to identify the connection of computers that are physically close to one another?
marta [7]

Answer: Local Area Network (LAN)

Explanation:

A Local Area Network (LAN) is a computer network that interconnects computers within a limited physical area such as a residence, school, laboratory, university campus or office building.

An example of  LAN network is "Phone, Computer and TV connected to a single network (such as a Home Network) via Cables, Wifi, Bluetooth or Hotspot". When the devices are interconnected or connected to a LAN, it becomes accessible between each other.

A simplest example of a LAN Device is a <em>Home Router.</em>

6 0
3 years ago
Read 2 more answers
Given three variables, a, b, c, of type double that have already been declared and initialized, write a statement that prints ea
mihalych1998 [28]

Answer:

The statement is written in Java.

  1. System.out.printf("%.5f %.5f %.5f",a,b,c);

Explanation:

Presume that there are three variable a, b and c which have already been declared and initialized with 4.014268319, 14309, 0.00937608 respectively.

To print each of the value with 5 digits to the right of the decimal point, we can use printf() method. We create a format specifier %.5f which is a placeholder of a floating point value. The .5 will specify five digits to the right of the decimal point.

We just create three similar format specifiers ( one for variable a, b, and c, respectively) and include them into printf() method. This will print the output as follows:

4.01427 14309.00000 0.00938  

6 0
3 years ago
Other questions:
  • Use the script below as a starting point to create a Rectangle class. Your rectangle class must have the following methods;A con
    12·1 answer
  • Please help with this
    5·2 answers
  • A ____ by a design professional is used to determine the best system to provide the appropriate level and type of protection.
    6·1 answer
  • A variation of pronounce is a. Proclaim c. Produce b. Profound d. Pronunciation Please select the best answer from the choices p
    11·1 answer
  • Who invented the ENIAC? More than one answer may apply.
    14·1 answer
  • The move toward access instead of ownership is a sign of collaborative consumption.
    5·1 answer
  • What is the first step to apply the line and page breaks options to groups of paragraphs in a Word document?
    10·2 answers
  • ______________ is a raw fact about a person or an object
    6·1 answer
  • 1. Identify one modern technology and discuss its development and discuss what future changes might occur that could have an eve
    13·1 answer
  • Creating a Numpy Array
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!