answer.
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
klasskru [66]
2 years ago
10

Define the instance method inc_num_kids() for PersonInfo. inc_num_kids increments the member data num_kids. Sample output for th

e given program with one call to inc_num_kids():

Computers and Technology
1 answer:
kow [346]2 years ago
7 0

Answer:

This is the instance method inc_num_kids()

def inc_num_kids(self):

       self.num_kids += 1

Explanation:

The first line is the definition of function inc_num_kids() which has a parameter self. self is basically an instance of  class PersonInfo

self.num_kids += 1 this statement incremented the data member num_kids by 1. This means that the instance method inc_num_kids, using instance self, increments the value of num_kids data member by 1.

The complete program is as following:

class PersonInfo:  #class name PersonInfo

   def __init__(self):   #constructor of the class

       self.num_kids = 0  # data member num_kids

   def inc_num_kids(self):  # method inc_num_kids

       self.num_kids += 1  #increments num_kids by 1

person1 = PersonInfo()  #creates object person of class PersonInfo

print('Kids:', person1.num_kids)  # prints num_kids value before increment

person1.inc_num_kids()  #calls inc_num_kids method to increment num_kids

print('New baby, kids now:', person1.num_kids) #prints the value of num_kids after increment by inc_num_kids method

The person1 object first access the initial value of num_kids initialized by the constructor. So the first value of num_kids is 0. self.num_kids = 0  This statement assigns the value 0 to num_kids data member. Next the method inc_num_kids() using the object person1. Now when this method is called the value of data member num_kids is incremented to 1.

So previously the value was 0 which now increments by 1 and becomes 1. Last print statement displays this new value which is incremented by the inc_num_kids() method.

Hence the output is:

Kids: 0

New baby, kids now: 1

The program along with its output is attached.

You might be interested in
A city government is attempting to reduce the digital divide between groups with differing access to computing and the Internet.
sergeinik [125]

Answer:

C

Explanation:

Putting all government forms on the city web site is the least activity likely to be effective in the purpose of reducing digital divide.

Holding basic computer classes at the community centers will very much help to reduce the digital divide.

Providing free wireless internet connections at locations in low-income neighborhood will also reduce the gap of digital divide

Requiring that every city school has computers that meet a minimum hardware and software will made computing resources available to users thereby reducing digital divide.

5 0
1 year ago
Cooper Technologies is a technology company that offers many IT services in Chicago. The company's services and products include
yuradex [85]

Answer:

d. broad needs and few customers.

Explanation:

This strategy is based on creation of unique and valuable persons.

Broad needs and few customers (Wealth Management )

Wealth management is a service that combines to address the needs of clients. Wealth Management utilizes financial discipline such as financial and investment , accounting and tax.This service is appropriate for individuals with broad array of diverse needs.

4 0
2 years ago
Write a function addOddMinusEven that takes two integers indicating the starting point and the end point. Then calculate the sum
snow_lady [41]

Answer:g

   public static int addOddMinusEven(int start, int end){

       int odd =0;

       int even = 0;

       for(int i =start; i<end; i++){

           if(i%2==0){

               even = even+i;

           }

           else{

               odd = odd+i;

           }

       }

       return odd-even;

   }

}

Explanation:

Using Java programming language:

  • The method addOddMinusEven() is created to accept two parameters of ints start and end
  • Using a for loop statement we iterate from start to end but not including end
  • Using a modulos operator we check for even and odds
  • The method then returns odd-even
  • See below a complete method with a call to the method addOddMinusEven()

public class num13 {

   public static void main(String[] args) {

       int start = 2;

       int stop = 10;

       System.out.println(addOddMinusEven(start,stop));

   }

   public static int addOddMinusEven(int start, int end){

       int odd =0;

       int even = 0;

       for(int i =start; i<end; i++){

           if(i%2==0){

               even = even+i;

           }

           else{

               odd = odd+i;

           }

       }

       return odd-even;

   }

}

8 0
1 year ago
Create a program named Auction that allows a user to enter an amount bid on an online auction item. Include three overloaded met
Olin [163]

Answer:

Explanation:

The following code is written in Java and creates the overloaded methods as requested. It has been tested and is working without bugs. The test cases are shown in the first red square within the main method and the output results are shown in the bottom red square...

class Auction {

   public static void main(String[] args) {

       bid(10);

       bid(10.00);

       bid("10 dollars");

       bid("$10");

       bid("150 bills");

   }

   public static void bid(int bid) {

       if(bid >= 10) {

           System.out.println("Bid Accepted");

       } else {

           System.out.println("Bid not high enough");

       }

   }

   public static void bid(double bid) {

       if(bid >= 10) {

           System.out.println("Bid Accepted");

       } else {

           System.out.println("Bid not high enough");

       }

   }

   public static void bid(String bid) {

       if (bid.charAt(0) == '$') {

           if (Integer.parseInt(bid.substring(1, bid.length())) > 0) {

               System.out.println("Bid Accepted");

               return;

           } else {

               System.out.println("Bid not in correct Format");

               return;

           }

       }

       int dollarStartingPoint = 0;

       for (int x = 0; x < bid.length(); x++) {

           if (bid.charAt(x) == 'd') {

               if (bid.substring(x, x + 7).equals("dollars")) {

                   dollarStartingPoint = x;

               } else {

                   break;

               }

           }

       }

       if (dollarStartingPoint > 1) {

           if (Integer.parseInt(bid.substring(0, dollarStartingPoint-1)) > 0) {

               System.out.println("Bid Accepted");

               return;

           } else {

               System.out.println("Bid not in correct format");

               return;

           }

       } else {

           System.out.println("Bid not in correct format");

           return;

       }

   }

}

3 0
1 year ago
Give the logical function for the following: If cell B7 equals 12, check contents of cell B10. If cell B10 is 10, then the value
ASHA 777 [7]

Answer:

=IF( B7 = 12, ( IF( B10 = 10,"YES", "")), 7) and PRESS ENTER

Explanation:

the above logical if function checks the following

-IF cell B7 is 12, if true, check the value of cell B10, IF cell B10 contains 10 the function should produce YES as output to whatever cell selected, IF B10 is not 10 output of the function should be an empty string, IF B7 is not equal to 12 the the output of the function should be 7.

5 0
2 years ago
Other questions:
  • ____ refers to typing your entire e-mail message or discussion group post using only capital letters.
    15·1 answer
  • What is a typical grace period for a credit card...
    15·2 answers
  • In the game Beehive, you play the role of a worker bee who must watch over her hive. Your duties include (among others) directin
    12·2 answers
  • Which references are updated when you copy the formula =$E6-MAX(H$1:J4)
    10·1 answer
  • Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integer
    15·1 answer
  • Some early computers protected the operating system by placing it in a memory partition that could not be modified by either the
    5·1 answer
  • Danielle, a help desk technician, receives a call from a client. In a panic, he explains that he was using the Internet to resea
    9·1 answer
  • Complete the program below that takes in one positive, odd, integer, n (at least 3), and prints a "diamond" shape of stars with
    9·1 answer
  • Write a while loop that prints userNum divided by 2 (integer division) until reaching 1. Follow each number by a space. Example
    6·1 answer
  • TQ Artificial Intelligence (AI)
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!