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(); } }
結果以下: