Question: This is for Intermediate Java Programming. The code down below is from module 1 import java.util.Scanner; public class Main { public static void main(String[] args)

This is for Intermediate Java Programming. The code down below is from module 1

import java.util.Scanner;

public class Main {

public static void main(String[] args) { Fan fan1 = new Fan(); // Creates the fan class

System.out.println(fan1.toString()); fan1.setFanWorking(false); System.out.println("Fans state changed to " + fan1.isFanWorking()); System.out.println();

Fan fan2 = new Fan( 3, true, 9, "black"); // ANOTHER FAN CLASS WITH PARAMETERS System.out.println(fan2.toString()); fan2.setRadius(5); System.out.println("Radius changed to " + fan2.getRadius()); }

}

class Fan { // creates the fan class

final int STOPPED = 0; // creates the variables

final int SLOW = 1;

final int MEDIUM = 2;

final int FAST = 3;

private int speed; // creates private variables

private boolean fanWorking;

private int radius;

String color;

public Fan() { // creates the constructor to set the default values

speed = STOPPED; // sets the values given in the question

fanWorking = false;

radius = 6;

color = "white";

} public Fan(int speed, boolean fanWorking, int radius, String color) {

this.speed = speed; // sets the values to the given values

this.fanWorking = fanWorking;

this.radius = radius;

this.color = color;

}

public int getSpeed() {

return this.speed;

}

public void setSpeed(int speed) {

this.speed = speed;

}

public boolean isFanWorking() {

return this.fanWorking;

}

public void setFanWorking(boolean fanWorking) {

this.fanWorking = fanWorking;

}

public int getRadius() {

return this.radius;

}

public void setRadius(int radius) {

this.radius = radius;

}

public String getColor() {

return this.color;

}

public void setColor(String color) {

this.color = color;

}

public String toString() { // creates the toString method

return "STOPPED = " + STOPPED + " SLOW = " + SLOW + " MEDIUM = " + MEDIUM + " FAST = " + FAST

+ " Speed = " + speed + " Fan Working = " + fanWorking + " Radius = " + radius + " Color = "

+ color;

}

}

Starting with your code from Module 1 create the following new class titled UseFans:

1. Create a collection of Fan instances

2. Create a method taking a collection of Fan instances for displaying without using the toString() method

3. Create a method that takes a single instance of a Fan for displaying without using the toString() method

4. Use the this reference throughout the Fan class where allowed

5. Write test code that creates a collection of Fans and displays the functionality of all of the Fan instances in the collection

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!