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
2. Using the Enhanced for Statement, write an application that uses an enhanced for statement to sum the double values passed by
solniwko [45]

Answer:

Here is the program:

public class DoubleValue

{ public static void main(String[] args) { //start of the main function

 double sum = 0.0;  // initialize double type sum by 0.0

//for statement to sum the double values passed by the command-line //arguments

       for (String str : args)        {  

         sum += Double.parseDouble(str);  

//returns double representation of the passed str argument and takes the //sum of these double values         }

       System.out.printf("The sum of the double values passed in from the command line is %.1f\n", sum);  }  }      

//prints the above message with output 0.0                                  

Explanation:

The above program has a static method parseDouble of class Double to convert a string str to a double value and the for statement is used to sum the double values passed by command line arguments. This sum is stored in sum variable and is displayed in the output. The program along with its output is attached.

If you want to get the input from the user you can use the following code. Just use the Scanner class to take input from the user.

import java.util.Scanner;

public class DoubleValue

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

//two string type variables

 String str1;

               String str2;

//scans and reads input from user

Scanner input = new Scanner(System.in);

System.out.println("Enter value of str1: ");

str1 = input.next();

System.out.println("Enter value of str2: ");

str2 = input.next();

double sum = 0.0;

//sum double values and parseDouble function is used to convert string to //double value

sum += Double.parseDouble(str1) + Double.parseDouble(str2);

System.out.printf("The sum of the double values passed in from the command line is %.1f\n", sum); } }  //prints result of the sum

5 0
3 years ago
PYTHON
Korvikt [17]

Answer:

import random

print("Hello! I have a random number from 1 to 100! It is your job to try and guess it!")

number = random.randint(1,101)

guess = int(input("start to guess: "))

num_guesses = 1

while guess != number:

   if guess > number:

       print("lower")

       guess = int(input("try again: "))

       num_guesses +=1

   elif guess < number:

       print ("higher")

       guess = int(input("start to guess: "))

       num_guesses +=1

print("congrats it took you", num_guesses, "tries")

Explanation:

6 0
3 years ago
A keyboard shortcut to pasting in a document is to key _____.
m_a_m_a [10]
(Ctrl + V) is the shortcut for pasting.

Similarly, (Ctrl + C) is the shortcut for copying.
6 0
3 years ago
You want to get information about DNS request types and DNS query packet content. What kind of DNS logging do you need to enable
ololo11 [35]

Answer:

Option C i.e., Analytic event logging is the correct answer.

Explanation:

The user required to enable Analytic event logging Type of DNS logging to take data or information related to the type of DNS request and also the content packet of the DNS query. By Analytic event logging, Users get data about the forms of DNS requests and the size of the DNS query packets. That's why the following option is correct.

8 0
3 years ago
True or False <br><br> Rootkits are only made by black-hat hackers.
Kipish [7]
True rookies are only made by black hat hackers I am not sure I hope this will help
4 0
3 years ago
Other questions:
  • Our company is only interested in purchasing a software upgrade if it leads to faster connectivity and data sharing. The old sof
    7·1 answer
  • An engineer is assigned to replace an older data-grade autonomous wireless network with a cisco controllerbased wireless network
    6·1 answer
  • Dani wants to create a web page to document her travel adventures. Which coding language should she use? HTML Java Python Text
    15·1 answer
  • When you choose the ____ compression setting, photos are compressed to the resolution specified on the advanced tab in the power
    13·2 answers
  • Parts are described by partnum, color, and price. Parts can be subassemblies as well and this means that they contain other part
    12·1 answer
  • a traditional wireless network involving access points that all have wired connections is known as a ?​
    5·1 answer
  • True of False - use T or F The Math class can be instantiated.
    15·1 answer
  • A program that doesn’t work properly needs to be debugged. true or false
    8·1 answer
  • Write fade in shorthand​
    11·1 answer
  • Identify some possible delivery systems for video programs
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!