随笔分类 - Java 基础(cs106A)
stanford
摘要:/* * File: Breakout.java * * Name: * Section Leader: * * This file will eventually implement the game of Breakout. */ import acm.graphics.*; import ac
阅读全文
摘要:04 switch(e): { case1: case2: statement1; break; default: statment2; } 05 自顶向下 分解: 将大型任务分解成简单的子任务. (分解任务, 不是分解代码) [分解过程中还要注意抽象出公共组件被公共利用 06 随机数种子, jav
阅读全文
摘要:/** * The student class is basic class. * @author Leon * */ public class Student { /** * @param name The student's name * @param id student's id */ pu
阅读全文
摘要:1. 根据现有的函数画 5 环. import acm.graphics.*; import acm.program.*; import java.awt.*; public class OlympicRings extends GraphicsProgram { public void run()
阅读全文
摘要:留下两个例子作为参考,1. 追逐小方块的例子2. HashMap 和 Iterator 的例子Example one:import acm.graphics.*;import acm.program.*;import java.awt.*;import java.awt.event.*;public...
阅读全文
摘要:/* video 18 */score[0][0] -> int 类型 比如 score[0] 表示第 0 行, -> int[] 这样,传递参数时,可以传递一行 ++ 这里的++是指下一行 score.length -> 行的长度 ( 包含多少个子数组 ) , 每一行都是单个数组 ...
阅读全文
摘要:/* video 12 */Enumeration 枚举 ( 想象成组合在一起的项 )public static final int ONE = 1; // java 一般用以前的方式,就是这种,而不是新的枚举类型 switch (num) { case ONE: println("one...
阅读全文
摘要:完整类 实例Student class/** * The Student class keeps track of the following pieces of data * about a student: the student's name, ID number, the number of * credits the student has earned toward graduation, and whether * the student is paid up with respect to university bills. * All of this informat
阅读全文
摘要:/* video 08 */实现类的编程人员 : 尽可能的对(使用者)隐藏实现的细节,只发布(使用者)最需要的信息。 使用类的编程人员 : 不需要知道有关类如何运行的细节。定义类时 : 常量定义在上边 方法 实例变量随机数生成方法:(伪随机) 首先有一个数字,一般和你机器上的时间有关,然后根据着个数字生成了一个数字,假设生成的是5,然后根据5继续生成一个数字。 setSeed(1), 其中,setSeed方法是让生成数字的序列完全一致,即虽然还是随机生成,但是,第一次运行程序和第二次运行程序生成的随机“序列”完全一致。 setSeed 也就是设置了第一个数字,第一个数字一样,那么生成序列就一样
阅读全文
摘要:// video 01 在 Java prepare 中当出现类型转换时,尽量使用显示类型转换 int x ; double y = (double) x;尽量避免重复代码在循环中尽量不要出现过多的 break, 因为出现过多的 break 就表示有很多种情况可以跳出循环// 要知道循环次数 for (init; test; step) { statements }// 不知道循环次数的情况 init while (test) { statements step } 以上两种循环等价method 就是为了分割顺序编程的 method 的目的就...
阅读全文
摘要:1. 分解 关于如何分解 ? 分解是将问题分解,要具有逻辑性,而不是将程序分解。 - 分解后的函数只做 1 件事,具有普遍性,这样就可以反复利用 - 函数包含 1 ~ 15 行 - 给函数起一个好名字, 一目了然知道函数的意义 ( 能给方法起 一个简单的好的名字,并且方法也是做该名字对应的事情,是很
阅读全文