write a java class definition as per the requirements given below: assume that t
ID: 3564773 • Letter: W
Question
write a java class definition as per the requirements given below: assume that the Company class is already defined. this class has instance variables name and year and a constructor which accepts a string variable and an int variable as arguments. write the class defintion for a class named Fan as described below. Fan has the following instance variables. *an int variable called speed that specifies the speed of the fan (default1) * a boolean variable named on that specifies whether or not the fan is on (default false) * a string variable called color (default blue) * a double variable called radius(default 5.0) *a Company varaible called manufacturere (default CromptonGreaves and 1976) Fan has a no-arg constructor Set the values of all instance variables to their default values. For the company instance variable you must first create a Company object by calling the corresponding constructor with the default values.
Explanation / Answer
========================================================
File : Company.java
// Only getters included because values are set through constructor
========================================================
public class Company {
private String name;
private int year;
public Company(String name, int year) {
this.name = name;
this.year = year;
}
public String getName() {
return name;
}
public int getYear() {
return year;
}
}
========================================================
File : Fan.java
// Both getters and setters included
========================================================
public class Fan {
private int speed;
private boolean isOn;
private double radius;
private Company manufacturer;
public Fan(){
this.speed = 1;
this.isOn = false;
this.radius = 5.0;
this.manufacturer = new Company("CromptonGreaves", 1976);
}
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}
public boolean isOn() {
return isOn;
}
public void setOn(boolean isOn) {
this.isOn = isOn;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
public Company getManufacturer() {
return manufacturer;
}
public void setManufacturer(Company manufacturer) {
this.manufacturer = manufacturer;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.