Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Model a real life object as a Java class with at least one attribute and an instance method. Write main method to create instance

Model a real life object as a Java class with at least one attribute and an instance method.

 

Write main method to create instance of the class, assign a value to the attribute, call your method, and demonstrate that the value of the attribute changed and that the method successfully completed what it was supposed to do.

 


//This is the code I currently have, I am a beginner and would like to know a solution since I can't seem to understand the concepts of non static variables and changing them. Any help would be appreciated, thank you!


public class PC {

//attributes to class PC (temperature, cost, on or off)

int initialtemp= 0;
int temp = 80;
int cost = 1000;
boolean ONOFF = false;

//instance
public void PCTemp(int initialtemp, boolean ONOFF, int temp) {

System.out.println("The PC is currently at: " +initialtemp);
System.out.println("Is the PC turned on?" +ONOFF);
System.out.println("The PC is currently at a retail cost of: " +cost);
}



public static void main(String[] args) {
PC instance = new PC();
instance.ONOFF= true;
instance.temp= 85;

System.out.print(ONOFF);
System.out.print(temp);
}

}

Step by Step Solution

3.28 Rating (151 Votes )

There are 3 Steps involved in it

Step: 1

public class PC Attributes of the PC instance variables private int temperature 0 Initial temperatur... 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

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Programming questions

Question

Write short notes on Interviews.

Answered: 1 week ago

Question

Define induction and what are its objectives ?

Answered: 1 week ago

Question

Discuss the techniques of job analysis.

Answered: 1 week ago