Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/** * A class for testing static variable usage and method overloading. You should complete * the following: * * - Implement two constructors, one

/**

* A class for testing static variable usage and method overloading. You should complete

* the following:

*

* - Implement two constructors, one that takes in a string and a default constructor.

* Both should count how many objects have been created

* - Implement two versions of myMethod, which increments the method counter as

* specified below

* - Implement accessors for all private variables

*/

public class StaticVariableClass

{

private static int constructor_counter = 0;

private static int method_counter = 0;

private String name;

// Create a constructor with no parameters that sets the name to "default"

// and increases the counter of how many objects of this type have been

// created

//-----------Start below here. To do: approximate lines of code = 3

//

//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.

// Create a constructor that stores the name and increases the counter of

// how many objects of this type have been created.

//-----------Start below here. To do: approximate lines of code = 3

//

//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.

public void myMethod()

{

// Increment the method counter

//-----------Start below here. To do: approximate lines of code = 1

//

//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.

}

public void myMethod(int toCount)

{

// Increase the method counter by the toCount value

//-----------Start below here. To do: approximate lines of code = 1

//

//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.

}

// Create a static accessor for the constructor counter

//-----------Start below here. To do: approximate lines of code = 2

//

//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.

// Create a static accessor for the method counter

//-----------Start below here. To do: approximate lines of code = 2

//

//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.

// Create an accessor for the name

//-----------Start below here. To do: approximate lines of code = 2

//

//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.

}

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

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions

Question

1. Who is responsible for resolving this dilemma?

Answered: 1 week ago

Question

7. How might you go about testing these assumptions?

Answered: 1 week ago