2日目段階2~4です
This commit is contained in:
@@ -3,12 +3,24 @@ public class BasicCheck2 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
Student student = new Student ();
|
||||
Student student1 = new Student(1, "鈴木一郎");
|
||||
|
||||
student.studentId = 1;
|
||||
student.name = "鈴木一郎";
|
||||
// student1.studentId = 1;
|
||||
// student1.name = "鈴木一郎";
|
||||
student1.printProfile();
|
||||
|
||||
Student student2 = new Student(2, "田中花子");
|
||||
|
||||
student2.printProfile();
|
||||
|
||||
Student student3 = new Student(3, "佐藤次郎");
|
||||
|
||||
student3.printProfile();
|
||||
|
||||
Student.getStudentCount();{
|
||||
System.out.println("現在の生徒数:" + Student.studentCount + "人");
|
||||
}
|
||||
|
||||
student.printProfile();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,34 +6,46 @@ public class BasicCheck3 {
|
||||
|
||||
Item[] items = new Item[3];
|
||||
|
||||
Item item0 = new Item();
|
||||
Item item1 = new Item();
|
||||
|
||||
item1.name = "ノート";
|
||||
item1.price = 120;
|
||||
item1.stock = 50;
|
||||
|
||||
Item item2 = new Item();
|
||||
|
||||
item2.name = "消しゴム";
|
||||
item2.price = 80;
|
||||
item2.stock = 30;
|
||||
items[0] = item0;
|
||||
items[1] = item1;
|
||||
items[2] = item2;
|
||||
|
||||
Item item3 = new Item();
|
||||
item0.setName("ノート");
|
||||
item0.setPrice(120);
|
||||
item0.setStock(50);
|
||||
|
||||
item3.name = "鉛筆";
|
||||
item3.price = 60;
|
||||
item3.stock = 100;
|
||||
item1.setName("消しゴム");
|
||||
item1.setPrice(80);
|
||||
item1.setStock(30);
|
||||
|
||||
items[0] = item1;
|
||||
items[1] = item2;
|
||||
items[2] = item3;
|
||||
item2.setName("鉛筆");
|
||||
item2.setPrice(60);
|
||||
item2.setStock(100);
|
||||
// item1.setName = "ノート";
|
||||
// item1.price = 120;
|
||||
// item1.stock = 50;
|
||||
//
|
||||
// Item item2 = new Item();
|
||||
//
|
||||
// item2.name = "消しゴム";
|
||||
// item2.price = 80;
|
||||
// item2.stock = 30;
|
||||
//
|
||||
// Item item3 = new Item();
|
||||
//
|
||||
// item3.name = "鉛筆";
|
||||
// item3.price = 60;
|
||||
// item3.stock = 100;
|
||||
|
||||
for(int i = 0; i < items.length; i++) {
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
|
||||
items[i].sell(5);
|
||||
|
||||
System.out.println(items[i].name +" " + items[i].price +"円 " + "残り" +items[i].stock +"個");
|
||||
items[i].sell(5);
|
||||
|
||||
System.out.println(items[i]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,72 @@
|
||||
|
||||
public class EmployeeData {
|
||||
String idEmployee;
|
||||
String nmEmployee;
|
||||
String knEmployee;
|
||||
String mailAddress;
|
||||
String password;
|
||||
String idDepartment;
|
||||
private String idEmployee;
|
||||
private String nmEmployee;
|
||||
private String knEmployee;
|
||||
private String mailAddress;
|
||||
private String password;
|
||||
private String idDepartment;
|
||||
|
||||
EmployeeData(String idEmployee, String nmEmployee, String knEmployee, String mailAddress, String password,
|
||||
String idDepartment) {
|
||||
this.idEmployee = idEmployee;
|
||||
this.nmEmployee = nmEmployee;
|
||||
this.knEmployee = knEmployee;
|
||||
this.mailAddress = mailAddress;
|
||||
this.password = password;
|
||||
this.idDepartment = idDepartment;
|
||||
}
|
||||
|
||||
public String getIdEmployee() {
|
||||
return idEmployee;
|
||||
}
|
||||
|
||||
public void setIdEmployee(String idEmployee) {
|
||||
this.idEmployee = idEmployee;
|
||||
}
|
||||
|
||||
public String getNmEmployee() {
|
||||
return nmEmployee;
|
||||
}
|
||||
|
||||
public void setNmEmployee(String nmEmployee) {
|
||||
this.nmEmployee = nmEmployee;
|
||||
}
|
||||
|
||||
public String getKnEmployee() {
|
||||
return knEmployee;
|
||||
}
|
||||
|
||||
public void setKnEmployee(String knEmployee) {
|
||||
this.knEmployee = knEmployee;
|
||||
}
|
||||
|
||||
public String getMailAddress() {
|
||||
return mailAddress;
|
||||
}
|
||||
|
||||
public void setMailAddress(String mailAddress) {
|
||||
this.mailAddress = mailAddress;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getIdDepartment() {
|
||||
return idDepartment;
|
||||
}
|
||||
|
||||
public void setIdDepartment(String idDepartment) {
|
||||
this.idDepartment = idDepartment;
|
||||
}
|
||||
|
||||
void showInfo() {
|
||||
System.out.println(this.idEmployee + "\t" + this.nmEmployee + "\t" + this.knEmployee + "\t" + this.mailAddress
|
||||
+ "\t" + this.password + "\t" + this.idDepartment);
|
||||
System.out.println(getIdEmployee() + "\t" + getNmEmployee() + "\t" + getKnEmployee() + "\t" + getMailAddress()
|
||||
+ "\t" + getPassword() + "\t" + getIdDepartment());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,44 @@
|
||||
|
||||
public class Item {
|
||||
String name;
|
||||
int price;
|
||||
int stock;
|
||||
private String name;
|
||||
private int price;
|
||||
private int stock;
|
||||
|
||||
void sell(int amount) {
|
||||
this.stock = this.stock - amount;
|
||||
// void sell(int amount) {
|
||||
// this.stock = this.stock - amount;
|
||||
|
||||
public void sell(int amount) {
|
||||
setStock(this.getStock() - amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String output = getName() + " " + getPrice() + "円 (残り" + getStock() + "個)";
|
||||
return output;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(int price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public int getStock() {
|
||||
return stock;
|
||||
}
|
||||
|
||||
public void setStock(int stock) {
|
||||
this.stock = stock;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,50 +6,50 @@ public class Main {
|
||||
|
||||
EmployeeData[] employees = new EmployeeData[5];
|
||||
|
||||
EmployeeData employee = new EmployeeData();
|
||||
EmployeeData employee = new EmployeeData("10001","山田龍也","ヤマダタツヤ","yamada@hoge.jp","aaa","10");
|
||||
|
||||
employee.idEmployee = "10001";
|
||||
employee.nmEmployee = "山田龍也";
|
||||
employee.knEmployee = "ヤマダタツヤ";
|
||||
employee.mailAddress = "yamada@hoge.jp";
|
||||
employee.password = "aaa";
|
||||
employee.idDepartment = "10";
|
||||
// employee.idEmployee = "10001";
|
||||
// employee.nmEmployee = "山田龍也";
|
||||
// employee.knEmployee = "ヤマダタツヤ";
|
||||
// employee.mailAddress = "yamada@hoge.jp";
|
||||
// employee.password = "aaa";
|
||||
// employee.idDepartment = "10";
|
||||
|
||||
EmployeeData employee1 = new EmployeeData();
|
||||
EmployeeData employee1 = new EmployeeData("10002","高橋準","タカハシジュン","jtaka@hoge.jp","bbb","10");
|
||||
|
||||
employee1.idEmployee = "10002";
|
||||
employee1.nmEmployee = "高橋準";
|
||||
employee1.knEmployee = "タカハシジュン";
|
||||
employee1.mailAddress = "jtaka@hoge.jp";
|
||||
employee1.password = "bbb";
|
||||
employee1.idDepartment = "10";
|
||||
// employee1.idEmployee = "10002";
|
||||
// employee1.nmEmployee = "高橋準";
|
||||
// employee1.knEmployee = "タカハシジュン";
|
||||
// employee1.mailAddress = "jtaka@hoge.jp";
|
||||
// employee1.password = "bbb";
|
||||
// employee1.idDepartment = "10";
|
||||
|
||||
EmployeeData employee2 = new EmployeeData();
|
||||
EmployeeData employee2 = new EmployeeData("10003", "麻枝史明","マエダフミアキ","fmak@hoge.jp","ccc","11");
|
||||
|
||||
employee2.idEmployee = "10003";
|
||||
employee2.nmEmployee = "麻枝史明";
|
||||
employee2.knEmployee = "マエダフミアキ";
|
||||
employee2.mailAddress = "fmak@hoge.jp";
|
||||
employee2.password = "ccc";
|
||||
employee2.idDepartment = "11";
|
||||
// employee2.idEmployee = "10003";
|
||||
// employee2.nmEmployee = "麻枝史明";
|
||||
// employee2.knEmployee = "マエダフミアキ";
|
||||
// employee2.mailAddress = "fmak@hoge.jp";
|
||||
// employee2.password = "ccc";
|
||||
// employee2.idDepartment = "11";
|
||||
|
||||
EmployeeData employee3 = new EmployeeData();
|
||||
EmployeeData employee3 = new EmployeeData("10004","丸戸章介", "マルトショウスケ","marusyo@hoge.jp","ddd","12");
|
||||
|
||||
employee3.idEmployee = "10004";
|
||||
employee3.nmEmployee = "丸戸章介";
|
||||
employee3.knEmployee = "マルトショウスケ";
|
||||
employee3.mailAddress = "marusyo@hoge.jp";
|
||||
employee3.password = "ddd";
|
||||
employee3.idDepartment = "12";
|
||||
// employee3.idEmployee = "10004";
|
||||
// employee3.nmEmployee = "丸戸章介";
|
||||
// employee3.knEmployee = "マルトショウスケ";
|
||||
// employee3.mailAddress = "marusyo@hoge.jp";
|
||||
// employee3.password = "ddd";
|
||||
// employee3.idDepartment = "12";
|
||||
|
||||
EmployeeData employee4 = new EmployeeData();
|
||||
EmployeeData employee4 = new EmployeeData("10005","三宅武","ミヤケタケシ","miya@hoge.jp,eee","eee","13");
|
||||
|
||||
employee4.idEmployee = "10005";
|
||||
employee4.nmEmployee = "三宅武";
|
||||
employee4.knEmployee = "ミヤケタケシ";
|
||||
employee4.mailAddress = "miya@hoge.jp,eee";
|
||||
employee4.password = "eee";
|
||||
employee4.idDepartment = "13";
|
||||
// employee4.idEmployee = "10005";
|
||||
// employee4.nmEmployee = "三宅武";
|
||||
// employee4.knEmployee = "ミヤケタケシ";
|
||||
// employee4.mailAddress = "miya@hoge.jp,eee";
|
||||
// employee4.password = "eee";
|
||||
// employee4.idDepartment = "13";
|
||||
|
||||
employees[0] = employee;
|
||||
employees[1] = employee1;
|
||||
|
||||
@@ -2,10 +2,24 @@
|
||||
public class Student {
|
||||
int studentId;
|
||||
String name;
|
||||
static int studentCount = 0;
|
||||
{
|
||||
studentCount++;
|
||||
}
|
||||
|
||||
Student(int studentId, String name) {
|
||||
this.studentId = studentId;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public static int getStudentCount() {
|
||||
return studentCount;
|
||||
}
|
||||
|
||||
void printProfile() {
|
||||
|
||||
System.out.println("学籍番号:" + this.studentId + " 名前:"+ this.name);
|
||||
System.out.println("学籍番号:" + this.studentId + " 名前:" + this.name);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user