2 Commits

Author SHA1 Message Date
683be27ae1 1102自主学習 2026-11-02 13:49:42 +09:00
c0101fc96d 1030自主学習 2026-10-30 17:49:49 +09:00
138 changed files with 865 additions and 1665 deletions

View File

@@ -5,19 +5,7 @@
<projects> <projects>
</projects> </projects>
<buildSpec> <buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec> </buildSpec>
<natures> <natures>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures> </natures>
</projectDescription> </projectDescription>

View File

@@ -1,11 +0,0 @@
public class Question1_1 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
System.out.println("`Hello,world`");
}
}

View File

@@ -1,16 +0,0 @@
public class Question1_2 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
//1行だけを無効化する方法
/*
複数行をまとめて無効化する方法
*/
System.out.println("テスト");
}
}

View File

@@ -1,16 +0,0 @@
public class Question1_3 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
//変数strを宣言して代入する
String str;
str = "こんにちは";
//出力
System.out.println(str);
}
}

View File

@@ -1,15 +0,0 @@
public class Question1_4 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
//変数numberを値10で初期化する
int number = 10;
//出力
System.out.println(number);
}
}

View File

@@ -1,15 +0,0 @@
public class Question1_5 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
//変数chを値Aで初期化する
char ch = 'A';
//出力
System.out.println(ch);
}
}

View File

@@ -1,15 +0,0 @@
public class Question1_6 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
//変数boを値trueで初期化する
boolean bo = true;
//出力
System.out.println(bo);
}
}

View File

@@ -1,15 +0,0 @@
public class Question1_7 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
//変数loを値1000000000000で初期化する
long lo = 1000000000000L;
//出力
System.out.println(lo);
}
}

View File

@@ -1,15 +0,0 @@
public class Question1_8 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
//変数flを値3.14で初期化する
float fl = 3.14F;
//出力
System.out.println(fl);
}
}

View File

@@ -1,42 +0,0 @@
public class Question1_9 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
//変数宣言
boolean bl; // true or false
char ch; // 16ビットUnicode文字 u0000-uFFFF
byte by; // 8ビット整数 -128~127 (符号ビット+2^7)
short sh; // 16ビット整数 -32,768~32,767 (符号ビット+2^15)
int num; // 32ビット整数 -2,147,483,648~2,147,483,647 (符号ビット+2^31)
long lo; // 64ビット整数 -9,223,372,036,854,775,808~9,223,372,036,854,775,807 (符号ビット+2^63)
float fl; // 32ビット単精度浮動小数点数
double db; // 64ビット倍精度浮動小数点数
String str; // 文字列を扱うクラス
//代入
bl = true;
ch = 'A';
by = 100;
sh = 10000;
num = 1000000000;
lo = 1000000000000000000L;
fl = 3.1415926F;
db = 1e2;
str = "DONE";
//出力
System.out.println(bl);
System.out.println(ch);
System.out.println(by);
System.out.println(sh);
System.out.println(num);
System.out.println(lo);
System.out.println(fl);
System.out.println(db);
System.out.println(str);
}
}

View File

@@ -3,21 +3,20 @@ public class Question2_1 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
int sum = (6 + 2);
System.out.println(sum);
int sum, diff, mulch, div, rem; int diff = (6 - 2);
System.out.println(diff);
sum = 6 + 2; int mulch = (6 * 2);
diff = 6 - 2; System.out.println(mulch);
mulch = 6 * 2;
div = 6 / 2;
rem = 17 % 5;
System.out.println("変数sum:" + sum); int div = (6 / 2);
System.out.println("変数diff:" + diff); System.out.println(div);
System.out.println("変数mulch:" + mulch);
System.out.println("変数div:" + div);
System.out.println("変数rem:" + rem);
int rem = (17 % 5);
System.out.println(rem);
} }
} }

View File

@@ -3,12 +3,10 @@ public class Question2_2 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
String lastName = "山田";
String firstName = "太郎";
String lastName = "太郎"; System.out.println(lastName + firstName);
String firstName = "山田";
System.out.println(firstName+lastName);
} }
} }

View File

@@ -3,13 +3,9 @@ public class Question2_3 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
int num = 10; int num = 10;
num += 5;
num = num + 5;
System.out.println(num); System.out.println(num);
} }
} }

View File

@@ -3,16 +3,12 @@ public class Question2_4 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
float sum;
int num = 10;
float fl= 3.14f;
// error sum = num + fl;
// int sum;
// sum = 10 + 3.14;
double sum;
sum = 10 + 3.14;
System.out.println(sum); System.out.println(sum);
} }
} }

View File

@@ -3,13 +3,11 @@ public class Question2_5 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
int age = 20; int age = 20;
int diff = 5; int diff = 5;
System.out.println("山田さんは"+age+"歳です。"); System.out.println("山田さんは" + age + "歳です。");
System.out.println(diff+"年後には"+(age+diff)+"歳になります。"); System.out.println(diff + "年後には" + (age + diff) + "歳になります。");
} }
} }

View File

@@ -3,12 +3,8 @@ public class Question2_6 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
float sum = 9f / 2f;
int numerator = 9; System.out.println(sum);
int denominator = 2;
System.out.println( (float)numerator/(float)denominator );
} }
} }

View File

@@ -3,16 +3,8 @@ public class Question2_7 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
int num = (int)1.0;
int num;
// error
// num = 1.0;
num = (int)1.0;
System.out.println(num); System.out.println(num);
} }
} }

View File

@@ -3,15 +3,16 @@ public class Question2_8 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
int money = 1000; int money = 1000;
int price = 580; int price = 580;
float taxRate = 0.08F; float taxRate = 0.08f;
money = money - (int)( price*(1.0+taxRate) ); float tax = (int) (price * taxRate);
System.out.println("残金は"+money+"円です。"); float total = price + tax;
money -= total;
System.out.println("残金は" + money + "円です。");
} }
} }

View File

@@ -3,13 +3,12 @@ public class Question3_1 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
//設問1
int num = 100; int num;
num = 100;
if ( num == 100 ) { if(num == 100) {
System.out.println("条件に合致しました"); System.out.println("条件に合致しました");
} }
} }
} }

View File

@@ -3,15 +3,13 @@ public class Question3_2 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
int num;
int num = 65; num = 65;
if(num >= 65) {
if ( num >= 65 ) {
System.out.println("合格です"); System.out.println("合格です");
} else { }else if(num < 65) {
System.out.println("不合格です"); System.out.println("不合格です");
} }
} }
} }

View File

@@ -3,13 +3,11 @@ public class Question3_3 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
int num;
int num = 10; num = 10;
if (num % 2 == 0 && num % 5 == 0) {
if ( (num % 2 == 0 ) && ( num % 5 == 0 ) ) { System.out.println(num + "は2でも5でも割り切れます。");
System.out.println(num+"は"+2+"でも"+5+"でも割り切れます");
} }
} }
} }

View File

@@ -4,23 +4,19 @@ public class Question3_4 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
System.out.println("降水確率を入力してください。(数字のみ)"); System.out.println("降水確率を入力してください。(数字のみ)");
Scanner sc = new Scanner(System.in); Scanner sc = new Scanner(System.in);
int num = Integer.parseInt(sc.nextLine()); int num = sc.nextInt();
sc.close();
if ( (num<0) || (num>100) ) { if(num < 0 || num >100){
System.out.println("不正な値が入力されました"); System.out.println("不正な値が入力されました");
} else if ( num >= 75 ) { }else if(num >= 75) {
System.out.println("雨が降る確率が高いです"); System.out.println("雨が降る確率が高いです");
} else if ( (num<75) && (num>=30) ) { }else if(num >= 30 && num <75) {
System.out.println("雨が降るかもしれないです"); System.out.println("雨が降るかもしれないです");
} else { }else if (num < 30) {
System.out.println("雨はまず降らないでしょう"); System.out.println("雨はまず降らないでしょう");
} }
} }
} }

View File

@@ -3,13 +3,11 @@ public class Question4_1 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
int num = 0; int num = 0;
while ( num!=5 ) {
num = (int)( Math.random()*10 ); while(num != 5) {
num = (int)(Math.random()*10);
System.out.println(num); System.out.println(num);
} }
} }
} }

View File

@@ -3,13 +3,12 @@ public class Question4_2 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
int num = 2; int num = 2;
while ( num<=1000 ) {
num = num*2;
}
System.out.println(num);
while(num < 1000) {
num *= 2;
System.out.println(num);
}
} }
} }

View File

@@ -3,16 +3,18 @@ public class Question4_3 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
int num = 0; int num = 0;
while ( true ) {
num = (int)( Math.random()*10 ); while(true) {
num = (int)(Math.random()*10);
if(num !=5) {
System.out.println(num);
continue;
}else {
System.out.println(num); System.out.println(num);
if ( num==5 ) {
break; break;
} }
} }
} }
} }

View File

@@ -4,29 +4,30 @@ public class Question4_4 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
int map = 50; int map = 50;
int progress = 0; int progress = 0;
int num = 0;
String str;
System.out.println("===== START ====="); System.out.println("===== START =====");
while ( true ) { while(progress <= map) {
System.out.println("Enterキーを押してください。さいころをふります。"); System.out.println("Enterキーを押してください。さいころをふります。");
Scanner sc = new Scanner(System.in); Scanner sc = new Scanner(System.in);
String str = sc.nextLine(); str = sc.nextLine();
System.out.println(str);
int num = (int)( Math.random()*6+1 ); num = (int)(Math.random()*6) + 1;
System.out.println(num+"の目が出ました。"); System.out.println(num + "の目がでました。");
progress = progress + num;
if ( map-progress<=0 ) { break; }
System.out.println("残りのマスは"+(map-progress)+"マスです。");
progress += num;
int remaining = map - progress;
if(progress < map) {
System.out.println("残りのマスは" + remaining + "マスです。");
}
} }
System.out.println("===== GOAL ====="); System.out.println("===== GOAL =====");
} }
} }

View File

@@ -4,64 +4,50 @@ public class Question4_5 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
boolean winFlag = false;
boolean winflag = false; while(!winFlag) {
while ( !winflag ) {
System.out.println("じゃんけんを行います。"); System.out.println("じゃんけんを行います。");
System.out.println("あなたの出す手を入力してください。"); System.out.println("あなたの出す手を入力してください。");
System.out.println("0:グー, 1:チョキ, 2:パー"); System.out.println("0:グー、1:チョキ、2:パー");
Scanner sc = new Scanner(System.in); Scanner sc = new Scanner(System.in);
int playerHand = sc.nextInt(); int playerHand;
switch ( playerHand ) { playerHand= sc.nextInt();
case 0 : System.out.println(playerHand);
if(playerHand == 0) {
System.out.println("あなたはグーを出しました。"); System.out.println("あなたはグーを出しました。");
break; }else if(playerHand == 1) {
case 1 :
System.out.println("あなたはチョキを出しました。"); System.out.println("あなたはチョキを出しました。");
break; }else {
case 2 :
System.out.println("あなたはパーを出しました。"); System.out.println("あなたはパーを出しました。");
break;
// default :
// System.out.println("不正な入力です。");
// System.exit(0);
} }
int npcHand = (int)( Math.random()*3 ); int num = (int)(Math.random()*3);
switch ( npcHand ) { int npcHand = num;
case 0 :
if(npcHand ==0) {
System.out.println("相手はグーを出しました。"); System.out.println("相手はグーを出しました。");
break; }else if(npcHand ==1) {
case 1 :
System.out.println("相手はチョキを出しました。"); System.out.println("相手はチョキを出しました。");
break; }else {
case 2 :
System.out.println("相手はパーを出しました。"); System.out.println("相手はパーを出しました。");
break;
} }
if ( playerHand == npcHand ) { if(playerHand == 0 && npcHand ==1 || playerHand == 1 && npcHand ==2 || playerHand == 2 &&npcHand ==0) {
System.out.println("引き分けました。"); System.out.println("あなたの勝ちです。");
System.out.println(""); winFlag = true;
}else if(playerHand == npcHand) {
System.out.println("あいこです。");
System.out.println();
continue;
}else {
System.out.println("あなたの負けです。");
System.out.println();
continue; continue;
} }
if ( ((playerHand==0)&&(npcHand==2)) ||
((playerHand==1)&&(npcHand==0)) ||
((playerHand==2)&&(npcHand==1)) ) {
System.out.println("負けました。");
System.out.println("");
continue;
} else {
System.out.println("勝ちました。");
winflag = true;
} }
}
}
}
} }

View File

@@ -3,33 +3,34 @@ public class Question5_1 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
System.out.println("今日の運勢を占います。"); System.out.println("今日の運勢を占います。");
int num = (int)(Math.random()*6);
int num = (int)( Math.random()*5+1 ); switch(num) {
// System.out.println(num); case 0:
System.out.println("あなたの運勢は「大吉」です");
break;
switch (num) { case 1:
case 0 : System.out.println("あなたの運勢は「吉」です");
System.out.println("あなたの運勢は「大吉」です。");
break; break;
case 1 :
System.out.println("あなたの運勢は「吉」です。"); case 2:
System.out.println("あなたの運勢は「中吉」");
break; break;
case 2 :
System.out.println("あなたの運勢は「中吉」です。"); case 3:
System.out.println("あなたの運勢は「小吉」");
break; break;
case 3 :
System.out.println("あなたの運勢は「小吉」です。"); case 4:
System.out.println("あなたの運勢は「末吉」");
break; break;
case 4 :
System.out.println("あなたの運勢は「末吉」です。"); case 5:
break; System.out.println("あなたの運勢は「凶」");
case 5 :
System.out.println("あなたの運勢は「凶」です。");
break; break;
} }
} }
} }

View File

@@ -4,44 +4,39 @@ public class Question5_2 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
int num1, num2;
String choice;
Scanner sc = new Scanner(System.in);
System.out.println("1つ目の数値を入力してください"); System.out.println("1つ目の数値を入力してください");
num1 = sc.nextInt(); Scanner sc = new Scanner(System.in);
int num1 = sc.nextInt();
System.out.println("2つ目の数値を入力してください"); System.out.println("2つ目の数値を入力してください");
num2 = sc.nextInt(); int num2 = sc.nextInt();
System.out.println("計算方法を選択してください"); System.out.println("計算方法を選択してください");
choice = sc.next(); sc.nextLine();
String choice = sc.nextLine();
sc.close(); switch(choice) {
case "+":
System.out.println(num1 + num2);
break;
switch (choice) { case "-":
case "+" : System.out.println(num1 - num2);
System.out.println(num1+num2);
break; break;
case "-" :
System.out.println(num1-num2); case "*":
System.out.println(num1 * num2);
break; break;
case "*" :
System.out.println(num1*num2); case "/":
System.out.println(num1 / num2);
break; break;
case "/" :
System.out.println((double)num1/(double)num2); case "%":
System.out.println(num1 % num2);
break; break;
case "%" :
System.out.println(num1%num2); default:
break;
default :
System.out.println("計算に失敗しました"); System.out.println("計算に失敗しました");
break;
} }
} }
} }

View File

@@ -4,64 +4,55 @@ public class Question5_3 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
System.out.println("=========================================");
System.out.println(" ゲームの説明 ");
System.out.println("=========================================");
System.out.println("=========================================\n" System.out.println("これからハイ&ローゲームを行います。");
+ " ゲームの説明\n" System.out.println("ハイ&ローゲームは、あなたのカードがディーラーのカードより大きいか小さいかを予想するゲームです。");
+ "=========================================\n" System.out.println();
+ "これからハイ&ローゲームを行います。\n"
+ "ハイ&ローゲームは、あなたのカードがディーラーのカードより大きいか小さいかを予想するゲームです。\n"
+ "\n"
+ "=========================================\n"
+ " ゲーム開始\n"
+ "=========================================");
int dealerCard = (int)( Math.random()*12+1 ); System.out.println("=========================================");
// dealerCard = ; System.out.println(" ゲーム開始 ");
System.out.println("ディーラーのカードは"+dealerCard+"です"); System.out.println("=========================================");
int myCard = (int)( Math.random()*12+1 );
// myCard = ;
System.out.println("");
int dealerCard = (int)(Math.random()*13)+1;
System.out.println("ディーラーのカードは" + dealerCard + "です");
int myCard = (int)(Math.random()*13)+1;
System.out.println();
System.out.println("あなたのカードがディーラのカードより大きい場合は H 小さい場合は L を入力してください。"); System.out.println("あなたのカードがディーラのカードより大きい場合は H 小さい場合は L を入力してください。");
System.out.println("※ カードの数値が同じ場合はあなたの勝ちです。"); System.out.println("※ カードの数値が同じ場合はあなたの勝ちです。");
String jedgement;
Scanner sc = new Scanner(System.in); Scanner sc = new Scanner(System.in);
jedgement = sc.next(); String judgement = sc.nextLine();
sc.close(); System.out.println("あなたのカードは" + myCard + "です");
System.out.println("あなたのカードは"+myCard+"です");
System.out.println(""); System.out.println();
System.out.println("=========================================");
System.out.println(" 勝敗判定" );
System.out.println("=========================================");
System.out.println("=========================================\n" switch(judgement) {
+ " 勝敗判定\n" case "H":
+ "========================================="); if(myCard > dealerCard || myCard == dealerCard) {
switch (jedgement) {
case "H" :
if (myCard>=dealerCard) {
System.out.println("あなたの勝ちです"); System.out.println("あなたの勝ちです");
break; break;
} else { }else{
System.out.println("あなたの負けです"); System.out.println("あなたの負けです");
break; break;
} }
case "L" : case "L":
if (myCard<=dealerCard) { if(myCard < dealerCard || myCard == dealerCard) {
System.out.println("あなたの勝ちです"); System.out.println("あなたの勝ちです");
break; break;
} else { }else{
System.out.println("あなたの負けです"); System.out.println("あなたの負けです");
break; break;
} }
default : default:
System.out.println("不正な値が入力されました"); System.out.println("不正な値が入力されました");
break;
} }
} }
} }

View File

@@ -3,11 +3,9 @@ public class Question6_1 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
for(int i = 0; i < 100; i++){
for ( int i = 0 ; i<100 ; i++ ) {
System.out.println(i); System.out.println(i);
} }
} }
} }

View File

@@ -3,18 +3,11 @@ public class Question6_2 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
System.out.println("■■■■■");
StringBuilder square = new StringBuilder(); for(int i = 0; i < 5;i++) {
for ( int i=0 ; i<5 ; i++ ) { System.out.print("■");
square.append('\u25A0'); // ■ = \u25A0
} }
System.out.println(square);
// 1009
for ( int i=0 ; i<5 ; i++ ) {
System.out.print("\u25A0");
}
} }
} }

View File

@@ -3,13 +3,11 @@ public class Question6_3 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
for(int i = 0;i < 100; i++) {
for ( int i = 0 ; i<=100 ; i++ ) { if(i % 2 == 0) {
if ( i%2 == 0 ) {
System.out.println(i); System.out.println(i);
} }
} }
} }
} }

View File

@@ -3,22 +3,17 @@ public class Question6_4 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
for(int i = 1; i <= 49; i++) {
for ( int i = 1 ; i<50 ; i++ ) { if(i % 3 == 0 && i % 5 == 0) {
if ( (i%3 == 0) && (i%5 == 0) ) {
System.out.println("fizzbuzz"); System.out.println("fizzbuzz");
continue; }else if(i % 5 == 0) {
} else if ( i%3==0 ) {
System.out.println("fizz");
} else if ( i%5==0 ) {
System.out.println("buzz"); System.out.println("buzz");
} else { }else if(i % 3 == 0 ) {
System.out.println("fizz");
}else {
System.out.println(i); System.out.println(i);
} }
} }
} }
} }

View File

@@ -3,20 +3,12 @@ public class Question6_5 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
for(int i = 0; i < 10; i++) {
int rand; int num = (int)(Math.random()*3);
for ( int i = 0 ; i<10 ; i++) { if(num !=2) {
System.out.println(num);
rand = (int)( Math.random()*3 );
if ( rand==2 ) {
// no output
} else {
System.out.println(rand);
} }
} }
} }
} }

View File

@@ -3,23 +3,9 @@ public class Question6_6 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
for(int i = 0; i < 5; i++) {
StringBuilder square = new StringBuilder(); System.out.println("■■■■■");
for ( int i=0 ; i<5 ; i++ ) {
square.append('\u25A0'); // ■ = \u25A0
} }
for ( int i=0 ; i<5 ; i++ ) {
System.out.println(square);
}
// 1009
for (int j=0 ; j<5 ; j++ ) {
for ( int i=0 ; i<5 ; i++ ) {
System.out.print("\u25A0");
}
System.out.println("");
}
} }
} }

View File

@@ -3,29 +3,12 @@ public class Question6_7 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
for(int i = 1; i <= 9; i++) {
StringBuilder sb = new StringBuilder(); for(int j = 1; j <= 9; j++) {
for ( int i=1 ; i<=9 ; i++ ) { System.out.printf("%2d",i * j);
for ( int j=1 ; j<=9 ; j++ ) {
if ( j>=2 ) {
sb.append(" "); // *2以降には空白を追加する
} }
sb.append(i*j); // 計算結果を文字列として追加していく System.out.println();
} }
System.out.println(sb);
sb.delete(0,sb.length()); // 追記した文字列をクリアする
}
// 1009
for ( int i=1 ; i<=9 ; i++ ) {
for ( int j=1 ; j<=9 ; j++ ) {
System.out.print(i*j);
if ( j==9 ) { continue; }
System.out.print(" ");
}
System.out.println("");
}
} }
} }

View File

@@ -3,16 +3,7 @@ public class Question7_1 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
int[] nums = {1, 3, 5, 7, 9};
int nums[] = new int[5];
nums[0] = 1;
nums[1] = 3;
nums[2] = 5;
nums[3] = 7;
nums[4] = 9;
System.out.println(nums[1]); System.out.println(nums[1]);
} }
} }

View File

@@ -3,19 +3,14 @@ public class Question7_10 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
int[] nums = new int[100]; int[] nums = new int[100];
// ArrayIndexOutOfBoundException for(int i = 0; i < nums.length; i++) {
// for ( int i=1 ; i<=100 ; i++ ) { nums[i] = i + 1;
// nums[i] = i+1; }
// } for(int i = 0; i < nums.length; i++) {
for ( int i=0 ; i<100 ; i++ ) {
nums[i] = i+1;
System.out.println(nums[i]); System.out.println(nums[i]);
} }
} }
} }

View File

@@ -3,11 +3,8 @@ public class Question7_2 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
int[] nums = {1, 10, 100};
int[] nums = {1 ,10, 100}; System.out.println(nums[0] + nums[2]);
System.out.println(nums[0]+nums[2]);
} }
} }

View File

@@ -3,13 +3,10 @@ public class Question7_3 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
String[] str = {"森", "山", "沼", "島", "平地"};
String[] str = {"森","山","沼","島","平地"}; for(int i = 0; i <= 4; i++) {
for ( int i=0 ; i<str.length ; i++ ) {
System.out.println(str[i]); System.out.println(str[i]);
} }
} }
} }

View File

@@ -3,14 +3,13 @@ public class Question7_4 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
int[] nums = new int[1000];
int nums[] = new int[1000]; for(int i = 0; i < 1000; i++) {
nums[i] = i + 1;
for ( int i=1 ; i<=nums.length ; i++ ) {
nums[i-1] = i;
System.out.println(nums[i-1]);
} }
for(int i = 0; i < 1000; i++) {
System.out.println(nums[i]);
} }
} }
}

View File

@@ -3,12 +3,9 @@ public class Question7_5 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
String[] str = {"森", "山", "沼", "島", "平地"};
String[] str = {"森","山","沼","島","平地"}; int num = (int)(Math.random()*5);
int num = (int)( Math.random()*5 );
System.out.println(str[num]); System.out.println(str[num]);
} }
} }

View File

@@ -3,12 +3,10 @@ public class Question7_6 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
String[] str = {"森", "山", "沼", "島", "平地"};
String[] str = {"森","山","沼","島","平地"}; for(int i = 4; i >=0; i--) {
for ( int i=str.length ; i>0 ; i-- ) { System.out.println(str[i]);
System.out.println(str[i-1]);
}
} }
} }
}

View File

@@ -3,17 +3,26 @@ public class Question7_7 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
String[][] timetable = {
String[][] table = { {"国語", "社会", "国語", "理科", "社会"},
{"国語","社会","国語","理科","社会"}, {"英語", "数学", "英語", "数学", "国語"},
{"英語","数学","英語","数学","国語"}, {"理科", "国語", "理科", "国語" ,"理科"},
{"理科","国語","理科","国語","理科"}, {"社会", "社会", "数学", "社会", "数学"},
{"社会","社会","数学","社会","数学"}, {"数学", "英語", "英語", "理科", "英語"},
{"数学","英語","英語","理科","英語"}
}; };
System.out.println(table[1][4]); System.out.println("\t 月\t 火\t 水\t 木\t 金");
for(int i = 0; i < 5; i++) {
System.out.print((i + 1) + "時間目");
for(int j = 0; j < 5; j++) {
System.out.print("\t" + timetable[i][j]);
}
System.out.println();
} }
} System.out.println(timetable[1][4]);
}
}

View File

@@ -3,18 +3,14 @@ public class Question7_8 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
int[][] nums = {
int[][] array = { {1, 3, 5, 7},
{1,3,5,7}, {11, 13, 17, 19, 23, 29}
{11,13,17,19,23,29}
}; };
for(int i = 0; i < nums.length; i++) {
for ( int i=0 ; i<array.length ; i++) { for(int j = 0; j < nums[i].length; j++) {
for ( int j=0 ; j<array[i].length ; j++ ) { System.out.println(nums[i][j]);
System.out.println(array[i][j]);
} }
} }
} }
} }

View File

@@ -3,22 +3,21 @@ public class Question7_9 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
int[][] nums = {
int[][] array = { {1, 3, 5, 7},
{1,3,5,7}, {11, 13, 17, 19, 23, 29}
{11,13,17,19,23,29}
}; };
int sum = 0;
int count = 0;
int count=0; for(int i = 0; i < nums.length; i++) {
double sum=0; for(int j = 0; j < nums[i].length; j++) {
for ( int i=0 ; i<array.length ; i++) { sum += nums[i][j];
for ( int j=0 ; j<array[i].length ; j++ ) {
sum += array[i][j];
count++; count++;
} }
} }
System.out.println(sum/count); float ave = (float)sum / count;
System.out.println(ave);
} }
} }

View File

@@ -3,13 +3,10 @@ public class Question8_1 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
hello();
hello() ;
} }
public static void hello() { public static void hello() {
System.out.println("こんにちは"); System.out.println("こんにちは");
} }
} }

View File

@@ -3,13 +3,10 @@ public class Question8_2 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
hello("山田"); hello("山田");
} }
public static void hello( String name ) { public static void hello(String str) {
System.out.println("こんにちは。"+name+"です。"); System.out.println("こんにちは" + str + "です");
} }
} }

View File

@@ -3,16 +3,11 @@ public class Question8_3 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
String str = hello();
String str;
str = hello();
System.out.println(str); System.out.println(str);
} }
public static String hello() { public static String hello() {
return "こんにちは"; return "こんにちは";
} }
} }

View File

@@ -3,18 +3,12 @@ public class Question8_4 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
int total = 0;
int sum; total = sum(1, 2);
int x = 1; System.out.println(total);
int y = 2;
sum = sum(x,y);
System.out.println(sum);
} }
public static int sum( int x, int y ) { public static int sum(int x, int y) {
return x+y; return x + y;
} }
} }

View File

@@ -4,24 +4,24 @@ public class Question8_5 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
int num1, num2;
Scanner sc = new Scanner(System.in);
System.out.println("1つ目の数値を入力してください"); System.out.println("1つ目の数値を入力してください");
Scanner sc = new Scanner(System.in);
int num1;
num1 = sc.nextInt(); num1 = sc.nextInt();
System.out.println(num1);
System.out.println("2つ目の数値を入力してください"); System.out.println("2つ目の数値を入力してください");
int num2;
num2 = sc.nextInt(); num2 = sc.nextInt();
System.out.println(num2);
sc.close(); int total = 0;
total = sum(num1, num2);
System.out.println(sum(num1,num2)); System.out.println(total);
} }
public static int sum( int x, int y ) { public static int sum(int num1, int num2) {
return x+y; return num1 + num2;
} }
} }

View File

@@ -1,24 +1,17 @@
import java.util.Arrays;
public class Question8_6 { public class Question8_6 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
int[] array = addArray(10, 20);
int[] array = addArray(10,20); System.out.println(Arrays.toString(array));
System.out.println(array[0]);
System.out.println(array[1]);
} }
public static int[] addArray( int x, int y ) { public static int[] addArray(int x, int y) {
int[] array = new int[2];
int array[] = new int[2];
array[0] = x; array[0] = x;
array[1] = y; array[1] = y;
return array; return array;
} }
} }

View File

@@ -3,28 +3,25 @@ public class Question8_7 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
printValue("こんにちは"); printValue("こんにちは");
printValue(100); printValue("100");
printValue(10.1F); printValue("10.1");
printValue('A'); printValue("A");
} }
public static void printValue( String arg ) { public static void printValue(String str) {
System.out.println("引数は"+arg+"です"); System.out.println("引数は" + str + "です");
} }
public static void printValue( int arg ) { public static void printValue(int i) {
System.out.println("引数は"+arg+"です"); System.out.println("引数は" + i + "です");
} }
public static void printValue( float arg ) { public static void printValue(float f) {
System.out.println("引数は"+arg+"です"); System.out.println("引数は" + f + "です");
} }
public static void printValue( char arg ) { public static void printValue(char ch) {
System.out.println("引数は"+arg+"です"); System.out.println("引数は" + ch + "です");
} }
} }

View File

@@ -3,23 +3,23 @@ public class Question8_8 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
int total = 0;
total = sum(1, 2);
System.out.println(total);
System.out.println(sum(1,2)); total = sum(1, 2, 3);
System.out.println(sum(1,2,3)); System.out.println(total);
System.out.println(sum(1,2,3,4));
total = sum(1, 2, 3, 4);
System.out.println(total);
} }
public static int sum( int x1, int x2 ) { public static int sum(int... numbers) {
return x1+x2; int total = 0;
for(int n : numbers) {
total += n;
} }
return total;
public static int sum( int x1, int x2, int x3 ) {
return x1+x2+x3;
} }
public static int sum( int x1, int x2, int x3, int x4 ) {
return x1+x2+x3+x4;
}
} }

View File

@@ -3,10 +3,7 @@ public class Question9_1 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
Util.hello();
Util util = new Util();
util.hello();
} }
} }

View File

@@ -3,10 +3,7 @@ public class Question9_2 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
common.Util.showSum(1, 2);
common.Util util = new common.Util();
util.showSum(1,2);
} }
} }

View File

@@ -1,13 +1,9 @@
import common.Util; import common.Util;
public class Question9_3 { public class Question9_3 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
Util.showSum(1, 2);
Util util = new Util();
util.showSum(1,2);
} }
} }

View File

@@ -1,8 +1,6 @@
public class Util { public class Util {
public static void hello() {
public void hello() {
System.out.println("こんにちは"); System.out.println("こんにちは");
} }
} }

View File

@@ -1,9 +1,7 @@
package common; package common;
public class Util { public class Util {
public static void showSum(int num1, int num2) {
public void showSum(int num1,int num2) { System.out.println(num1 + num2);
System.out.println(num1+num2);
} }
} }

View File

@@ -1,10 +1,9 @@
public class Calculation { public class Calculation {
int baseNum; int baseNum;
public void add(int num) { public void add(int num) {
this.baseNum += num; this.baseNum += num;
} }
} }

View File

@@ -1,19 +1,17 @@
import java.util.Random;
public class Car { public class Car {
String color; String color;
int gasoline; int gasoline;
public int run() { public int run() {
this.gasoline -= 1;
this.gasoline--; if(this.gasoline >= 0) {
Random rand = new Random();
if (this.gasoline>=0) { int num = rand.nextInt(15) + 1;
return (int)(Math.random()*15+1) ; return num;
} else { }else {
return -1; return -1;
} }
} }
} }

View File

@@ -3,13 +3,13 @@ public class Question10_1 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
User user = new User(); User user = new User();
user.id = 1000; user.id = 1000;
user.name = "山田太郎"; user.name = "山田太郎";
System.out.println(user.id); System.out.println(user.id);
System.out.println(user.name); System.out.println(user.name);
} }
} }

View File

@@ -3,12 +3,12 @@ public class Question10_2 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
User user = new User(); User user = new User();
user.id = 2000; user.id = 2000;
user.name = "佐藤二郎"; user.name = "佐藤二郎";
user.printProfile();
user.printProfile();
} }
} }

View File

@@ -3,8 +3,8 @@ public class Question10_3 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
Student student = new Student(); Student student = new Student();
student.studentId = 10; student.studentId = 10;
student.name = "田中二郎"; student.name = "田中二郎";
student.mail = "test@mail.com"; student.mail = "test@mail.com";
@@ -13,8 +13,7 @@ public class Question10_3 {
System.out.println(student.studentId); System.out.println(student.studentId);
System.out.println(student.name); System.out.println(student.name);
System.out.println(student.mail); System.out.println(student.mail);
System.out.println(student.password); System.out.println(student.password );
} }
} }

View File

@@ -3,12 +3,13 @@ public class Question10_4 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
Calculation cal = new Calculation();
Calculation calculation = new Calculation(); cal.baseNum = 100;
calculation.baseNum = 100;
calculation.add(100);
System.out.println(calculation.baseNum); cal.add(100);
System.out.println(cal.baseNum);
} }

View File

@@ -3,14 +3,15 @@ public class Question10_5 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
Car car = new Car(); Car car = new Car();
car.color = "赤";
car.gasoline = 50;
int progress = car.run();
System.out.println(car.color+"色の車は"+progress+"進みました");
System.out.println(car.gasoline);
car.color ="赤";
car.gasoline = 50;
int y =car.run();
System.out.println(car.color + "色の車は" + y + "進みました");
System.out.println(car.gasoline);
} }
} }

View File

@@ -3,26 +3,27 @@ public class Question10_6 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
Car car = new Car(); Car car = new Car();
car.color = "赤"; car.color = "赤";
car.gasoline = 50; car.gasoline = 50;
int goal = 300;
int totaldistance = 0;
int time = 0;
int distance = 300; while(totaldistance < goal) {
int nRuns = 0; int y = car.run();
while (true) { if(y == -1) {
distance -= car.run(); System.out.println(car.color + "色の車は目的地に到達できませんでした");
nRuns++;
if (car.gasoline<0) {
System.out.println(car.color+"色の車は、目的地に到達できませんでした。");
break;
}
if (distance<=0) {
System.out.println(car.color+"色の車は、目的地にまで"+nRuns+"時間かかりました。残りのガソリンは、"+car.gasoline+"リットルです。");
break; break;
}else{
totaldistance += y;
time += 1;
continue;
} }
} }
System.out.println(car.color + "色の車は目的地にまで" + time + "時間かかりました。" +
"残りのガソリンは、" + car.gasoline + "リットルです");
} }
} }

View File

@@ -3,9 +3,7 @@ public class Question10_7 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
User[] userList = new User[3]; User[] userList = new User[3];
User user1 = new User(); User user1 = new User();
User user2 = new User(); User user2 = new User();
User user3 = new User(); User user3 = new User();
@@ -21,13 +19,9 @@ public class Question10_7 {
userList[1] = user2; userList[1] = user2;
userList[2] = user3; userList[2] = user3;
// for (int i=0;i<userList.length;i++) { for(int i = 0; i < 3; i++) {
// userList[i].printProfile(); userList[i].printProfile();
// }
for (User user:userList) {
user.printProfile();
} }
} }
} }

View File

@@ -3,39 +3,44 @@ public class Question10_8 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
Car[] carList = new Car[3];
Car car1 = new Car(); Car car1 = new Car();
car1.color = "赤"; car1.color = "赤";
car1.gasoline = 50; car1.gasoline = 50;
Car car2 = new Car(); Car car2 = new Car();
car2.color = "青"; car2.color = "青";
car2.gasoline = 60; car2.gasoline = 60;
Car car3 = new Car(); Car car3 = new Car();
car3.color = "黄"; car3.color = "黄";
car3.gasoline = 70; car3.gasoline = 70;
carList[0] = car1; Car[] cars = new Car[3];
carList[1] = car2; cars[0] = car1;
carList[2] = car3; cars[1] = car2;
cars[2] = car3;
int goal = 300;
for(int i = 0; i < 3; i++) {
int totaldistance = 0;
int time = 0;
int y = 0;
while(totaldistance < goal) {
y = cars[i].run();
if(y == -1) {
for (Car car:carList) {
int distance = 300;
int nRuns = 0;
while (true) {
distance -= car.run();
nRuns++;
if (car.gasoline<0) {
System.out.println(car.color+"色の車は、目的地に到達できませんでした。");
break; break;
}else {
totaldistance += y;
time += 1;
continue;
} }
if (distance<=0) {
System.out.println(car.color+"色の車は、目的地にまで"+nRuns+"時間かかりました。残りのガソリンは、"+car.gasoline+"リットルです。");
break;
} }
if(y == -1) {
System.out.println(cars[i].color + "色の車は、目的地に到達できませんでした");
}else {
System.out.println(cars[i].color + "色の車は、目的地にまで" + time + "時間かかりました。"
+ "残りのガソリンは、" + cars[i].gasoline + "リットルです");
} }
} }

View File

@@ -1,7 +1,7 @@
public class Student { public class Student {
int studentId; int studentId;
String name, mail, password; String name;
String mail;
String password;
} }

View File

@@ -1,11 +1,10 @@
public class User { public class User {
int id; int id;
String name; String name;
public void printProfile() {
System.out.println("ID"+this.id+":"+this.name);
}
public void printProfile() {
System.out.println("ID" + this.id + ":" + this.name);
}
} }

View File

@@ -1,20 +1,14 @@
public class Atm { public class Atm {
int credit = 100000;
int credit; public void withdraw(Wallet wallet, int money) {
if(credit < money) {
public Atm () {
this.credit = 100000;
}
public void withdraw( Wallet wallet , int money ) {
if ( this.credit < money ) {
System.out.println("預金残高不足です。現金の引き出しに失敗しました。"); System.out.println("預金残高不足です。現金の引き出しに失敗しました。");
} else { }else {
this.credit = this.credit - money; credit -= money;
wallet.money = wallet.money + money; wallet.money += money;
System.out.println("ATMの残り残高は"+this.credit+"です"); System.out.println("ATMの残り残高は" + credit + "です");
} }
} }
} }

View File

@@ -1,14 +1,14 @@
public class Cat { public class Cat {
String name; String name;
public Cat() { //ⅰ
Cat(){
this.name = "タマ"; this.name = "タマ";
} }
public Cat( String name ) { //ⅱ
public Cat(String name) {
this.name = name; this.name = name;
} }
} }

View File

@@ -1,10 +1,8 @@
public class Jam { public class Jam {
String material; String material;
public Jam( String jam ) { public Jam(String material) {
this.material = jam; this.material = material;
} }
} }

View File

@@ -3,18 +3,17 @@ public class Question11_1 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
Wallet wallet = new Wallet(); Wallet wallet = new Wallet();
wallet.money = 10000;
User user = new User(); User user = new User();
wallet.money = 10000;
user.name = "太郎"; user.name = "太郎";
user.wallet = wallet; user.wallet = wallet;
user.confirmWallet(); user.confirmWallet();
user.useMoney(1000); user.useMoney(1000);
user.confirmWallet(); user.confirmWallet();
} }
} }

View File

@@ -3,18 +3,15 @@ public class Question11_2 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
Wallet wallet = new Wallet(); Wallet wallet = new Wallet();
wallet.money = 10000;
Atm atm = new Atm(); Atm atm = new Atm();
atm.withdraw(wallet,100000); wallet.money = 10000;
atm.withdraw(wallet, 100000);
System.out.println(wallet.money); System.out.println(wallet.money);
atm.withdraw(wallet,100000); atm.withdraw(wallet, 100000);
System.out.println(wallet.money); System.out.println(wallet.money);
} }
} }

View File

@@ -3,13 +3,11 @@ public class Question11_3 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
Cat cat1 = new Cat(); Cat cat1 = new Cat();
System.out.println(cat1.name);
Cat cat2 = new Cat("ミケ"); Cat cat2 = new Cat("ミケ");
System.out.println(cat2.name);
System.out.println(cat1.name);
System.out.println(cat2.name);
} }
} }

View File

@@ -3,15 +3,13 @@ public class Question11_4 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
Student student = new Student(); Student student = new Student();
student.name = "太郎"; student.name = "太郎";
student.group = "A"; Student.group= "A";
student.teacher = "山田"; Student.teacher = "山田";
student.studentProfile(); student.studentProfile();
student.groupProfile(); Student.groupProfile();
} }
} }

View File

@@ -3,12 +3,10 @@ public class Question11_5 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
Jam jam = new Jam("ブルーベリー"); Jam jam = new Jam("ブルーベリー");
Toast toast = new Toast(jam); Toast toast = new Toast(jam);
toast.taste(); toast.taste();
} }
} }

View File

@@ -1,16 +1,14 @@
public class Student { public class Student {
String name; String name;
static String group; static String group;
static String teacher; static String teacher;
public void studentProfile() { public void studentProfile() {
System.out.println(this.name+"は"+this.group+"教室の生徒です。"); System.out.println(this.name + "は" + group + "教室の生徒です。");
} }
public void groupProfile() { public static void groupProfile() {
System.out.println(this.group+"教室の担任は"+this.teacher+"先生です。"); System.out.println(group + "教室の担任は" + teacher + "先生です。");
} }
} }

View File

@@ -1,6 +1,5 @@
public class Toast { public class Toast {
Jam jam; Jam jam;
public Toast(Jam jam) { public Toast(Jam jam) {
@@ -8,7 +7,6 @@ public class Toast {
} }
public void taste() { public void taste() {
System.out.println(jam.material+"味のトーストです。"); System.out.println(this.jam.material + "味のトーストです。");
} }
} }

View File

@@ -1,16 +1,16 @@
public class User { public class User {
String name; String name;
Wallet wallet; Wallet wallet;
public void useMoney( int money ) { public void useMoney(int money) {
this.wallet.money = this.wallet.money - money; this.wallet.money -= money;
System.out.println(this.name+"は財布の中のお金を"+money+"円使用しました"); System.out.println(this.name + "は財布の中のお金を" +
money + "円使用しました");
} }
public void confirmWallet() { public void confirmWallet() {
System.out.println(this.name+"の財布の中の残額は"+this.wallet.money+"円です"); System.out.println(this.name + "の財布の中の残額は" +
this.wallet.money + "円です");
} }
} }

View File

@@ -1,6 +1,4 @@
public class Wallet { public class Wallet {
int money; int money;
} }

View File

@@ -1,14 +1,8 @@
public class Item { public class Item {
public String name = "アイテムA";
private String item; public String getName() {
return name;
public Item() {
this.item = "アイテムA";
} }
public String getItem() {
return item;
}
} }

View File

@@ -3,19 +3,16 @@ public class Question12_1 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
User user = new User(); User user = new User();
user.setId(1000); user.setId(1000);
user.setName("リゾーム太郎"); user.setName("リゾーム太郎");
user.setMail("rhizome@hogehoge.com"); user.setAddress("rhizome@hogehoge.com");
user.setPass("12345"); user.setPass("12345");
System.out.println("ID :"+user.getId()); System.out.println("ID :" + user.getId());
System.out.println("名前 :"+user.getName()); System.out.println("名前 :" + user.getName());
System.out.println("メールアドレス :"+user.getMail()); System.out.println("メールアドレス  :" + user.getAddress());
System.out.println("パスワード :"+user.getPass()); System.out.println("パスワード  :" + user.getPass());
} }
} }

View File

@@ -3,10 +3,8 @@ public class Question12_2 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
Item item = new Item(); Item item = new Item();
System.out.println(item.getItem()); System.out.println(item.getName());
} }
} }

View File

@@ -1,16 +1,14 @@
public class User { public class User {
public int id;
private int Id; public String name;
private String name; public String address;
private String mail; public String pass;
private String pass;
public int getId() { public int getId() {
return Id; return id;
} }
public void setId(int id) { public void setId(int id) {
Id = id; this.id = id;
} }
public String getName() { public String getName() {
return name; return name;
@@ -18,11 +16,11 @@ public class User {
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
public String getMail() { public String getAddress() {
return mail; return address;
} }
public void setMail(String mail) { public void setAddress(String address) {
this.mail = mail; this.address = address;
} }
public String getPass() { public String getPass() {
return pass; return pass;
@@ -31,4 +29,5 @@ public class User {
this.pass = pass; this.pass = pass;
} }
} }

View File

@@ -1,8 +1,15 @@
public class Animal { public class Animal {
private String name; private String name;
public void run() {
System.out.println(this.name + "は走りました。");
}
public void eat() {
System.out.println(this.name + "は食事をしました。");
}
public String getName() { public String getName() {
return name; return name;
} }
@@ -11,12 +18,5 @@ public class Animal {
this.name = name; this.name = name;
} }
public void Run() {
System.out.println(this.getName()+"走りました。");
}
public void Eat() {
System.out.println(this.getName()+"は食事をしました。");
}
} }

View File

@@ -1,4 +1,4 @@
public class Cat extends Animal { public class Cat extends Animal{
} }

View File

@@ -1,84 +1,53 @@
public class Character { public class Character {
private String name; private String name;
private int hp; private int hp;
private int power; private int power;
private int defense; private int defense;
public Character(int hp, int power, int defense) {
this.hp = hp;
this.power = power;
this.defense = defense;
}
public String getName() { public String getName() {
return name; return name;
} }
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
public int getHP() {
return hp;
}
public void setHP(int HP) {
hp = HP;
}
public int getPower() {
return power;
}
public void setPower(int power) {
this.power = power;
}
public int getDefense() {
return defense;
}
public void setDefense(int defense) {
this.defense = defense;
}
public Character() {
}
public Character(int HP, int power, int defense) {
this.hp = HP;
this.power = power;
this.defense = defense;
}
public int attack() { public int attack() {
return this.getPower(); return this.power;
} }
public boolean dameged(int enemypower) { public boolean damage(int enemyAttack) {
int damage = enemyAttack - this.defense; //ダメージ量の計算
boolean isDead = false; if(damage <= 0) {
damage = 1; //計算結果が0以下ならダメージ量1にする
int damage = 0;
if (enemypower-this.getDefense()<0) {
damage = 1;
} else {
damage = enemypower-this.getDefense();
} }
if (this.getHP()-damage<0) { this.hp -= damage; //hpからダメージ量引いて残りをhpにする
this.setHP(0); boolean dead= false; //戦闘不能かどうかを真偽地を使って判断
isDead = true;
} else { if(this.hp <= 0) { //hpが0以下なら
this.setHP(this.getHP()-damage); this.hp = 0; //hpを0に補正
dead = true;
} }
System.out.println(this.getName()+"は"+damage+"のダメージを受けた。"); System.out.println(this.name + "は" + damage + "のダメージを受けた");
System.out.println(this.getName()+"の残り体力は"+this.getHP()+"。"); System.out.println(this.name + "の残りの体力は" + this.hp + "。");
if(isDead) {
System.out.println(this.getName()+"はちからつきた。");
}
System.out.println("↓");
return isDead; if(dead) { //戦闘不能の時
System.out.println(this.name + "はちからつきた。");
}
return dead;
} }
public String display() { public String Parameters() { //パラメーターを文字列で返す
String str = "名 前:"+this.getName()+"\n" return "名前:" + this.name + "\n" + "体力:" + this.hp + "\n" +
+"体 力:"+this.getHP()+"\n" "力" + this.power + "\n" + "耐久" + this.defense;
+" 力 :"+this.getPower()+"\n"
+"耐 久:"+this.getDefense();
return str;
} }
} }

View File

@@ -1,6 +1,6 @@
public class Dog extends Animal { public class Dog extends Animal{
public void Eat() { public void eat() {
System.out.println(this.getName()+"はドッグフードを食べました。"); System.out.println(getName() + "はドッグフードを食べました。");
} }
} }

View File

@@ -1,9 +1,6 @@
public class Hero extends Character { public class Hero extends Character{
public Hero() { public Hero(){
this.setName(""); super(25, 10, 7);
this.setHP(25);
this.setPower(10);
this.setDefense(7);
} }
} }

View File

@@ -1,25 +1,28 @@
public class Item { public class Item {
private String eName;
private int addDamage;
public Item(String eNmae, int addDamage) {
this.eName = eNmae;
this.addDamage = addDamage;
private String name;
private int add;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAdd() {
return add;
}
public void setAdd(int add) {
this.add = add;
} }
public Item(String name,int add) { public String geteNmae() {
this.setName(name); return eName;
this.setAdd(add);
} }
public void seteNmae(String eNmae) {
this.eName = eNmae;
}
public int getAddDamage() {
return addDamage;
}
public void setAddDamage(int addDamage) {
this.addDamage = addDamage;
}
} }

View File

@@ -3,12 +3,10 @@ public class Question13_1 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
Cat cat = new Cat(); Cat cat = new Cat();
cat.setName("タマ"); cat.setName("タマ");
cat.Run(); cat.run();
cat.Eat(); cat.eat();
} }
} }

View File

@@ -3,12 +3,10 @@ public class Question13_2 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
Dog dog = new Dog(); Dog dog = new Dog();
dog.setName("ポチ"); dog.setName("ポチ");
dog.Run(); dog.run();
dog.Eat(); dog.eat();
} }
} }

View File

@@ -1,13 +1,9 @@
public class Question13_3 { public class Question13_3 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
Hero hero = new Hero(); Hero hero = new Hero();
hero.setName("勇者"); hero.setName("勇者");
System.out.println(hero.display()); System.out.println(hero.Parameters());
} }
} }

View File

@@ -3,11 +3,9 @@ public class Question13_4 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
Slime slime = new Slime(); Slime slime = new Slime();
slime.setName("スライム"); slime.setName("スライム");
System.out.println(slime.display()); System.out.println(slime.Parameters());
} }
} }

View File

@@ -3,26 +3,24 @@ public class Question13_5 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
Hero hero = new Hero(); Hero hero = new Hero();
hero.setName("勇者"); hero.setName("勇者");
// System.out.println(hero.display());
Slime slime = new Slime(); Slime slime = new Slime();
slime.setName("スライム"); slime.setName("スライム");
// System.out.println(slime.display());
while (true) { while(true) {
if ( slime.dameged(hero.attack()) ) { //勇者の攻撃
System.out.println(hero.getName()+"は"+slime.getName()+"との戦闘に勝利した"); boolean slimedead = slime.damage(10); //スライムがダメージを受ける
//スライムの戦闘不能判断
if(slimedead == true) {
System.out.println("勇者はスライムとの戦闘に勝利した");
break; break;
} }
if ( hero.dameged(slime.attack()) ) { boolean herodead = hero.damage(5);
System.out.println(slime.getName()+"は"+hero.getName()+"との戦闘に勝利した"); if(herodead == true) {
System.out.println("勇者はスライムとの戦闘に敗北した");
break; break;
} }
} }
} }
} }

View File

@@ -3,19 +3,17 @@ public class Question13_6 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
SuperHero sHero = new SuperHero();
SuperHero superhero = new SuperHero(); sHero.setName("勇者(装備あり)");
superhero.setName("勇者(装備あり)");
System.out.println(superhero.display());
Slime slime = new Slime(); Slime slime = new Slime();
slime.setName("スライム");
Item item = new Item("こんぼう",5); Item item = new Item("こんぼう", 5);
superhero.setItem(item); sHero.setItem(item);
System.out.println(superhero.attack()); int damage = sHero.attack();
System.out.println(damage);
} }
} }

Some files were not shown because too many files have changed in this diff Show More