Model a real life object as a Java class with at least one attribute and an instance
Question:
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);
}
}
Modern Database Management
ISBN: 978-0133544619
12th edition
Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi