Last active
August 29, 2015 14:03
-
-
Save typosone/2d1c9b72a0e2badbaf6c to your computer and use it in GitHub Desktop.
Java講義 サンプル (Student)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Student { | |
private String firstName; | |
private String lastName; | |
private String course; | |
private String gender; | |
private double height; | |
private double weight; | |
public Student() { | |
setFirstName("ひろき"); | |
setLastName("かめはま"); | |
setCourse("未所属"); | |
setGender("その他"); | |
setHeight(140); | |
setWeight(40); | |
} | |
public Student(String firstName, String lastName, String course, | |
String gender, double height, double weight) { | |
setFirstName(firstName); | |
setLastName(lastName); | |
setCourse(course); | |
setGender(gender); | |
setHeight(height); | |
setWeight(weight); | |
} | |
public void setFirstName(String firstName) { | |
this.firstName = firstName; | |
} | |
public void setLastName(String lastName) { | |
this.lastName = lastName; | |
} | |
public void setFullName(String firstName, String lastName) { | |
setFirstName(firstName); | |
setLastName(lastName); | |
} | |
public void setCourse(String course) { | |
this.course = course; | |
} | |
public void setGender(String gender) { | |
if (gender.equals("男") || gender.equals("女")) { | |
this.gender = gender; | |
} else { | |
this.gender = "その他"; | |
} | |
} | |
public void setHeight(double height) { | |
if (height > 100) { | |
this.height = height; | |
} else { | |
this.height = 100; | |
} | |
} | |
public void setWeight(double weight) { | |
if (weight > 40) { | |
this.weight = weight; | |
} else { | |
this.weight = 40; | |
} | |
} | |
public String getFirstName() { | |
return firstName; | |
} | |
public String getLastName() { | |
return lastName; | |
} | |
public String getCourse() { | |
return course; | |
} | |
public String getGender() { | |
return gender; | |
} | |
public double getHeight() { | |
return height; | |
} | |
public double getWeight() { | |
return weight; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StudentTester { | |
public static void main(String...args) { | |
Student tsuyoshi = new Student( | |
"たろう", "やまだ", "エンジニア科システムコース", | |
"男", 168.0, 70.5); | |
System.out.println(tsuyoshi.getLastName()); | |
System.out.println(tsuyoshi.getFirstName()); | |
System.out.println(tsuyoshi.getCourse()); | |
System.out.println(tsuyoshi.getGender()); | |
System.out.println(tsuyoshi.getHeight()); | |
System.out.println(tsuyoshi.getWeight()); | |
Student student = new Student(); | |
System.out.println(student.getLastName()); | |
System.out.println(student.getFirstName()); | |
System.out.println(student.getCourse()); | |
System.out.println(student.getGender()); | |
System.out.println(student.getHeight()); | |
System.out.println(student.getWeight()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment