TestSilsub2
package com.kh.silsub2.main;
import com.kh.silsub2.example.Munjae2;
public class TestSilsub2 {
public static void main(String[] args) {
Munjae2 test = new Munjae2();
//test.sample1();
//test.sample2();
//test.sample3();
//test.sample4();
//test.sample5();
test.sample6();
}
}
MunJae2
package com.kh.silsub2.example;
import java.util.Scanner;
public class Munjae2 {
public void sample1() {
Scanner sc = new Scanner(System.in);
System.out.print("정수를 하나 입력하세요 : ");
int num = sc.nextInt();
if(num >= 1 && num <= 10) {
if(num % 2 == 0) {
System.out.println("짝수다.");
}else {
System.out.println("홀수다.");
}
}else {
System.out.println("반드시 1~10사이의 정수를 입력해야 합니다.");
}
}
public void sample2() {
Scanner sc = new Scanner(System.in);
System.out.print("키 : ");
double height = sc.nextDouble();
System.out.print("몸무게 : ");
double weight = sc.nextDouble();
double bmi = weight / (height * height);
if(bmi >= 30) {
System.out.println("비만");
}else if(bmi >= 25) {
System.out.println("과체중");
}else if(bmi >= 20) {
System.out.println("정상체중");
}else {
System.out.println("저체중");
}
}
public void sample3() {
Scanner sc = new Scanner(System.in);
System.out.print("첫 번째 정수를 입력하세요 : ");
int num1 = sc.nextInt();
System.out.print("두 번째 정수를 입력하세요 : ");
int num2 = sc.nextInt();
System.out.print("연산자을 입력하세요 : ");
char ch = sc.next().charAt(0);
int plus = num1 + num2;
int minus = num1 - num2;
int multi = num1 * num2;
int div = num1 / num2;
int mod = num1 % num2;
switch(ch) {
case '+': System.out.printf("%d + %d = %d", num1, num2, plus); break;
case '-': System.out.printf("%d - %d = %d", num1, num2, minus); break;
case '*': System.out.printf("%d * %d = %d", num1, num2, multi); break;
case '/': System.out.printf("%d / %d = %d", num1, num2, div); break;
case '%': System.out.printf("%d %% %d = %d", num1, num2, mod); break;
default: System.out.println("입력하신 연산은 없습니다.\n프로그램을 종료합니다."); return;
}
}
public void sample4() {
Scanner sc = new Scanner(System.in);
System.out.print("과일 이름 입력 : ");
String str = sc.nextLine();
int price;
switch(str) {
case "사과": price = 1000; break;
case "바나나": price = 3000; break;
case "복숭아": price = 2000; break;
case "키위": price = 5000; break;
default : System.out.println("없는 과일 입니다."); return;
}
System.out.printf("%s의 가격은 %d원 입니다.", str, price);
}
public void sample5() {
Scanner sc = new Scanner(System.in);
System.out.print("국어 점수 : ");
int lag = sc.nextInt();
System.out.print("영어 점수 : ");
int eng = sc.nextInt();
System.out.print("수학 점수 : ");
int math = sc.nextInt();
int sum = lag + eng + math;
int avg = sum / 3;
if(avg >= 60) {
if(lag >= 40 && eng >= 40 && math >= 40) {
System.out.println("합격입니다.");
}else {
if(lag < 40 && eng >= 40 && math >= 40) {
System.out.println("국어 과목의 점수 미달로 불합격 입니다.");
}else if(lag <= 40 && eng < 40 && math >= 40) {
System.out.println("영어 과목의 점수 미달로 불합격 입니다.");
}else {
System.out.println("수학 과목의 점수 미달로 불합격 입니다.");
}
}
}else {
System.out.println("평균점수 미달로 불합격 입니다.");
}
/* if(avg < 60){
* System.out.println("평균점수 미달로 불합격 입니다.");
* }else if(lag < 40){
*
* }
* */
}
public void sample6() {
Scanner sc = new Scanner(System.in);
System.out.print("월 급여액 : ");
int salary = sc.nextInt();
System.out.print("월 매출액 : ");
int sales = sc.nextInt();
System.out.println("==================");
double bonus;
double bprice;
if(sales >= 50000000) {
bonus = 0.05;
}else if(sales >= 30000000) {
bonus = 0.03;
}else if(sales >= 10000000) {
bonus = 0.01;
}else {
bonus = 0;
}
System.out.printf("매출액 : %d\n", sales);
System.out.println("보너스율 : " + (int)(bonus * 100) + "%");
System.out.printf("월 급여 : %d\n", salary);
bprice = sales * bonus; //보너스금액
System.out.printf("보너스 금액 : %.0f\n", bprice);
System.out.println("==================");
salary = (int)((sales * bonus) + salary);
System.out.printf("총 급여 : %d\n", salary);
}
}
'JAVA > 이론 정리 및 예제' 카테고리의 다른 글
[JAVA/자바] #4_1 배열 / 예제 (0) | 2021.09.05 |
---|---|
[JAVA/자바] #3_6 제어문 실습 (0) | 2021.09.05 |
[JAVA/자바] #3_4 실습문제 (0) | 2021.09.05 |
[JAVA/자바] #3_3 분기문 / 예제 (0) | 2021.09.05 |
[JAVA/자바] #3_2 반복문 / 예제 (0) | 2021.09.05 |