到底为了什么呢?
大概是10多年前吧,工作不顺心,想多找条出路,也因为爱好,选择了学习编程。后来因为结了婚,也算是抛锚了,不适合再去闯荡就收了这个心思。
现在年纪又大了不少,却又想把它拾起来。原因主要有三点,一是工作中自己的定位模糊了;二是想赚钱;三是喜欢编程。会不会再一次放弃?不好说,希望自己能持续精进,快乐编程。
那么就在这里把自己的学习记录下来吧!
用实践来学习
网上找了免费课程,1.5倍速,复习倒是很快。不过学编程是少不了实践的,就模拟写一个农场游戏的部分功能玩玩吧。
//主类,负责调用其他类,如等农民类和作物类
public class farmgame {
public static void main(String[] args) {
plants plts = new plants("Tomato",0,2.5F);
System.out.println(plts.name);
farmer fmr = new farmer();
fmr.Seed(plts);
fmr.TakeCare(plts);
fmr.TakeCare(plts);
fmr.Harvest(plts);
fmr.Sell(plts);
}
}
//农民类,负责执行种植、照顾、收获、贩卖等动作
public class farmer {
public void Seed(plants plts){
System.out.println("Seed the : " + plts.name);
plts.status = 1;
}
public void TakeCare(plants plts){
plts.status += 1;
}
public void Harvest(plants plts){
if (plts.status >= 3) {
System.out.println("Harvest the plants:" + plts.name);
plts.status = 0;
}
else
System.out.println("Cann't harvest the " + plts.name);
}
public void Sell(plants plts) {
System.out.print("Sell the : " + plts.name + " for " + plts.prices + " yuan.");
}
}
//作物类,负责作物的创建、生长变化、
public class plants {
String name;
int status;
float prices;
public plants(String str,int stus,float abc) {
name = str;
status = stus;
prices = abc;
}
public void CreatStatus(int stus) {
status = status +stus;
}
}