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
Pavel [41]
3 years ago
9

Print person1's kids, call the incNumKids() method, and print again, outputting text as below. End each line with a newline.

Computers and Technology
1 answer:
Hatshy [7]3 years ago
5 0

Answer:

Hi there! This is a good question to grasp the concepts of object-oriented classes, encapsulation and abstraction of classes and their properties in Java. Please find the details below.

Explanation:

You can implement the solution by calling the getNumKids() function of the personInfo object or directly using the personKid input from the user to display the initial number of kids for the user. Then, calling the incNumKids() increases the kids count. Finally, displaying the new number of kids is done by invoking the getNumKids() method of the PersonInfo object that returns the private property of numKids to the user. The user cannot access this property without the get and set methods.

CallPersonInfo.java =====

import java.util.Scanner;

public class CallPersonInfo {

public static void main (String [] args) {

Scanner scnr = new Scanner(System.in);

PersonInfo person1 = new PersonInfo();

int personsKid;

personsKid = scnr.nextInt();

person1.setNumKids(personsKid);

System.out.println("Kids: " + personKid); // or person1.getNumKids();

   person1.incNumKids();

   System.out.println("New baby, kids now: " + personInfoObject.getNumKids());

 

}

}

You can also write the code in the same file as PersonInfo.java as below.

import java.util.Scanner;

class PersonInfo {

 private int numKids;

 public void setNumKids(int setPersonsKids) {

   numKids = setPersonsKids;

 }

 public void incNumKids() {

   numKids = numKids + 1;

 }

 public int getNumKids() {

   return numKids;

 }

 public static void main(String args[]) {

   System.out.println("Enter number of kids: ");

   Scanner scan = new Scanner(System.in);

   int num_kids = scan.nextInt();

   PersonInfo personInfoObject = new PersonInfo();

   personInfoObject.setNumKids(num_kids);

   System.out.println("Kids: " + num_kids);

   personInfoObject.incNumKids();

   System.out.println("New baby, kids now: " + personInfoObject.getNumKids());

 }

}

You might be interested in
What is the software that provides the mechanisms to access a database called?
NeX [460]

Answer:

Database Management Software.

Explanation:

The software that provides  the mechanism to access the database is called  Database Management Software.There are two types databases  SQL  and  No SQL.There are various types of  database Management Software  present online for ex:-My SQL,Microsoft SQL server,Microsoft Access,Postgres SQL,Mongo DB etc.

3 0
3 years ago
Intellectual property piracy has gotten a small boost from the increasing availability of counterfeit goods through Internet cha
Aliun [14]

Answer:

The answer is "Option B".

Explanation:

Intellectual property is protected by law in which property, copyright, and trademarks, are uses, that enable you to gain individuals' popularity or personally benefit according to what they create.

  • It is a program that helps to create an environment, in which imagination and technology are used.
  • It will change the growth by striking a balance between innovator rights and wider public interest.
3 0
3 years ago
You are writing a program to help compare two sports teams. A sample member of the list scores is [2. 5] where your team scored
Slav-nsk [51]

Answer:

The correct answer is C

Explanation:

4 0
3 years ago
Read 2 more answers
When you call a ____________ method, it executes statements it contains and then returns a value back to the program statement t
Maksim231197 [3]

Answer:

The answer is a VOID method.

Explanation:

A void method is one that simply performs a task and then terminates.

4 0
4 years ago
Read 2 more answers
Which Internet connection can have speeds around 1 Gbps?<br> Cable<br> DSL<br> Fiber<br> Satellite
Alexus [3.1K]
<h2>Answer:</h2>

<u>Fiber</u> Internet connection has speeds around 1 Gbps.

<h2></h2><h2>Explanation:</h2>

Fiber Internet connection is the modern way of transmitting and receiving data. As obvious from the name Optical Fiber consists of thin fibers that are extremely thin (as a human hair). They transmit data with the beam of light that make this transmission speedy as well as reliable. Therefore they provide  the download speed ranging from 25 Mbps to 1 Gbps.

Fiber Internet connection is considered best for the small businesses as it provides high bandwidth for transmission.  The best part of this connection is that it is made of glass and plastic that  do not conduct heat or electricity that means the fiber is safe from the damages as well.

<h3>I hope it will help you! </h3>
5 0
4 years ago
Other questions:
  • PLEASE HELP
    12·2 answers
  • An “evil twin” in the context of computer security is: a) A virus-laden attachment that looks just like a sincere attachment b)
    5·1 answer
  • What is a piece of information sent to a function
    15·1 answer
  • Question B_1 (15 points) Please define (describe) local variables and how they are used in computer programming ( e.g. In C, C )
    6·1 answer
  • Help meee pleaseeee
    5·1 answer
  • What is analog computer?​
    14·1 answer
  • Como se llama este icono de word
    9·1 answer
  • Mohammed’s parents learn that his classmates have begun sending him text messages making fun of his heritage. Mohammed says he’s
    5·2 answers
  • Ví dụ sau sẽ in ra dữ liệu của x là kiểu gì ?
    9·1 answer
  • How have cell phones improved our lives​
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!