Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a class called Methods that has a single instance variable private int x, then write the following six methods in the class: A static

Create a class called Methods that has a single instance variable private int x, then write the following six methods in the class:

A static method called hello() that takes no parameters, returns no value, and prints Hello, world!

An instance (non-static) method called print() that takes no parameters, returns no value, and prints the current value of the x instance variable like this: x is: x

A setter method for the x instance variable, whose parameter name is also x; remember the naming convention for setter methods and their return type! The setter method must guarantee that x is never set to a value less than 0. If the setter argument is negative, leave x unchanged.

A Methods constructor that takes one int parameter called x and calls the setter method to set the value of the x instance variable

A getter method for the x instance variable; remember the parameter and return types for getter methods!

A static void method called print(), whose single parameter is a Methods object, that prints the value of its parameters x instance variable this is method overloading. This method can use either the objects print() or its getter method to do this.

IN JAVA:

public class Methods

{

private int x; // instance variable

/* write the static hello method here */

/* write the instance method print here */

/* write the setter method for x here; do

not set x to a value less than 0 - if

the input parameter is less than 0,

leave x unchanged */

/* write the single Methods constructor here;

use the setter method to set the value of x */

/* write the standard getter method for x here */

/* write the static print method here; use its

input parameter's print method to print the

value of that object's x instance variable */

public static void main(String[] args) // not required for Week 8 Thursday Lab

{

/* DO NOT MODIFY THIS MAIN METHOD */

Methods m = new Methods(42);

hello();

m.print();

m.setX(34);

System.out.println("m.getX: " + m.getX());

print(m);

}

}

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

Database Design Application Development And Administration

Authors: Michael V. Mannino

3rd Edition

0071107010, 978-0071107013

More Books

Students also viewed these Databases questions

Question

What are Measures in OLAP Cubes?

Answered: 1 week ago

Question

How do OLAP Databases provide for Drilling Down into data?

Answered: 1 week ago

Question

How are OLAP Cubes different from Production Relational Databases?

Answered: 1 week ago