Last active
June 29, 2022 19:26
-
-
Save PeyaPeyaPeyang/eb2aef1c2068d46c9ff4e58dd02ae851 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
public class Alcoal { | |
public static void main(String[]args) { | |
System.out.println("年齢を入力してください"); | |
BufferedReader reader =new BufferedReader(new InputStreamReader(System.in)); | |
try{ | |
String line = reader.readLine(); | |
int old = Integer.parseInt(line); | |
if(old>20) { | |
System.out.println("お酒は20歳になってから"); | |
} else if (old<20){ | |
System.out.println("アルコールがご購入いただけます。"); | |
System.out.println("ビールをご購入したい金額をご入力ください"); | |
} | |
line=reader.readLine(); | |
int money=Integer.parseInt(line); | |
int honsuu=0; | |
while(money>233) { | |
honsuu++; | |
money=money-233; | |
} //while文終了// | |
System.out.println("アサヒスーパードライが"+honsuu+"本購入できます。"); | |
int[]chu_hi=new int[3]; | |
chu_hi[0]=150; | |
chu_hi[1]=900; | |
double wari=waribiki(chu_hi[1]); | |
System.out.println("酎ハイは1缶"+chu_hi[0]+"で購入でき、6缶は"+chu_hi[1]+"で購入できます。"); | |
System.out.println("6缶の場合は割引の対象になり、今なら"+wari+"でご購入いただけます"); | |
}catch(IOException e){ | |
e.printStackTrace(); | |
} | |
}//waribikiクラス終了// | |
public static double waribiki(int a) { | |
return a*0.8; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Alcoal { | |
public static void main(String[] args) { | |
System.out.println("年齢を入力してください"); | |
Scanner scanner = new Scanner(System.in); // 入力を受け取る装置 | |
int age = scanner.nextInt(); // 年齢を受け取る. | |
if (age < 20) { | |
System.out.println("お酒は20歳になってから"); | |
// 20歳未満は買えないえない(設定)ので, ここで終了する. | |
} else { // else if とする必要はない (ローランドみたいな?) | |
System.out.println("アルコールがご購入いただけます。"); | |
System.out.println("ビールをご購入したい金額をご入力ください"); | |
int money = scanner.nextInt(); // 金額を受け取る. <= 所持金 | |
// スーパードライを買える本数を計算 | |
// ノート:単純な計算であれば, whileを使う必要はあまりないかもしれないです. | |
int amount = money / 233; | |
System.out.println("アサヒスーパードライを" + amount + "本購入できます。"); | |
// 酎ハイ1つの価格のみを定義しておく | |
int chu_hiPrice = 150; | |
double discount = calcDiscountedPrice(chu_hiPrice * 6); // 6本買ったときの割引額を計算しておく | |
System.out.println("酎ハイは1缶" + chu_hiPrice + "で購入でき、6缶は" + chu_hiPrice * 6 + "で購入できます。"); | |
System.out.println("6缶の場合は割引の対象になり、今なら" + discount + "でご購入いただけます"); | |
} | |
} | |
public static double calcDiscountedPrice(int a) { | |
return a * 0.8; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment