[java]枚举类练习
emm...很
想法:
- 枚举类实现季节信息打印
- 一个简单的交互
- 一个很艹的剧情
上代码
enum Season
package com.wenjun.www; public enum Season { SPRING(温暖,三月),SUMMER(炎热,六月),AUTUMN(凉爽,八月),WINTER(寒冷,十二月); @SuppressWarnings(all) private String intro = ; @SuppressWarnings(all) private String month = ; Test(String intro, String mouth) { this.intro = intro; this.mouth = month; } @Override public String toString() { return this.name().toLowerCase()+ 在+month+最+intro; } }
对吧,直接重写toString()
打印完事。不要在意@SuppressWarnings(all)
[滑稽]
class mainMenu
package com.wenjun.www; import com.wenjun.www.Season; import java.util.Scanner; public class mainMenu { private boolean appear = true; private Scanner choice = new Scanner(System.in); private String seasonName = ; private Season[] seasons = Season.values(); private void seasonList(){ for (Season value : seasons) { System.out.println(value); } } public void menu(){ do { System.out.println(燕子,你喜欢哪个季节?); seasonList(); System.out.println(选一个,不行让我滚!); season_name = choice.next(); switch (seasonName){ case spring: findSeason(0); break; case summer: findSeason(1); break; case autumn: findSeason(2); break; case winter: findSeason(3); break; case 滚: System.out.println(燕子!你别走啊燕子!); System.out.println(司机:“确定要加速吗?”(y/n):); seasonName = choice.next(); if (seasonName.toUpperCase().equals(Y)){ appear = false; } break; default: System.out.println(燕子!你说句话啊燕子!); break; } }while (appear); } private void findSeason(int id){ System.out.println(seasons[id]); } }
Season[] seasons = Season.values();
直接全装进去seasonList()
增强for循环打印menu()
中switch+Scanner简单交互findSeason()
数组下标查询打印- 生草的剧情
RUN!
package com.wenjun.www; import com.wenjun.www.mainMenu; public class App { public static void main(String[] args) { new mainMenu().menu(); System.out.println(燕子!!!); } }
完事!
后记
乱写+1
exp+3