Q1: Write a Java class called Machine which has: 2 instance variables brandName and power (to check if it is On or not) 2 constructors (a multi-argument constructor and a zero-argument one) getters for the two instance variables a setter for brandName 2 methods switchOn() and switchOff() which change the value of power a method called display () to print the status of the machine Q2: Write a Java class called TestMachines which has a main method to test your code as follows: create a Machine object to be initialized to "Dell" brand and to be Off. create another Machine object using the zero-arg constructor. Then change its brand to "Sharp" and switch it on. • print the status of the 2 machines. declare and create an array that can hold up to 3 machines fill the array with suitable data print how many machines of brand "Dell" declare and create an ArrayList of machines fill the list with suitable data
Q1: Write a Java class called Machine which has:
2 instance variables brandName and power (to check if it is On or not)
2 constructors (a multi-argument constructor and a zero-argument one)
getters for the two instance variables
a setter for brandName
2 methods switchOn() and switchOff() which change the value of power
a method called display() to print the status of the machine
Q2: Write a Java class called TestMachines which has a main method to test your
code as follows:
create a Machine object to be initialized to "Dell" brand and to be Off.
create another Machine object using the zero-arg constructor. Then change its
brand to "Sharp" and switch it on.
print the status of the 2 machines.
declare and create an array that can hold up to 3 machines
fill the array with suitable data
print how many machines of brand "Dell"
declare and create an ArrayList of machines
fill the list with suitable data
print how many machines are On.
Step by step
Solved in 4 steps with 2 images