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>
<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>
<natures>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</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) {
// 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;
diff = 6 - 2;
mulch = 6 * 2;
div = 6 / 2;
rem = 17 % 5;
int mulch = (6 * 2);
System.out.println(mulch);
System.out.println("変数sum:" + sum);
System.out.println("変数diff:" + diff);
System.out.println("変数mulch:" + mulch);
System.out.println("変数div:" + div);
System.out.println("変数rem:" + rem);
int div = (6 / 2);
System.out.println(div);
int rem = (17 % 5);
System.out.println(rem);
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -3,15 +3,16 @@ public class Question2_8 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
int money = 1000;
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) {
// TODO 自動生成されたメソッド・スタブ
int num = 100;
if ( num == 100 ) {
//設問1
int num;
num = 100;
if(num == 100) {
System.out.println("条件に合致しました");
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

@@ -3,13 +3,12 @@ public class Question4_2 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
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) {
// TODO 自動生成されたメソッド・スタブ
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);
if ( num==5 ) {
break;
}
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -3,23 +3,9 @@ public class Question6_6 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
StringBuilder square = new StringBuilder();
for ( int i=0 ; i<5 ; i++ ) {
square.append('\u25A0'); // ■ = \u25A0
for(int i = 0; i < 5; i++) {
System.out.println("■■■■■");
}
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) {
// TODO 自動生成されたメソッド・スタブ
StringBuilder sb = new StringBuilder();
for ( int i=1 ; i<=9 ; i++ ) {
for ( int j=1 ; j<=9 ; j++ ) {
if ( j>=2 ) {
sb.append(" "); // *2以降には空白を追加する
for(int i = 1; i <= 9; i++) {
for(int j = 1; j <= 9; j++) {
System.out.printf("%2d",i * j);
}
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) {
// TODO 自動生成されたメソッド・スタブ
int nums[] = new int[5];
nums[0] = 1;
nums[1] = 3;
nums[2] = 5;
nums[3] = 7;
nums[4] = 9;
int[] nums = {1, 3, 5, 7, 9};
System.out.println(nums[1]);
}
}

View File

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

View File

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

View File

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

View File

@@ -3,14 +3,13 @@ public class Question7_4 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
int nums[] = new int[1000];
for ( int i=1 ; i<=nums.length ; i++ ) {
nums[i-1] = i;
System.out.println(nums[i-1]);
int[] nums = new int[1000];
for(int i = 0; i < 1000; i++) {
nums[i] = 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) {
// TODO 自動生成されたメソッド・スタブ
String[] str = {"森","山","沼","島","平地"};
int num = (int)( Math.random()*5 );
String[] str = {"森", "山", "沼", "島", "平地"};
int num = (int)(Math.random()*5);
System.out.println(str[num]);
}
}

View File

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

View File

@@ -3,17 +3,26 @@ public class Question7_7 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
String[][] table = {
{"国語","社会","国語","理科","社会"},
{"英語","数学","英語","数学","国語"},
{"理科","国語","理科","国語","理科"},
{"社会","社会","数学","社会","数学"},
{"数学","英語","英語","理科","英語"}
String[][] timetable = {
{"国語", "社会", "国語", "理科", "社会"},
{"英語", "数学", "英語", "数学", "国語"},
{"理科", "国語", "理科", "国語" ,"理科"},
{"社会", "社会", "数学", "社会", "数学"},
{"数学", "英語", "英語", "理科", "英語"},
};
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) {
// TODO 自動生成されたメソッド・スタブ
int[][] array = {
{1,3,5,7},
{11,13,17,19,23,29}
int[][] nums = {
{1, 3, 5, 7},
{11, 13, 17, 19, 23, 29}
};
for ( int i=0 ; i<array.length ; i++) {
for ( int j=0 ; j<array[i].length ; j++ ) {
System.out.println(array[i][j]);
for(int i = 0; i < nums.length; i++) {
for(int j = 0; j < nums[i].length; j++) {
System.out.println(nums[i][j]);
}
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -3,8 +3,8 @@ public class Question10_3 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
Student student = new Student();
student.studentId = 10;
student.name = "田中二郎";
student.mail = "test@mail.com";
@@ -13,8 +13,7 @@ public class Question10_3 {
System.out.println(student.studentId);
System.out.println(student.name);
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) {
// TODO 自動生成されたメソッド・スタブ
Calculation cal = new Calculation();
Calculation calculation = new Calculation();
calculation.baseNum = 100;
calculation.add(100);
cal.baseNum = 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) {
// TODO 自動生成されたメソッド・スタブ
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) {
// TODO 自動生成されたメソッド・スタブ
Car car = new Car();
car.color = "赤";
car.gasoline = 50;
int goal = 300;
int totaldistance = 0;
int time = 0;
int distance = 300;
int nRuns = 0;
while (true) {
distance -= car.run();
nRuns++;
if (car.gasoline<0) {
System.out.println(car.color+"色の車は、目的地に到達できませんでした。");
break;
}
if (distance<=0) {
System.out.println(car.color+"色の車は、目的地にまで"+nRuns+"時間かかりました。残りのガソリンは、"+car.gasoline+"リットルです。");
while(totaldistance < goal) {
int y = car.run();
if(y == -1) {
System.out.println(car.color + "色の車は目的地に到達できませんでした");
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) {
// TODO 自動生成されたメソッド・スタブ
User[] userList = new User[3];
User user1 = new User();
User user2 = new User();
User user3 = new User();
@@ -21,13 +19,9 @@ public class Question10_7 {
userList[1] = user2;
userList[2] = user3;
// for (int i=0;i<userList.length;i++) {
// userList[i].printProfile();
// }
for (User user:userList) {
user.printProfile();
for(int i = 0; i < 3; i++) {
userList[i].printProfile();
}
}
}

View File

@@ -3,39 +3,44 @@ public class Question10_8 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
Car[] carList = new Car[3];
Car car1 = new Car();
car1.color = "赤";
car1.gasoline = 50;
Car car2 = new Car();
car2.color = "青";
car2.gasoline = 60;
Car car3 = new Car();
car3.color = "黄";
car3.gasoline = 70;
carList[0] = car1;
carList[1] = car2;
carList[2] = car3;
Car[] cars = new Car[3];
cars[0] = car1;
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;
}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 {
int studentId;
String name, mail, password;
String name;
String mail;
String password;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -3,13 +3,11 @@ public class Question11_3 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
Cat cat1 = new Cat();
System.out.println(cat1.name);
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) {
// TODO 自動生成されたメソッド・スタブ
Student student = new Student();
student.name = "太郎";
student.group = "A";
student.teacher = "山田";
Student.group= "A";
Student.teacher = "山田";
student.studentProfile();
student.groupProfile();
Student.groupProfile();
}
}

View File

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

View File

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

View File

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

View File

@@ -1,16 +1,16 @@
public class User {
String name;
Wallet wallet;
public void useMoney( int money ) {
this.wallet.money = this.wallet.money - money;
System.out.println(this.name+"は財布の中のお金を"+money+"円使用しました");
public void useMoney(int money) {
this.wallet.money -= money;
System.out.println(this.name + "は財布の中のお金を" +
money + "円使用しました");
}
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 {
int money;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,25 +1,28 @@
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) {
this.setName(name);
this.setAdd(add);
public String geteNmae() {
return eName;
}
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) {
// TODO 自動生成されたメソッド・スタブ
Cat cat = new Cat();
cat.setName("タマ");
cat.Run();
cat.Eat();
cat.run();
cat.eat();
}
}

View File

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

View File

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

View File

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

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