init commit
This commit is contained in:
9
Question12-Encapsulation/src/ItemA.java
Normal file
9
Question12-Encapsulation/src/ItemA.java
Normal file
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
* ItemA.java
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
public class ItemA {
|
||||
private String name = "アイテムA";
|
||||
}
|
||||
26
Question12-Encapsulation/src/PTra12_01.java
Normal file
26
Question12-Encapsulation/src/PTra12_01.java
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* PTra12_01.java
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
import common.User;
|
||||
|
||||
public class PTra12_01 {
|
||||
public static void main(String[] args) {
|
||||
// ※ この問題はcommonパッケージのUserクラスを完成させてから解いてください。
|
||||
/*
|
||||
* TODO インスタンスフィールドへのアクセスをアクセサ経由に変更してください
|
||||
*/
|
||||
User user = new User();
|
||||
user.userId = 1000;
|
||||
user.userName = "リゾーム太郎";
|
||||
user.mailAddress ="rhizome@hogehoge.com";
|
||||
user.password = "12345";
|
||||
|
||||
System.out.println("ID :" + user.userId);
|
||||
System.out.println("名前 :" + user.userName);
|
||||
System.out.println("メールアドレス :" + user.mailAddress);
|
||||
System.out.println("パスワード :" + user.password);
|
||||
}
|
||||
}
|
||||
16
Question12-Encapsulation/src/PTra12_02.java
Normal file
16
Question12-Encapsulation/src/PTra12_02.java
Normal file
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* PTra12_02.java
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
|
||||
// TODO 同一パッケージのItemAクラスを変更してエラーが出ないようにしてください。
|
||||
// ※ このクラスの内容は変更しないこと
|
||||
public class PTra12_02 {
|
||||
public static void main(String[] args) {
|
||||
ItemA item = new ItemA();
|
||||
System.out.println(item.name);
|
||||
|
||||
}
|
||||
}
|
||||
18
Question12-Encapsulation/src/PTra12_03.java
Normal file
18
Question12-Encapsulation/src/PTra12_03.java
Normal file
@@ -0,0 +1,18 @@
|
||||
import common.ItemB;
|
||||
|
||||
/*
|
||||
* PTra12_03.java
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
|
||||
//TODO commonパッケージのItemBクラスを変更してエラーが出ないようにしてください。
|
||||
//※ このクラスの内容は変更しないこと
|
||||
public class PTra12_03 {
|
||||
public static void main(String[] args) {
|
||||
ItemB item2 = new ItemB();
|
||||
System.out.println(item2.name);
|
||||
|
||||
}
|
||||
}
|
||||
11
Question12-Encapsulation/src/common/ItemB.java
Normal file
11
Question12-Encapsulation/src/common/ItemB.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package common;
|
||||
|
||||
/*
|
||||
* ItemB.java
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
public class ItemB {
|
||||
String name = "アイテムB";
|
||||
}
|
||||
18
Question12-Encapsulation/src/common/User.java
Normal file
18
Question12-Encapsulation/src/common/User.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package common;
|
||||
|
||||
/*
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
public class User {
|
||||
|
||||
// TODO 各フィールドにprivateアクセス修飾子を指定してください
|
||||
int userId;
|
||||
String userName;
|
||||
String mailAddress;
|
||||
String password;
|
||||
|
||||
// TODO 各フィールドのアクセサを作成してください
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user