Skip to content

Instantly share code, notes, and snippets.

@AuroraNorthernQuarter
Last active October 20, 2018 07:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AuroraNorthernQuarter/e369b74eb3ccf7d3eb550c0140c8264f to your computer and use it in GitHub Desktop.
Save AuroraNorthernQuarter/e369b74eb3ccf7d3eb550c0140c8264f to your computer and use it in GitHub Desktop.
package testprogramm;
import java.util.Scanner;
public class Sample {
private static final String yamaguchi = "山口県";
private static final String hyogo = "兵庫県";
private static final String kanagawa = "神奈川県";
public static void main(String[] args) {
System.out.println("都道府県名を入れてください。有名な港をご紹介します。");
Scanner scan = new Scanner(System.in);
String inputharbour = scan.next();
String name = getName(inputharbour);
String detail = getDetail(inputharbour);
System.out.println(name + "->" + detail);
scan.close();
}
/**
* 港名を出す
* @param harbour 港名
* @return 港の名前
*/
private static String getName(String harbour){
String name;
switch(harbour){
case yamaguchi:
name = "山口県";
break;
case hyogo:
name = "兵庫県";
break;
case kanagawa:
name = "神奈川県";
break;
default:
name = "その他の県は準備中";
}
return name;
}
/**
* 件名に紐づいた港の特徴を返す
* @param harbour
* @return 港名
*/
private static String getDetail(String harbour){
String detail;
switch(harbour){
case yamaguchi:
detail = "門司港";
break;
case hyogo:
detail = "神戸港";
break;
case kanagawa:
detail = "横浜港";
break;
default:
detail = "準備中";
}
return detail;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment