標題:
2022/10/07 課堂重點(若晴)
[打印本頁]
作者:
葉桔良
時間:
2022-9-29 22:26
標題:
2022/10/07 課堂重點(若晴)
本帖最後由 葉桔良 於 2022-10-7 21:26 編輯
【課程內容】
基礎物件導向概念(以人為例子)
[attach]13683[/attach]
物件導向基礎概念 (一)
建構子 (一)
物件導向基礎概念 (二)
建構子 (二)
[隨堂測驗] 建構子 (三)
【作業】
基礎物件導向概念(以電腦為例子)
複習今日上課內容
打字練習簿中文第六課
作者:
若晴
時間:
2022-10-7 20:58
public class Main {
public static void main(String[] args) {
// TODO 自動產生的方法 Stub
People ye = new People();
ye.hd=new Head(20);
ye.bd=new Body(30);
ye.rh=new Hand(40);
ye.lh=new Hand(42);
ye.rl=new Leg(453);
ye.ll=new Leg(4);
ye.showProfile();
}
}
複製代碼
public class People {
Head hd=new Head();
Body bd=new Body();
Hand rh=new Hand();
Hand lh=new Hand();
Leg rl=new Leg();
Leg ll=new Leg();
void showProfile()
{
System.out.println(hd.circum);
System.out.println(bd.capacity);
System.out.println(rh.width);
System.out.println(lh.width);
System.out.println(rl.length);
System.out.println(ll.length);
}
}
複製代碼
public class Body {
int capacity;
Body()
{
capacity=50;
}
Body(int capacity)
{
this.capacity=capacity;
}
}
複製代碼
public class Hand {
int width;
Hand()
{
width=50;
}
Hand(int width)
{
this.width=width;
}
}
複製代碼
public class Head {
int circum;
Head()
{
circum=50;
}
Head(int circum)
{
this.circum=circum;
}
}
複製代碼
public class Leg {
int length;
Leg()
{
length=50;
}
Leg(int length)
{
this.length=length;
}
}
複製代碼
作者:
若晴
時間:
2022-10-13 21:24
public class Main {
public static void main(String[] args) {
// TODO 自動產生的方法 Stub
Computer ye = new Computer();
ye.kb = new Keyboard();
ye.ms = new Mouse();
ye.sc = new Screen();
ye.cpu = new Host();
ye.ram = new Host();
ye.disk = new Host();
ye.showProfile();
}
}
複製代碼
public class Computer {
Keyboard kb = new Keyboard();
Mouse ms = new Mouse();
Host cpu = new Host();
Host ram = new Host();
Host disk = new Host();
Screen sc = new Screen();
void showProfile()
{
System.out.println(kb.keys);
System.out.println(ms.length);
System.out.println(cpu.frequency);
System.out.println(ram.speed);
System.out.println(disk.capacity);
System.out.println(sc.resolution);
}
}
複製代碼
public class Host {
int frequency, speed, capacity;
Host()
{
frequency =100;
}
}
複製代碼
public class Keyboard {
int keys;
Keyboard()
{
keys = 70;
}
Keyboard(int keys)
{
this.keys = keys;
}
}
複製代碼
public class Mouse {
int length;
Mouse()
{
length = 100;
}
Mouse(int length)
{
this.length = length;
}
}
複製代碼
public class Screen {
int resolution;
Screen()
{
resolution = 300;
}
Screen(int resolution)
{
this.resolution = resolution;
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2