init
This commit is contained in:
36
Question20-InstanceBasicOperation/src/Dog.java
Normal file
36
Question20-InstanceBasicOperation/src/Dog.java
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
public class Dog {
|
||||
private String name;
|
||||
private int age;
|
||||
private Toys toys;
|
||||
|
||||
public Dog(String name, int age, Toys toys) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
this.toys = toys;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public Toys getToys() {
|
||||
return toys;
|
||||
}
|
||||
|
||||
public void setToys(Toys toys) {
|
||||
this.toys = toys;
|
||||
}
|
||||
}
|
||||
20
Question20-InstanceBasicOperation/src/PTra20_01.java
Normal file
20
Question20-InstanceBasicOperation/src/PTra20_01.java
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* PTra20_01.java
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
public class PTra20_01 {
|
||||
public static void main(String[] args) {
|
||||
String str = "Hello";
|
||||
String str2 = new String("Hello");
|
||||
String str3 = str2;
|
||||
|
||||
// TODO strとstr2を比較して、trueと表示させてください。
|
||||
|
||||
// TODO str2とstr3を比較して、trueと表示させてください。
|
||||
|
||||
// TODO strとstr3を比較して、trueと表示させてください。
|
||||
|
||||
}
|
||||
}
|
||||
14
Question20-InstanceBasicOperation/src/PTra20_02.java
Normal file
14
Question20-InstanceBasicOperation/src/PTra20_02.java
Normal file
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* PTra20_02.java
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
public class PTra20_02 {
|
||||
public static void main(String[] args) {
|
||||
User user = new User("田中太郎", "tanaka@hoge.com","password01");
|
||||
User user2 = new User("田中太郎", "tanaka@hoge.com","password01");
|
||||
// TODO trueと表示されるように、Userクラスに追記してください ※このクラスは修正しないでください
|
||||
System.out.println(user.equals(user2));
|
||||
}
|
||||
}
|
||||
20
Question20-InstanceBasicOperation/src/PTra20_03.java
Normal file
20
Question20-InstanceBasicOperation/src/PTra20_03.java
Normal file
@@ -0,0 +1,20 @@
|
||||
import java.util.Arrays;
|
||||
|
||||
/*
|
||||
* PTra20_03.java
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
public class PTra20_03 {
|
||||
public static void main(String[] args) {
|
||||
Dog dog = new Dog("太郎", 10, new Toys(Arrays.asList("ボール","フリスビー","骨")));
|
||||
// このクラスは修正しないでください
|
||||
// TODO コンパイルエラーが発生しないように修正してください。※Objectクラスのcloneメソッドを使用してください
|
||||
Dog dog1 = dog.clone();
|
||||
// falseと表示される
|
||||
System.out.println(dog == dog1);
|
||||
// TODO falseと表示されるようにDogクラス、Toyクラスを修正してください。※Objectクラスのcloneメソッドを使用してください
|
||||
System.out.println(dog.getToys().equals(dog1.getToys()));
|
||||
}
|
||||
}
|
||||
14
Question20-InstanceBasicOperation/src/Toys.java
Normal file
14
Question20-InstanceBasicOperation/src/Toys.java
Normal file
@@ -0,0 +1,14 @@
|
||||
import java.util.List;
|
||||
|
||||
public class Toys {
|
||||
private List<String> toysList;
|
||||
public Toys(List<String> toysList) {
|
||||
this.toysList = toysList;
|
||||
}
|
||||
public List<String> getToysList() {
|
||||
return toysList;
|
||||
}
|
||||
public void setToysList(List<String> toysList) {
|
||||
this.toysList = toysList;
|
||||
}
|
||||
}
|
||||
36
Question20-InstanceBasicOperation/src/User.java
Normal file
36
Question20-InstanceBasicOperation/src/User.java
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
public class User {
|
||||
private String name;
|
||||
private String mail;
|
||||
private String pass;
|
||||
|
||||
public User(String name, String mail, String pass) {
|
||||
this.name = name;
|
||||
this.mail = mail;
|
||||
this.pass = pass;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getMail() {
|
||||
return mail;
|
||||
}
|
||||
|
||||
public void setMail(String mail) {
|
||||
this.mail = mail;
|
||||
}
|
||||
|
||||
public String getPass() {
|
||||
return pass;
|
||||
}
|
||||
|
||||
public void setPass(String pass) {
|
||||
this.pass = pass;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user