KDT/Java

240104 Java

001cloudid 2024. 1. 4. 17:41
728x90

package test;

 

public class Exam {

 

public static void main(String[] args) {

//1) 알파벳 대문자 A~Z까지 출력하는 프로그램 작성

// char a = 'A';

// System.out.println((int)a); //65

// char f = 'F';

// System.out.println((int)f);//70

 

for(int i =65; i<=70; i++) {

System.out.println((char)i);

}

 

System.out.println("====================");

 

//2) 정수 1~10까지 범위에서 홀수의 개수와 짝수의 개수

int even = 0;

int odd = 0;

 

for(int i = 1; i<=10; i++) {

if(i%2==0) {

even += 1;

} else {

odd += 1;

}

}

System.out.println("짝수의 개수 = " + even);

System.out.println("홀수의 개수 = " + odd);

 

 

 

 

 

 

 

}

}

A

B

C

D

E

F

====================

짝수의 개수 = 5

홀수의 개수 = 5

 

package test;

 

public class One {

 

//무게에 따른 요금 메소드 작성

public static int func1(int weight) {

if(weight<5) {

return 500;

} else if(weight<10) {

return 1000;

} else {

return 4000;

}

}

 

//상자 크기에 따른 요금 메소드 작성 : 상자 크기 = (가로*세로*높이)

public static int func2(int size) {

if(size<80) {

return 3500;

} else if(size<100) {

return 4500;

} else {

return 6000;

}

}

 

public static int delivery(int width, int length, int height, int weight) {

int size = width + length + height;

if(((width>=90)&&(length>=90)&&(height>=90))||(size>=160)||(weight>=25)){

return -1;

} else {

int price = size + weight;

return price;}

}

 

 

public static void main(String[] args) {

System.out.println("price = " + delivery(50, 50, 50, 10));

System.out.println("price = " + delivery(50, 90, 60, 5));

 

 

}

 

}

price = 160

price = -1

 

package test;

 

public class Customer {

int customerID;

String customerName;

int bonusPoint;

double bonusRatio;

 

Customer(int customerID,String customerName,int bonusPoint,double bonusRatio)

{

this.customerID = customerID;

this.customerName = customerName;

this.bonusPoint = bonusPoint;

this.bonusRatio = bonusRatio;

 

}

 

;

public int calc(int money) {

bonusRatio = 0.05;

bonusPoint = (int)(money * bonusRatio);

return bonusPoint;

}

 

 

public void showInfo(int money){

System.out.println("====할인율과 보너스 포인트 계산====");

System.out.println(customerName + "고객이 지불하신 금액 : " + money);

System.out.println(customerName + "고객의 보너스 포인트 적립율 : " + bonusRatio);

System.out.println(customerName + "고객의 적립된 보너스 포인트 : " + bonusPoint );

}

 

 

 

 

}

 

package test;

 

public class customer_Main {

 

public static void main(String[] args) {

Customer kim = new Customer(2000, "이자바", 0, 0.05);

kim.calc(10000);

kim.showInfo(10000);

 

}

 

}

====할인율과 보너스 포인트 계산====

이자바고객이 지불하신 금액 : 10000

이자바고객의 보너스 포인트 적립율 : 0.05

이자바고객의 적립된 보너스 포인트 : 500

 

728x90

'KDT > Java' 카테고리의 다른 글

240110 Java  (0) 2024.01.10
240108 Java  (0) 2024.01.08
240103 Java  (0) 2024.01.03
231228 Java  (0) 2023.12.28
231227 Java  (0) 2023.12.27