案例五:请实现如果今天是周六或周日,则准备外出。如果气温在30度以上,去游泳;否则就去爬山。如果今天不是周六或者周日,就要工作。如果天气好,去客户单位谈业务;否则在公司上网查资料。

package project_05;

import java.util.Scanner;

/**
 * 2018年9月7日22:06:42
 * @author Suaron XiaMen
 *
 */
public class Plan {
    private String day;     //属性
    private int airTemperature;
    private String weather;
    //无参构造方法
    public Plan(){}
    //有参构造方法
    public Plan(String day, int airTemperature, String weather) {
        super();
        this.day = day;
        this.airTemperature = airTemperature;
        this.weather = weather;
    }
    public String getDay() {
        return day;
    }
    public void setDay(String day) {
        this.day = day;
    }
    public int getAirTemperature() {
        return airTemperature;
    }
    public void setAirTemperature(int airTemperature) {
        this.airTemperature = airTemperature;
    }
    public String getWeather() {
        return weather;
    }
    public void setWeather(String weather) {
        this.weather = weather;
    }
    
    //构造方法
    public void playPlan(String day, int airTemperature, String weather){
        if(day.equals("星期六")||day.equals("星期日")){
            if(airTemperature>30){
                System.out.println("去游泳!");
            }else{
                System.out.println("去爬山!");
            }
        }else{
            if(weather.equals("好")){
                System.out.println("去客户单位谈业务!");
            }else{
                System.out.println("公司上网查资料!");
            }
        }
    }
    
        //方法入口
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        Plan plan=new Plan();
        System.out.print("请输入今天的星期(星期*):");
        String day=input.next();
        System.out.print("请输入今天的温度(30):");
        int airTemperature=input.nextInt();
        System.out.print("请输入今天天气的好坏(好/不好):");
        String weather=input.next();
        plan.playPlan(day, airTemperature, weather);
        input.close();
    }
}

结果如下:

 

posted @ 2018-09-07 22:38  Sauron_Three  阅读(1554)  评论(0编辑  收藏  举报