Java之前在学习过,基础知识还没有忘光,并且这些高级语言实在是太像,所以那些数据类型,或者循环控制流,以及标准设备等等就直接略过不说了.
只是一些重大概念会穿插在文章的介绍中.
So,这些文章适合于那些有一定高级面向对象语言基础的人阅读.
我们首先编写一个学生类.其主要要求要熟悉的内容是:
关于类构造器(构造方法)的认识和理解.
关于方法的编写.
关于成员变量 & this 的使用,
熟悉了这些内容后,我们就能够依照以下的类图编写这个类了.
构造器的參数有姓名,性别,学号.
类图例如以下:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc3Vvb2w=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">
我写的參考的代码例如以下:
我把全部的属性都写成了private类型的,由于这些数据都可写一套set和get方法.....
/**
* Description:
* <br> Blog:<a href = "http://suool.net" target="blnak"> Suool's Blog </a>
* <br> Copyright (c), 2014-2015, SuooL
* <br> This program is writeen by Crazy Java.
* <br> Program name: student.java
* @author: SuooL
* @version: 1.0.0
*/
public class student
{
/// 私有变量
private String Stu_name;
private String Stu_sex ;
private long Stu_Id ;
private int Stu_age; /**
* Student 的构造方法
* @param name 构造的学生实例姓名
* @param sex 构造的学生实例性别
* @param Id 构造的学生实例学号,开头数字不为零
*/
public student(String name, String sex, long Id)
{
this.Stu_name = name;
this.Stu_sex = sex ;
this.Stu_Id = Id ;
}
/**
* 设置年龄的方法
* @param age 要设置的学生的年龄
*/
public void setAge(int age)
{
this.Stu_age = age;
System.out.println("You set the age of the student " + this.Stu_name + " is " + this.Stu_age);
}
/**
* 获取指定学生的学号
* @return 返回长整型学号值
*/
public long getID()
{
System.out.println("You get the ID of the student " + this.Stu_name + "is" + this.Stu_age);
return this.Stu_Id;
} /**
* 主方法
* @param args 命令行參数
*/
public static void main(String[] args)
{
// 构造学生对象
student Tom = new student("Tom", "Boy", 122511042);
student Jelly = new student("Jelly", "Girl", 122511043);
Tom.setAge(20);
System.out.println(Tom.getID());
}
}
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc3Vvb2w=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">
生成的JavaDoc例如以下.
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc3Vvb2w=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">
Next,下一节写一个小游戏,命令行版的无AI的五子棋.
事实上就是对数组和标准输入输出的练习吧.
“If you don't make the time to work on creating the life you want, you're eventually going
to be forced to spend a LOT of time dealing with a life you don't want.” --Kevin Ngo