Maya1991

Test115②

Jul 11th, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.92 KB | None | 0 0
  1. ▪️Test115.java
  2. package sc;
  3.  
  4. import java.io.*;
  5.  
  6. //String 型の変数 s に文字列を入力し、s の値を表示するプログラムを作成しなさい。
  7. public class Test115 {
  8.     // String 型変数 s に入力された1行分の文字列が得られる
  9.     static Human h;
  10.     static BufferedReader br;
  11.     static String name1;
  12.     static java.util.Scanner sc2;
  13.     static String s6;
  14.  
  15.     public static void main(String[] args) throws IOException {
  16.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  17.         java.util.Scanner sc2 = new java.util.Scanner(System.in);
  18.         // String s6 = sc2.nextLine();
  19.         System.out.println("あなたの名前を入力して下さい。");
  20.         String name1 = br.readLine();// 名前入力
  21.         h = new Human(name1);
  22.         // Human h = new Human(name1);
  23.         System.out.println(
  24.                 "ようこそ" + h.getName() + "さん\n あなたのポイントは" + h.point + "ポイントです\nこれから英語の問題を出します。\nポイントを集めて下さい( ´ ▽ ` )ノ");
  25.         // String s = br.readLine();// 1行分の文字列を入力する
  26.         // System.out.println(s);
  27.         System.out.println("海藻は英語で?");
  28.         String s1 = br.readLine();
  29.         if (s1.equals("seaweed")) {
  30.             System.out.println("正解");
  31.             h.point++;
  32.         } else {
  33.             System.out.println("不正解");
  34.         }
  35.         System.out.println("カワハギは英語で?");
  36.         String s2 = br.readLine();
  37.         if (s2.equals("filefish")) {
  38.             System.out.println("正解");
  39.             h.point++;
  40.         } else {
  41.             System.out.println("不正解");
  42.         }
  43.  
  44.         System.out.println("サバは英語で?");
  45.         System.out.println("1:needlefish 2:seerfish 3:mackerel 4:smelt");
  46.         // 文字列を数字に変換する
  47.         int s3 = Integer.parseInt(br.readLine());
  48.         if (s3 == 1) {
  49.             System.out.println("不正解");
  50.         } else if (s3 == 2) {
  51.             System.out.println("不正解");
  52.         } else if (s3 == 3) {
  53.             System.out.println("正解");
  54.             h.point++;
  55.         } else {
  56.             System.out.println("不正解");
  57.         }
  58.         System.out.println("ナマズは英語で?");
  59.         String s4 = br.readLine();
  60.         if (s4.equals("catfish")) {
  61.             System.out.println("正解");
  62.             h.point++;
  63.         } else {
  64.             System.out.println("不正解");
  65.  
  66.         }
  67.         System.out.println("ヒラメは英語で?");
  68.         java.util.Scanner sc = new java.util.Scanner(System.in);
  69.         String s5 = sc.nextLine();
  70.         if (s5.equals("flatfish")) {
  71.             System.out.println("正解");
  72.             h.point++;
  73.         } else {
  74.             System.out.println("不正解");
  75.         }
  76.         Test(h);
  77.         System.out.println("あなたのポイントは" + h.point + "ポイントになりました♡₍₍ ◝(・ω・)◟ ⁾⁾♡");
  78.  
  79.     }
  80.  
  81.     static void Test(Human h) {
  82.         // BufferedReader br = new BufferedReader(new
  83.         // InputStreamReader(System.in));
  84.         // java.util.Scanner sc2 = new java.util.Scanner(System.in);
  85.         // Human h = new Human("test");
  86.         System.out.println("マンボウは英語で?");
  87.         String s6 = sc2.nextLine();
  88.         if (s6.equals("sunfish")) {
  89.             System.out.println("正解");
  90.  
  91.             h.point++;
  92.         } else {
  93.             System.out.println("不正解");
  94.         }
  95.     }
  96.  
  97. }
  98.  
  99. ▪️Human.java
  100. package sc;
  101.  
  102. public class Human {
  103.     private String name;
  104.     int point;
  105.  
  106.     Human(String name) {
  107.         this.name = name;
  108.         this.point = 0;
  109.     }
  110.  
  111.     public String getName() {
  112.         return this.name;
  113.     }
  114.  
  115. }
  116.  
  117. ▪️Error
  118. あなたの名前を入力して下さい。
  119.  
  120. ようこそさん
  121.  あなたのポイントは0ポイントです
  122. これから英語の問題を出します。
  123. ポイントを集めて下さい( ´ ▽ ` )ノ
  124. 海藻は英語で?
  125.  
  126. 不正解
  127. カワハギは英語で?
  128.  
  129. 不正解
  130. サバは英語で?
  131. 1:needlefish 2:seerfish 3:mackerel 4:smelt
  132.  
  133. Exception in thread "main" java.lang.NumberFormatException: For input string: ""
  134.     at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
  135.     at java.lang.Integer.parseInt(Integer.java:592)
  136.     at java.lang.Integer.parseInt(Integer.java:615)
  137.     at sc.Test115.main(Test115.java:46)
Advertisement
Add Comment
Please, Sign In to add comment