init
This commit is contained in:
23
Question19-Collection/src/PTra19_01.java
Normal file
23
Question19-Collection/src/PTra19_01.java
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* PTra19_01.java
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
|
||||
public class PTra19_01 {
|
||||
public static void main(String[] args) {
|
||||
// TODO String型を格納するArraylistを変数名 animals で作成してください。
|
||||
|
||||
/*
|
||||
* TODO animalsに以下の文字列を追加してください
|
||||
* ・いぬ
|
||||
* ・ねこ
|
||||
* ・うさぎ
|
||||
* ・たぬき
|
||||
*/
|
||||
|
||||
// TODO animalsの中身を全て出力してください(拡張for文を使用する事)
|
||||
|
||||
}
|
||||
}
|
||||
46
Question19-Collection/src/PTra19_02.java
Normal file
46
Question19-Collection/src/PTra19_02.java
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* PTra19_02.java
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
|
||||
public class PTra19_02 {
|
||||
public static void main(String[] args) {
|
||||
// TODO Player型を格納するArraylistを変数名 playerList で作成してください。
|
||||
|
||||
/*
|
||||
* TODO 以下の情報を持つインスタンスを3つ作成してください
|
||||
*
|
||||
* -------1人目---------
|
||||
* ポジション:MF
|
||||
* 名前 :佐川真司
|
||||
* 国 :日本
|
||||
* 所属チーム:ドルトムント
|
||||
*
|
||||
* -------2人目---------
|
||||
* ポジション:DF
|
||||
* 名前 :永元佑都
|
||||
* 国 :日本
|
||||
* 所属チーム:インテル
|
||||
*
|
||||
* -------3人目---------
|
||||
* ポジション:MF
|
||||
* 名前 :本田健佑
|
||||
* 国 :日本
|
||||
* 所属チーム:ACミラン
|
||||
*/
|
||||
|
||||
// TODO 作成したインスタンスを全てplayerListに追加してください
|
||||
|
||||
/*
|
||||
* TODO playerListの情報を全て出力してください。(拡張for文を使用する事)
|
||||
*
|
||||
* ※ 以下のように標示されれば正解
|
||||
* MF,佐川真司,日本,ドルトムント
|
||||
* DF,永元佑都,日本,インテル
|
||||
* MF,本田健佑,日本,ACミラン
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
16
Question19-Collection/src/PTra19_03.java
Normal file
16
Question19-Collection/src/PTra19_03.java
Normal file
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* PTra19_03.java
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
|
||||
public class PTra19_03 {
|
||||
public static void main(String[] args) {
|
||||
//※ この問題はcommonパッケージのPlayerUtillクラスをよく読んでから解いてください。
|
||||
// TODO PlayerUtillクラスのgetPlayerListメソッドを使用して選手のリストを取得してください
|
||||
|
||||
// TODO 選手のリストから、ポジションが FW の選手のみ出力してください
|
||||
|
||||
}
|
||||
}
|
||||
17
Question19-Collection/src/PTra19_04.java
Normal file
17
Question19-Collection/src/PTra19_04.java
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* PTra19_04.java
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
|
||||
public class PTra19_04 {
|
||||
public static void main(String[] args) {
|
||||
// TODO PlayerUtillクラスのgetPlayerListメソッドを使用して選手のリストを取得してください
|
||||
|
||||
// TODO 選手のリストから、レアル・マドリード と バルセロナの選手を除外してください
|
||||
|
||||
// TODO 選手のリストをすべて出力してください
|
||||
|
||||
}
|
||||
}
|
||||
19
Question19-Collection/src/PTra19_05.java
Normal file
19
Question19-Collection/src/PTra19_05.java
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* PTra19_05.java
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
public class PTra19_05 {
|
||||
public static void main(String[] args) {
|
||||
// TODO FoodUtillクラスのgetFoodListメソッドを使用して料理一覧を取得してください
|
||||
|
||||
/*
|
||||
* TODO 料理一覧の中からランダムに3品選んで、
|
||||
* 選んだ料理名3つと合計の値段を出力してください。
|
||||
* ※ 同じ料理が2回以上表示されてはいけません
|
||||
* ※ 合計金額は 消費税は8%を加算して出力してください。(小数点以下切り捨て)
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
36
Question19-Collection/src/common/Food.java
Normal file
36
Question19-Collection/src/common/Food.java
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
package common;
|
||||
|
||||
public class Food {
|
||||
|
||||
// 名前
|
||||
String name;
|
||||
|
||||
// 値段
|
||||
int price;
|
||||
|
||||
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 Food(String name, int price) {
|
||||
this.name = name;
|
||||
this.price = price;
|
||||
}
|
||||
}
|
||||
35
Question19-Collection/src/common/FoodUtill.java
Normal file
35
Question19-Collection/src/common/FoodUtill.java
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
package common;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class FoodUtill {
|
||||
|
||||
/**
|
||||
* fileの中のFoodMenu.csvを読み込んで、
|
||||
* ArrayList<Food>の形に変換して返す
|
||||
* @return 料理一覧
|
||||
*/
|
||||
public static ArrayList<Food> getFoodList() {
|
||||
ArrayList<Food> foodList = new ArrayList<>();
|
||||
try (Scanner scanner = new Scanner(new File("file/FoodMenu.csv"))) {
|
||||
while(scanner.hasNext()) {
|
||||
String line = scanner.nextLine();
|
||||
String[] input = line.split(",");
|
||||
Food player = new Food(input[0],Integer.parseInt(input[1]));
|
||||
foodList.add(player);
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
System.out.println("ファイルが見つかりません");
|
||||
}
|
||||
return foodList;
|
||||
}
|
||||
|
||||
}
|
||||
109
Question19-Collection/src/common/Player.java
Normal file
109
Question19-Collection/src/common/Player.java
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
package common;
|
||||
|
||||
public class Player {
|
||||
/** ポジション */
|
||||
private String position;
|
||||
|
||||
/** 名前 */
|
||||
private String name;
|
||||
|
||||
/** 国 */
|
||||
private String country;
|
||||
|
||||
/** 所属チーム */
|
||||
private String team;
|
||||
|
||||
public Player() {
|
||||
|
||||
}
|
||||
|
||||
public Player(String position, String name, String country, String team) {
|
||||
this.position = position;
|
||||
this.name = name;
|
||||
this.country = country;
|
||||
this.team = team;
|
||||
}
|
||||
|
||||
/**
|
||||
* ポジションを取得します
|
||||
* @return ポジション
|
||||
*/
|
||||
public String getPosition() {
|
||||
return position;
|
||||
}
|
||||
/**
|
||||
* ポジションを設定します
|
||||
* @param position 設定したいポジション
|
||||
*/
|
||||
public void setPosition(String position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
/**
|
||||
* 名前を取得します
|
||||
* @return 名前
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 名前を設定します
|
||||
* @param name
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 国を取得します
|
||||
* @return
|
||||
*/
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
/**
|
||||
* 国を設定します
|
||||
* @param country 設定したい国
|
||||
*/
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
/**
|
||||
* 所属チームを取得します
|
||||
* @return 所属チーム
|
||||
*/
|
||||
public String getTeam() {
|
||||
return team;
|
||||
}
|
||||
|
||||
/**
|
||||
* 所属チームを設定します
|
||||
* @param team 設定したい所属チーム
|
||||
*/
|
||||
public void setTeam(String team) {
|
||||
this.team = team;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
final String SEP = ",";
|
||||
|
||||
StringBuilder str = new StringBuilder();
|
||||
str.append(this.position);
|
||||
str.append(SEP);
|
||||
str.append(this.name);
|
||||
str.append(SEP);
|
||||
str.append(this.country);
|
||||
str.append(SEP);
|
||||
str.append(this.team);
|
||||
|
||||
return str.toString();
|
||||
}
|
||||
}
|
||||
35
Question19-Collection/src/common/PlayerUtill.java
Normal file
35
Question19-Collection/src/common/PlayerUtill.java
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
package common;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class PlayerUtill {
|
||||
|
||||
/**
|
||||
* fileの中のBestElevenCandidate.csvを読み込んで、
|
||||
* ArrayList<Player>の形に変換して返す
|
||||
* @return サッカー選手一覧
|
||||
*/
|
||||
public static ArrayList<Player> getPlayerList() {
|
||||
ArrayList<Player> playerList = new ArrayList<>();
|
||||
try (Scanner scanner = new Scanner(new File("file/BestElevenCandidate.csv"))) {
|
||||
while(scanner.hasNext()) {
|
||||
String line = scanner.nextLine();
|
||||
String[] input = line.split(",");
|
||||
Player player = new Player(input[0],input[1],input[2],input[3]);
|
||||
playerList.add(player);
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
System.out.println("ファイルが見つかりません");
|
||||
}
|
||||
return playerList;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user