10:00——11:00:老师网课学习(一小时)
14:00——18:00:Java学习(四小时)
学习笔记:
1.DotComBust完整版.note
链接:http://note.youdao.com/noteshare?id=86f5d84cd07957f3c335abc65c20260c&sub=FC8B723219F74D83B186CB0017BE0370
完成了昨天的Java程序学习,对这个游戏有了更直观的理解,也修改除了这个程序存在的问题——import引导的句子应该放在代码最顶端。而且由public所引导的class类应该作为文件的名称再由javac编译,不然无法通过。
2.文档:函数库2-APL.note
链接:http://note.youdao.com/noteshare?id=f1dd295ca1345dd7ae2df822f3db6538&sub=A16EBC7395284283B4BBE3B5FA8D1C6F
具体学习了Java函数库API
20:40——21:10:背英语
今天最大的收获还是这个DotComBust。
因为前几天一直无法找到的问题今天解决了,而且第一个错误是import没有放在第一行,第二个错就是命名的问题,百度了一下,也找出来了哈哈。
import java.io.*;//这个要在第一行
class GameHelper{//加public的话会创建出另一个以GameHelper命名的class文件
public String getUserInput(String prompt){
String inputLine=null;
System.out.print(prompt+" ");
try{
BufferedReader is =new BufferedReader(new InputStreamReader(System.in));
inputLine=is.readLine();
if(inputLine.length()==0) return null;
}catch(IOException e){
System.out.println("IOException: "+ e);
}
return inputLine;
}
}
class SimpleDotCom{
int [] locationCells;
int numOfHits=0;
public void setLocationCells(int[] args){
locationCells=args;
}
public String checkyourself(String stringGuess){
int Guess=Integer.parseInt(stringGuess);
String result="miss";
for(int cell:locationCells){
if(Guess==cell) {
result="Hit";
numOfHits++;
break;
}
}
if(numOfHits==locationCells.length){
result="Kill";
}
System.out.println(result);
return result;
}
}
public class SimpleDotComGame{
public static void main(String[] args){
int numOfGuess=0;
GameHelper helper=new GameHelper();
SimpleDotCom theDotCom=new SimpleDotCom();
int randomNum=(int) (Math.random()*5);
int[] locations={randomNum,randomNum+1,randomNum+2};
theDotCom.setLocationCells(locations);
boolean isAlive=true;
while(isAlive==true){
String guess=helper.getUserInput("enter a number");
String result =theDotCom.checkyourself(guess);
numOfGuess++;
if(result.equals("Kill")){
isAlive=false;
System.out.println("You took "+numOfGuess +" guesses");
}
}
}
}