アプリ版:「スタンプのみでお礼する」機能のリリースについて

ここの多次元配列の出力するやり方が分かりません。

/** 部署データ(定数) */
★public static final String[][] QUATERDATA = {
{"総務部","業務部","システム部"},
{"5","10","35"},
};
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー

package practice13.common;

/**
* ユーザ情報を保持するクラスです
* @author rhizome
*
*/
public class Person {
/** 基準値 */
public static final int BASE_NO = 1000;

/** ユーザID */
public int userId;
/** ユーザ名 */
public String userNm;
/** メールアドレス */
public String mail;
/** パスワード */
public String password;
/**
* ユーザIDを取得します
* @return ユーザID
*/
public int getUserId() {
return userId;
}
/**
* ユーザIDを設定します
* @param userId 設定したいユーザID
*/
public void setUserId(int userId) {
this.userId = userId;
}
/**
* ユーザ名を取得します
* @return ユーザ名
*/
public String getUserNm() {
return userNm;
}
/**
* ユーザ名を設定します
* @param userNm 設定したいユーザ名
*/
public void setUserNm(String userNm) {
this.userNm = userNm;
}
/**
* メールアドレスを取得します
* @return メールアドレス
*/
public String getMail() {
return mail;
}
/**
* メールアドレスを設定します
* @param mail 設定したいメールアドレス
*/
public void setMail(String mail) {
this.mail = mail;
}
/**
* パスワードを取得します
* @return パスワード
*/
public String getPassword() {
return password;
}
/**
* パスワードを設定します
* @param password 設定したいパスワード
*/
public void setPassword(String password) {
this.password = password;
}

}
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
package practice13.common;

public class Employee extends Person {

private String departmentNm;
private int departmentCnt;

public String getDepartmentNm() {
return departmentNm;
}
public void setDepartmentNm(String departmentNm) {
this.departmentNm = departmentNm;
}
public int getDepartmentCnt() {
return departmentCnt;
}
public void setDepartmentCnt(int departmentCnt) {
this.departmentCnt = departmentCnt;
}
}

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
package practice13.ptra13;

import practice13.common.Employee;

public class PTra13_09 {



/** 名前データ(定数) */
public static final String[] NAMEDATA = {"山田", "佐藤", "小林"};

/** メールデータ(定数) */
public static final String[] MAILDATA = {"yamada@hoge.com","satou@hoge.com","kobayashi@hoge.com"};

/** パスワードデータ(定数) */
public static final String[] PASSDATA = {"rezo0001","rezo0002","rezo0003"};

/** 部署データ(定数) */
★public static final String[][] QUATERDATA = {
{"総務部","業務部","システム部"},
{"5","10","35"},
};

public static void main(String[] args) {

// ★ 定数で定義されている各データを使用して、Employeeインスタンスを3つ作成してください
Employee employee=new Employee();
for(int i=0;i<NAMEDATA.length;i++) {
employee.setUserNm(NAMEDATA[i]);
System.out.println(employee.getUserNm());


}for(int k=0;k<MAILDATA.length;k++) {
employee.setMail(MAILDATA[k]);
System.out.println(employee.getMail());


}for(int b=0;b<PASSDATA.length;b++) {
employee.setPassword(PASSDATA[b]);
System.out.println(employee.getPassword());


}






System.out.println(employee.getDepartmentCnt());

System.out.println(employee.getDepartmentNm());
}}

A 回答 (1件)

public class PTra13_09 {



/** 名前データ(定数) */
public static final String[] NAMEDATA = {"山田", "佐藤", "小林"};

/** メールデータ(定数) */
public static final String[] MAILDATA = {"yamada@hoge.com","satou@hoge.com","kobayashi@hoge.com"};

/** パスワードデータ(定数) */
public static final String[] PASSDATA = {"rezo0001","rezo0002","rezo0003"};

/** 部署データ(定数) */
public static final String[][] QUATERDATA = {
{"総務部","業務部","システム部"},
{"5","10","35"},
};

public static void main(String[] args) {
// ★ 定数で定義されている各データを使用して、Employeeインスタンスを3つ作成してください
Employee[] employee = new Employee[3];
// ↑employee配列の作成

for(int i=0; i<employee.length; i++) {
System.out.println("i="+i);
employee[i] = new Employee();
// ↑Employeeインスタンスの生成
employee[i].setUserNm(NAMEDATA[i]);
System.out.println(employee[i].getUserNm());
employee[i].setMail(MAILDATA[i]);
System.out.println(employee[i].getMail());
employee[i].setPassword(PASSDATA[i]);
System.out.println(employee[i].getPassword());
employee[i].setDepartmentCnt(Integer.valueOf(QUATERDATA[1][i]).intValue());
System.out.println(employee[i].getDepartmentCnt());
employee[i].setDepartmentNm(QUATERDATA[0][i]);
System.out.println(employee[i].getDepartmentNm());
System.out.println();
}
}
}

【実行結果】

>i=0
>山田
>yamada@hoge.com
>rezo0001
>5
>総務部
>
>i=1
>佐藤
>satou@hoge.com
>rezo0002
>10
>業務部
>
>i=2
>小林
>kobayashi@hoge.com
>rezo0003
>35
>システム部
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!