Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7b3c6d6

Browse files
committed
Java第六天
1 parentc8c8a7c commit7b3c6d6

File tree

44 files changed

+1045
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1045
-0
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
�������
2+
��������ǻ���������̵ı��˼��
3+
4+
������̣��Լ�һ��������ɲ�����ǿ�����ǹ��̡�
5+
������󣺵��ñ��˵IJ�����ǿ�����ǽ����
6+
7+
��������˼���ص㣺
8+
A:��һ�ָ���������˼��ϰ�ߵ�˼��
9+
B:���Խ����ӵ�����򵥻�
10+
C:�����Ǵ�ִ���߱����ָ����
11+
��ɫ������ת��
12+
13+
������
14+
A:ϴ�·�
15+
������̣������ӽ�ˮ,��ϴ�·�-->���·��ӽ�ȥ����-->��������·�-->Ưϴ�·�-->š��-->���¼�������
16+
������󣺰��·��ӵ�ϴ�»�����ϴ�·�,������������-->���¼�������
17+
18+
B:�Է�
19+
������̣�ȥ�������,����-->ϴ��,ϴ��-->�в�,����-->����-->�˲�,ʢ��-->����
20+
�������ȥ����-->���÷���Ա�ļDz˹���-->���ó�ʦ�ij��˹���-->���÷���Ա�Ķ˲˹���-->����-->����
21+
22+
������һ���������������Щ���顣
23+
24+
C:�����
25+
������̣���������-->������-->��������Գ�-->���ұȽ�-->ѡ���Լ�ϲ���IJ��ּۻ���-->�ؼ�
26+
������󣺲�������-->����-->��������
27+
28+
��������
29+
���󣺰Ѵ���װ������
30+
���裺
31+
A:�򿪱�����
32+
B:��������
33+
C:�رձ�����
34+
35+
A:�������
36+
a:�򿪱�����
37+
b:��������
38+
c:�رձ�����
39+
40+
���룺
41+
42+
class Demo {
43+
public static void main(String[] args) {
44+
//System.out.println("�򿪱�����");
45+
//System.out.println("��������");
46+
//System.out.println("�رձ�����");
47+
48+
//���ܴ򿪱����ŵIJ�����Ҫ�����
49+
//���ң��򿪱�����������ܵĴ���Ƚ϶�
50+
//���ʱ����ʵ����Ӧ���÷����Ľ�
51+
//���ù���
52+
open();
53+
in();
54+
close();
55+
56+
//open();
57+
//open();
58+
}
59+
60+
public static void open() {
61+
System.out.println("�򿪱�����");
62+
}
63+
64+
public static void in(){
65+
System.out.println("��������");
66+
}
67+
68+
public static void close() {
69+
System.out.println("�رձ�����");
70+
}
71+
}
72+
73+
B:�������
74+
Ҫ�������������������ҵ����仰��
75+
a:�������������
76+
UML(ͳһ��ģ����) ������ȡ��
77+
b:����ÿ��������Щ����
78+
c:����������Ĺ�ϵ
79+
80+
�������ǵ����⣺
81+
�Ѵ���װ������
82+
83+
a:�������������
84+
����
85+
����
86+
������(��main�������Ǹ���)
87+
b:����ÿ��������Щ����
88+
����:��ȥ
89+
����:��,�ر�
90+
������:main
91+
c:����������Ĺ�ϵ
92+
�ڲ������е��ñ�����ʹ�����Ĺ���
93+
94+
���룺
95+
class ���� {
96+
public static void in(){
97+
System.out.println("��������");
98+
}
99+
}
100+
101+
class ���� {
102+
public static void open() {
103+
System.out.println("�򿪱�����");
104+
}
105+
106+
public static void close() {
107+
System.out.println("�رձ�����");
108+
}
109+
}
110+
111+
class ������ {
112+
public static void main(String[] args) {
113+
�����open();
114+
�����in();
115+
�����close();
116+
}
117+
}
118+
119+
ѧ���������
120+
�Ժ����������һ�������ʱ���������Ƿ��ж��������������ܣ��У����Ǿ�ֱ��ʹ�ü��ɡ�
121+
���û�У����Ǿ��Լ�����һ���࣬��ɹ��ܣ����������Ը������á�
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
����ѧϰ������ԣ���Ϊ�˰���ʵ�������������������ʵ����Ϣ��������
2+
3+
����Ҫ��ͨ����������������������Ҫ֪������������α���ģ�
4+
���
5+
�����������������Ϣ(��������)
6+
��Ϊ�������ܹ���ʲô(������Ϊ)
7+
8+
����ѧϰ����java���ԣ���java����������ĵ�λ���ࡣ
9+
���ԣ�����Ҫ������ͨ���������֡�
10+
���
11+
�����������������Ϣ(��������)
12+
��Ϊ�������ܹ���ʲô(������Ϊ)
13+
14+
�ࣺ
15+
��Ա�����������������Ϣ(��������)
16+
��Ա�����������ܹ���ʲô(������Ϊ)
17+
18+
�ࣺ��һ����ص����Ժ���Ϊ�ļ���
19+
�����Ǹ�������ľ�������
20+
21+
������
22+
ѧ������
23+
�����Ƕ���
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
第一步:分析事物
3+
手机事物:
4+
属性:品牌,价格,颜色
5+
行为:打电话,发短信
6+
7+
第二步:把事物转换为类
8+
手机类:
9+
成员变量:品牌,价格,颜色
10+
成员方法:打电话,发短信
11+
12+
第三步:把类用英文体现
13+
Phone:
14+
成员变量:brand,price,color
15+
成员方法:call(String name),sendMessage()
16+
17+
第四步:写代码体现
18+
成员变量:其实就是一个变量,只不过定义在类中方法外,并且也可以不给初始化值。
19+
成员方法:其实就是一个方法,只不过不需要static了。
20+
*/
21+
//这是我的手机类
22+
classPhone {
23+
//品牌
24+
Stringbrand;
25+
//价格
26+
intprice;
27+
//颜色
28+
Stringcolor;
29+
30+
//打电话的方法
31+
publicvoidcall(Stringname) {
32+
System.out.println("给"+name+"打电话");
33+
}
34+
35+
//发短信的方法
36+
publicvoidsendMessage() {
37+
System.out.println("群发短信");
38+
}
39+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
第一步:分析事物
3+
学生事物:
4+
属性:学号,姓名,年龄
5+
行为:学习,吃饭,睡觉
6+
7+
第二步:把事物转换为类
8+
学生类:
9+
成员变量:学号,姓名,年龄
10+
成员方法:学习,吃饭,睡觉
11+
12+
第三步:把类用英文体现
13+
Student:
14+
成员变量:sid,name,age
15+
成员方法:study(),eat(),sleep()
16+
17+
第四步:写代码体现
18+
成员变量:其实就是一个变量,只不过定义在类中方法外,并且也可以不给初始化值。
19+
成员方法:其实就是一个方法,只不过不需要static了。
20+
21+
练习:
22+
手机
23+
*/
24+
//这是我的学生类
25+
classStudent {
26+
//成员变量
27+
//学号
28+
Stringsid;
29+
//姓名
30+
Stringname;
31+
//年龄
32+
intage;
33+
34+
//成员方法
35+
//学习的方法
36+
publicvoidstudy() {
37+
System.out.println("学生爱学习");
38+
}
39+
40+
//吃饭的方法
41+
publicvoideat() {
42+
System.out.println("学生要吃饭");
43+
}
44+
45+
//睡觉的方法
46+
publicvoidsleep() {
47+
System.out.println("学生想睡觉");
48+
}
49+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
一个.java文件中可以有多个类吗?
3+
可以。
4+
5+
如果类用public修饰后,它应该修饰哪个类呢?
6+
修饰带main方法的。并且一个类中只应该有一个类被public修饰
7+
目前不写public修饰的。
8+
9+
如何在测试类中使用一个类呢?
10+
创建对象使用类的成员
11+
如何创建对象呢?
12+
格式:
13+
类名 对象名 = new 类名();
14+
如何使用类的成员呢?
15+
成员变量:对象.变量名;
16+
成员方法:对象.方法名(...);
17+
18+
注意:
19+
引用类型的默认值是null。
20+
*/
21+
classStudent {
22+
//学号
23+
Stringsid;
24+
//姓名
25+
Stringname;
26+
//年龄
27+
intage;
28+
29+
//学习的方法
30+
//学习的方法
31+
publicvoidstudy() {
32+
System.out.println("学生爱学习");
33+
}
34+
35+
//吃饭的方法
36+
publicvoideat() {
37+
System.out.println("学生要吃饭");
38+
}
39+
40+
//睡觉的方法
41+
publicvoidsleep() {
42+
System.out.println("学生想睡觉");
43+
}
44+
}
45+
46+
classStudentDemo {
47+
publicstaticvoidmain(String[]args) {
48+
//创建学生对象
49+
Students =newStudent();
50+
51+
//输出对象名
52+
System.out.println(s);//Student@1afb7ac7
53+
54+
//输出成员变量
55+
System.out.println("学号是:"+s.sid);//null
56+
System.out.println("姓名是:"+s.name);//null
57+
System.out.println("年龄是:"+s.age);//0
58+
System.out.println("--------------");
59+
60+
//给成员变量赋值
61+
s.sid ="itcast001";
62+
s.name ="林青霞";
63+
s.age =28;
64+
65+
//再次输出成员变量
66+
System.out.println("学号是:"+s.sid);//itcast001
67+
System.out.println("姓名是:"+s.name);//林青霞
68+
System.out.println("年龄是:"+s.age);//28
69+
System.out.println("--------------");
70+
71+
//使用成员方法
72+
s.study();
73+
s.eat();
74+
s.sleep();
75+
}
76+
}
720 Bytes
Binary file not shown.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
手机类
3+
成员变量:品牌,价格,颜色
4+
成员方法:打电话,发短信
5+
*/
6+
classPhone {
7+
//品牌
8+
Stringbrand;
9+
//价格
10+
intprice;
11+
//颜色
12+
Stringcolor;
13+
14+
//打电话的方法
15+
publicvoidcall(Stringname) {
16+
System.out.println("给"+name+"打电话");
17+
}
18+
19+
//发短信
20+
publicvoidsendMessage() {
21+
System.out.println("群发短信");
22+
}
23+
}
Binary file not shown.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
classPhoneDemo {
2+
publicstaticvoidmain(String[]args) {
3+
//创建对象
4+
Phonep =newPhone();
5+
6+
//使用成员变量
7+
System.out.println("品牌是:"+p.brand);
8+
System.out.println("价格是:"+p.price);
9+
System.out.println("颜色是:"+p.color);
10+
System.out.println("----------------");
11+
12+
//给成员变量赋值
13+
p.brand ="三星";
14+
p.price =2999;
15+
p.color ="蓝色";
16+
17+
//再次使用成员变量
18+
System.out.println("品牌是:"+p.brand);
19+
System.out.println("价格是:"+p.price);
20+
System.out.println("颜色是:"+p.color);
21+
System.out.println("----------------");
22+
23+
//调用成员方法
24+
//String name = "林青霞";
25+
//p.call(name);
26+
p.call("林青霞");
27+
p.sendMessage();
28+
}
29+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
classStudent {
2+
//学号
3+
Stringsid;
4+
//姓名
5+
Stringname;
6+
//年龄
7+
intage;
8+
9+
//学习的方法
10+
//学习的方法
11+
publicvoidstudy() {
12+
System.out.println("学生爱学习");
13+
}
14+
15+
//吃饭的方法
16+
publicvoideat() {
17+
System.out.println("学生要吃饭");
18+
}
19+
20+
//睡觉的方法
21+
publicvoidsleep() {
22+
System.out.println("学生想睡觉");
23+
}
24+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp