⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exercise6_2.java

📁 Introduction to java programming 一书中所有编程练习部分的源码
💻 JAVA
字号:
// Exercise6_2.java: Create a Fan class
// To avoid naming conflict with another Fan class later,
// this class name is Fan1
public class Exercise6_2 {
  public static void main(String[] args) {
    Fan1 fan = new Fan1();
    fan.setSpeed(Fan1.FAST);
    fan.setRadius(10);
    fan.setOn(true);
    fan.setColor("yellow");

    System.out.println(fan.toString());
  }
}

class Fan1 {
  public static int SLOW = 1;
  public static int MEDIUM = 2;
  public static int FAST = 3;

  private int speed = SLOW;
  private boolean on = false;
  private double radius = 5;
  private String color = "white";

  public Fan1() {
  }

  public int getSpeed() {
    return speed;
  }

  public void setSpeed(int speed) {
    this.speed = speed;
  }

  public boolean isOn() {
    return on;
  }

  public void setOn(boolean trueOrFalse) {
    this.on = trueOrFalse;
  }

  public double getRadius() {
    return radius;
  }

  public void setRadius(double radius) {
    this.radius = radius;
  }

  public String getColor() {
    return color;
  }

  public void setColor(String color) {
    this.color = color;
  }

  public String toString() {
    return "speed " + speed + "\n"
      + "on " + on + "\n"
      + "radius " + radius + "\n"
      + "color " + color + "\n";
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -