심플 계산기 II
페이지 정보
작성자 최고관리자 작성일 70-01-01 09:00 조회 374 댓글 0본문
SalesAnalyzer.java
[code=php]
import java.util.ArrayList;
import java.util.Random;
public class SalesAnalyzer {
// 주문 리스트
private ArrayList<Ramyun> ramyunOrders;
private ArrayList<Kimbob> kimbobOrders;
private ArrayList<Topokki> topokkiOrders;
private ArrayList<Twigim> twigimOrders;
private ArrayList<Sundae> sundaeOrders;
private ArrayList<Mandu> manduOrders;
private ArrayList<Odeng> odengOrders;
public SalesAnalyzer() {
this.ramyunOrders = new ArrayList<Ramyun>();
this.kimbobOrders = new ArrayList<Kimbob>();
this.topokkiOrders = new ArrayList<Topokki>();
this.twigimOrders = new ArrayList<Twigim>();
this.sundaeOrders = new ArrayList<Sundae>();
this.manduOrders = new ArrayList<Mandu>();
this.odengOrders = new ArrayList<Odeng>();
}
// 메인 테스트
public static void main(String[] args) {
SalesAnalyzer sales = new SalesAnalyzer();
// 랜덤 주문 생성.
sales.randomOrders();
// 매출 계산.
int totalSales = sales.calculateSales();
System.out.println("총 매출액: " + totalSales + "원");
}
// 랜덤 주문 생산기
public void randomOrders() {
Random random = new Random();
int n = 51 + random.nextInt(50);
for (int i = 0; i < n; i++) {
switch (random.nextInt(7)) {
case 0:
addRamyunOrder(new Ramyun());
break;
case 1:
addKimbobOrder(new Kimbob());
break;
case 2:
addTopokkiOrder(new Topokki());
break;
case 3:
addTwgimOrder(new Twigim());
break;
case 4:
addSundaeOrder(new Sundae());
break;
case 5:
addManduOrder(new Mandu());
break;
case 6:
addOdengOrder(new Odeng());
break;
}
}
}
// 라면 주문 기록
public void addRamyunOrder(Ramyun ramyun) {
ramyunOrders.add(ramyun);
}
// 김밥 주문 기록
public void addKimbobOrder(Kimbob kimbob) {
kimbobOrders.add(kimbob);
}
// 떡복이 주문 기록
public void addTopokkiOrder(Topokki topokki) {
topokkiOrders.add(topokki);
}
// 튀김 주문 기록
public void addTwgimOrder(Twigim twigim) {
twigimOrders.add(twigim);
}
// 순대 주문 기록
public void addSundaeOrder(Sundae sundae) {
sundaeOrders.add(sundae);
}
// 만두 주문 기록
public void addManduOrder(Mandu mandu) {
manduOrders.add(mandu);
}
// 오뎅 주문 기록
public void addOdengOrder(Odeng odeng) {
odengOrders.add(odeng);
}
// 매출 계산
public int calculateSales() {
int raCount = ramyunOrders.size();
int kimCount = kimbobOrders.size();
int toCount = topokkiOrders.size();
int twiCount = twigimOrders.size();
int sunCount = sundaeOrders.size();
int manCount = manduOrders.size();
int oCount = odengOrders.size();
int raSales = Ramyun.PRICE * raCount;
int kimSales = Kimbob.PRICE * kimCount;
int toSales = Topokki.PRICE * toCount;
int sunSales = Sundae.PRICE * sunCount;
int twiSales = Twigim.PRICE * twiCount;
int manSales = Mandu.PRICE * manCount;
int oSales = Odeng.PRICE * oCount;
int totalSales = raSales + kimSales + toSales + sunSales + twiSales
+ manSales + oSales;
System.out.printf("[라면] %d개: %d원\n", raCount, raSales);
System.out.printf("[김밥] %d개: %d원\n", kimCount, kimSales);
System.out.printf("[떡볶이] %d개: %d원\n", toCount, toSales);
System.out.printf("[튀김] %d개: %d원\n", twiCount, twiSales);
System.out.printf("[순대] %d개: %d원\n", sunCount, sunSales);
System.out.printf("[만두] %d개: %d원\n", manCount, manSales);
System.out.printf("[오뎅] %d개: %d원\n", oCount, oSales);
System.out.println("==================");
return totalSales;
}
}
[/code]
Ramyun.java
[code=php]
public class Ramyun {
public static final String NAME = "라면";
public static final int PRICE = 3000;
}
[/code]
Kimbob.java
[code=php]
public class Kimbob {
public static final String NAME = "김밥";
public static int PRICE = 2000;
}
[/code]
Topokki.java
[code=php]
public class Topokki {
public static final String NAME = "떡볶이";
public static int PRICE = 2000;
}
[/code]
Twigim.java
[code=php]
public class Twigim {
public static final String NAME = "튀김";
public static int PRICE = 2000;
}
[/code]
Sundae.java
[code=php]
public class Sundae {
public static final String NAME = "순대";
public static int PRICE = 2000;
}
[/code]
Mandu.java
[code=php]
public class Mandu {
public static final String NAME = "만두";
public static int PRICE = 2500;
}
[/code]
Odeng.java
[code=php]
public class Odeng {
public static final String NAME = "오뎅";
public static int PRICE = 2500;
}
[/code]
[code=php]
import java.util.ArrayList;
import java.util.Random;
public class SalesAnalyzer {
// 주문 리스트
private ArrayList<Ramyun> ramyunOrders;
private ArrayList<Kimbob> kimbobOrders;
private ArrayList<Topokki> topokkiOrders;
private ArrayList<Twigim> twigimOrders;
private ArrayList<Sundae> sundaeOrders;
private ArrayList<Mandu> manduOrders;
private ArrayList<Odeng> odengOrders;
public SalesAnalyzer() {
this.ramyunOrders = new ArrayList<Ramyun>();
this.kimbobOrders = new ArrayList<Kimbob>();
this.topokkiOrders = new ArrayList<Topokki>();
this.twigimOrders = new ArrayList<Twigim>();
this.sundaeOrders = new ArrayList<Sundae>();
this.manduOrders = new ArrayList<Mandu>();
this.odengOrders = new ArrayList<Odeng>();
}
// 메인 테스트
public static void main(String[] args) {
SalesAnalyzer sales = new SalesAnalyzer();
// 랜덤 주문 생성.
sales.randomOrders();
// 매출 계산.
int totalSales = sales.calculateSales();
System.out.println("총 매출액: " + totalSales + "원");
}
// 랜덤 주문 생산기
public void randomOrders() {
Random random = new Random();
int n = 51 + random.nextInt(50);
for (int i = 0; i < n; i++) {
switch (random.nextInt(7)) {
case 0:
addRamyunOrder(new Ramyun());
break;
case 1:
addKimbobOrder(new Kimbob());
break;
case 2:
addTopokkiOrder(new Topokki());
break;
case 3:
addTwgimOrder(new Twigim());
break;
case 4:
addSundaeOrder(new Sundae());
break;
case 5:
addManduOrder(new Mandu());
break;
case 6:
addOdengOrder(new Odeng());
break;
}
}
}
// 라면 주문 기록
public void addRamyunOrder(Ramyun ramyun) {
ramyunOrders.add(ramyun);
}
// 김밥 주문 기록
public void addKimbobOrder(Kimbob kimbob) {
kimbobOrders.add(kimbob);
}
// 떡복이 주문 기록
public void addTopokkiOrder(Topokki topokki) {
topokkiOrders.add(topokki);
}
// 튀김 주문 기록
public void addTwgimOrder(Twigim twigim) {
twigimOrders.add(twigim);
}
// 순대 주문 기록
public void addSundaeOrder(Sundae sundae) {
sundaeOrders.add(sundae);
}
// 만두 주문 기록
public void addManduOrder(Mandu mandu) {
manduOrders.add(mandu);
}
// 오뎅 주문 기록
public void addOdengOrder(Odeng odeng) {
odengOrders.add(odeng);
}
// 매출 계산
public int calculateSales() {
int raCount = ramyunOrders.size();
int kimCount = kimbobOrders.size();
int toCount = topokkiOrders.size();
int twiCount = twigimOrders.size();
int sunCount = sundaeOrders.size();
int manCount = manduOrders.size();
int oCount = odengOrders.size();
int raSales = Ramyun.PRICE * raCount;
int kimSales = Kimbob.PRICE * kimCount;
int toSales = Topokki.PRICE * toCount;
int sunSales = Sundae.PRICE * sunCount;
int twiSales = Twigim.PRICE * twiCount;
int manSales = Mandu.PRICE * manCount;
int oSales = Odeng.PRICE * oCount;
int totalSales = raSales + kimSales + toSales + sunSales + twiSales
+ manSales + oSales;
System.out.printf("[라면] %d개: %d원\n", raCount, raSales);
System.out.printf("[김밥] %d개: %d원\n", kimCount, kimSales);
System.out.printf("[떡볶이] %d개: %d원\n", toCount, toSales);
System.out.printf("[튀김] %d개: %d원\n", twiCount, twiSales);
System.out.printf("[순대] %d개: %d원\n", sunCount, sunSales);
System.out.printf("[만두] %d개: %d원\n", manCount, manSales);
System.out.printf("[오뎅] %d개: %d원\n", oCount, oSales);
System.out.println("==================");
return totalSales;
}
}
[/code]
Ramyun.java
[code=php]
public class Ramyun {
public static final String NAME = "라면";
public static final int PRICE = 3000;
}
[/code]
Kimbob.java
[code=php]
public class Kimbob {
public static final String NAME = "김밥";
public static int PRICE = 2000;
}
[/code]
Topokki.java
[code=php]
public class Topokki {
public static final String NAME = "떡볶이";
public static int PRICE = 2000;
}
[/code]
Twigim.java
[code=php]
public class Twigim {
public static final String NAME = "튀김";
public static int PRICE = 2000;
}
[/code]
Sundae.java
[code=php]
public class Sundae {
public static final String NAME = "순대";
public static int PRICE = 2000;
}
[/code]
Mandu.java
[code=php]
public class Mandu {
public static final String NAME = "만두";
public static int PRICE = 2500;
}
[/code]
Odeng.java
[code=php]
public class Odeng {
public static final String NAME = "오뎅";
public static int PRICE = 2500;
}
[/code]
댓글목록 0
등록된 댓글이 없습니다.