Hello programmers ^^
i 'am new here... so..
i got assignment from my lecture.
this is the first assignment.
before this my lecture teach me about how to make a cake using constructor. but i can't catch up what she said in class, so she give this assignment and i don't know how to write it.
now my class using NetBeans IDE 6.5.
Design a class named Fan to represent a fan. The class contains:
- Three constants named SLOW, MEDIUM and FAST with value 1, 2, and 3 to denote the fan speed.
- An int data field named speed that specifies the speed of the fan(default SLOW).
- A boolean data field named on that specifies whether the fan is on(default false).
- A double data field named radius that specifies the radius of the fan(default 5).
- A string data field named color that specifies the color of the fan (default blue).
- A no-argument constructor that creates a default fan.
- The accessor and mutator methods for all four data field.
- 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 fan color and radius along with the string "fan is off" in one combine string.
this is my code that im doing this, if got any wrong pls tell me.
package lab1; public class FanTest { public static void main(String args[]){ Fan fan_is_on=new Fan(1,false,5,"blue"); fan_is_on.seton$off(true); fan_is_on.setcolor("blue"); fan_is_on.setspeed(3); System.out.println("Fan is on: "); System.out.println("Speed: "+fan_is_on.getspeed()); System.out.println("switch on: "+fan_is_on.ison$off()); System.out.println("radius: "+fan_is_on.getradius()); System.out.println("color: "+fan_is_on.getcolor()); } } class Fan{ int speed=1; boolean on$off=false; double radius=5; String color="blue"; Fan(int speed, boolean on$off, double radius, String color){ this.speed=speed; this.on$off=on$off; this.radius=radius; this.color=color; } Fan(){} void setspeed(int s){ speed=s; } void seton$off(boolean open){ on$off=open;} void setradius(double r){ radius=r; } void setcolor(String c){ color=c; } int getspeed(){ return speed; } boolean ison$off(){ return on$off; } double getradius(){ return radius; } String getcolor(){ return color; } }