Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design a class named Fan to represent a fan. The class contains: Three constants

ID: 3825887 • Letter: D

Question

Design a class named Fan to represent a fan. The class contains: Three constants named SLOW, MEDIUM, and FAST with the values 1, 2. and 3 to denote the fun speed. A private into data field named speed that specifies the speed of the fan (the default is SLOW). A private boolean data field named on that specifies whether the fan is on (the default is false). A private double data field named radius that specifies the radius of the fan (the default is 5). A string data field named col or that specifies the color of the fan (the default is blue). The accessor and mutator methods for all four data fields. A no-are constructor that creates a default fan. A method named toString() that returns a string description for the fan. If the fan is on, the method returns the fan speed, color, and radius in one combined string. If the fan is not on. the method returns the fan color and radius along with the string "fan is off' in one combined string. Draw the UML diagram for the class and then implement the class. Write a test program that creates two Fan objects. Assign maximum speed, radius 10. color yellow. and turn it on to the first object. Assign medium speed, radius S, color blue, and turn i(off to the second object. Display the objects by invoking their toString method. (Geometry: n-sided regular polygon) In an n-sided regular polygon, all sides have the same length and all angles have the same degree (i.e., the polygon is both equilateral and equiangular). Design a class named Regu larPolygon that contains: A private int data field named n that defines the number of sides in the polygon with default value 3. A private double data field named side that stores the length of the side with default value 1. A private double data field named x that defines the x-coordinate of the polygon's center with default value 0. Use JGrasp to design and implement the following programs (from the end of Chapter 9 in the textbook) and understand what they do. Required; Use java assert statement to validate program input values when conditions applied to inputs (for int and char types). See Chapter 3 slides for code examples. Apply this requirement to both lab exercises and assignment programs. Following the instructions in the problem statement, design and implement a Java program for programming exercise 9.8, page 362 (called Fan). Next, develop a test program in a separate file (call it Teszsan) to create two Fan objects and test the class methods on these objects following the instructions stated in the problem statement. Document your code, and organize and space the outputs properly. Use escape characters and formatting objects when applicable. Design and implement a Java class (name it SunroerStats. java) that tracks statistics for summer job salaries for a group of people over several years. The only data field you need is a 2-Dimenssional array of values representing salaries. The rows the represents the people and the columns represent the years. The constructor method takes two integers representing the number of people and the number of years, then randomly generates the annual salaries and fills the array. Other class methods include the following: - A method to return the index of the person having made the most money over the years. A method to return the index of the year when the highest salary was earned. A method to return the total amount of money made by a person (specified row index). A method to return the total amount of money made by all the people over the years. A method to return the index of the person who made the highest salary in a given year (specified by

Explanation / Answer

// Fan.java
/**
* @author Jyoti
*
*/
public class Fan {

   // constants
   final static int SLOW = 1, MEDIUM = 2, FAST = 3;

   int speed;
   boolean isOn;
   double radius;
   String color;

   /**
   *
   */
   public Fan() {
       // TODO Auto-generated constructor stub
       speed = SLOW;
       isOn = false;
       radius = 5d;
       color = "blue";

   }

   /**
   * @param speed
   * @param isOn
   * @param radius
   * @param color
   */
   public Fan(int speed, boolean isOn, double radius, String color) {
       super();
       this.speed = speed;
       this.isOn = isOn;
       this.radius = radius;
       this.color = color;
   }

   /**
   * @return the speed
   */
   public int getSpeed() {
       return speed;
   }

   /**
   * @param speed
   * the speed to set
   */
   public void setSpeed(int speed) {
       this.speed = speed;
   }

   /**
   * @return the isOn
   */
   public boolean isOn() {
       return isOn;
   }

   /**
   * @param isOn
   * the isOn to set
   */
   public void setOn(boolean isOn) {
       this.isOn = isOn;
   }

   /**
   * @return the radius
   */
   public double getRadius() {
       return radius;
   }

   /**
   * @param radius
   * the radius to set
   */
   public void setRadius(double radius) {
       this.radius = radius;
   }

   /**
   * @return the color
   */
   public String getColor() {
       return color;
   }

   /**
   * @param color
   * the color to set
   */
   public void setColor(String color) {
       this.color = color;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       if (isOn) {
           return "speed=" + speed + ", radius=" + radius + ", color=" + color
                   + "";
       } else {
           return "speed=" + speed + ", radius=" + radius + ", color=" + color
                   + " fan is off";

       }
   }

}

// TestFan.java
/**
* @author jyoti
*
*/
public class TestFan {

   /**
   * @param args
   */
   public static void main(String[] args) {

       //using default constructor
       Fan fan1 = new Fan();
       System.out.println("Default Fan1:" + fan1.toString());

       //using parameterised constructor
       Fan fan2 = new Fan(Fan.FAST, true, 7d, "Green");
       System.out.println("Prameterised Fan2:" + fan2.toString());

   }
}

OUTPUT:

Default Fan1:speed=1, radius=5.0, color=blue fan is off
Prameterised Fan2:speed=3, radius=7.0, color=Green

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote