package edu.kh.oop.practice.model.service;
import edu.kh.oop.practice.model.vo.Book;
public class BookService {
public void practice() {
Book b1 = new Book();
Book b2 = new Book();
b1.setTitle("c언어");
b1.setPrice(30000);
b1.setDiscountRate(0.1);
b1.setAuthor("홍길동");
System.out.println(b1.toString());
System.out.println(b2.toString());
b2.setTitle("자바의 정석");
b2.setPrice(30000);
b2.setDiscountRate(0.2);
b2.setAuthor("남궁성");
System.out.println("수정된 결과 확인");
System.out.println(b1.toString());
System.out.println("도서명 = " + b1.getTitle());
System.out.printf("할인된 가격 = %.0f\n", (b1.getPrice() - (b1.getPrice() * b1.getDiscountRate())));
System.out.println("도서명 = " + b2.getTitle());
System.out.printf("할인된 가격 = %.0f\n", (b2.getPrice() - (b2.getPrice() * b2.getDiscountRate())));
}
}
package edu.kh.oop.practice.model.vo;
public class Book {
private String title ;
private int price ;
private double discountRate ;
private String author ;
public Book() {
this. title = title;
this.price = price;
this. discountRate = discountRate;
this. author = author;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public double getDiscountRate() {
return discountRate;
}
public void setDiscountRate(double discountRate) {
this.discountRate = discountRate;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
}
package edu.kh.oop.practice.run;
import edu.kh.oop.practice.model.service.BookService;
public class PraticeRun {
public static void main(String[] args) {
BookService b1 = new BookService();
b1.practice();
}
}
package com.kh.practice.snack.model.vo;
public class Snack {
public Snack() {}
private String kind ;
private String name ;
private String flaver;
private int numOf;
private int price;
public String getKind() {
return kind;
}
public void setKind(String kind) {
this.kind = kind;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getFlavor() {
return flaver;
}
public void setFlaver(String flaver) {
this.flaver = flaver;
}
public int getNumOf() {
return numOf;
}
public void setNumOf(int numOf) {
this.numOf = numOf;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public String information() {
return getKind() + getName() + getFlavor() + getNumOf() + getPrice();
}
package com.kh.practice.snack.controller;
import java.util.Scanner;
import com.kh.practice.snack.model.vo.Snack;
public class SnackController {
Scanner sc = new Scanner(System.in);
Snack s = new Snack();
public SnackController() {}
public String saveData(String kind, String name, String flavor, int numOf, int price) {
this.s.setKind(kind);
this.s.setName(name);
this.s.setFlaver(flavor);
this.s.setNumOf(numOf);
this.s.setPrice(price);
return "저장되었습니다\n";
}
public String confirmData() {
return s.getKind() + "(" + s.getName() + " - " + s.getFlavor() + ") " + s.getNumOf() +"개 "+ s.getPrice()+"원";
}
}
package com.kh.practice.snack.view;
import java.util.Scanner;
import com.kh.practice.snack.controller.SnackController;
public class SnackMenu {
public void menu() {
Scanner sc = new Scanner(System.in);
SnackController scr = new SnackController();
System.out.print("스낵류를 입력하세요");
System.out.println("종류 :");
String inputKind = sc.next();
System.out.println("이름 :");
String inputName = sc.next();
System.out.println("맛 :");
String inputFlavor = sc.next();
System.out.println("개수:");
String inputNumOf = sc.next();
System.out.println("가격 :");
String inputPrice = sc.next();
System.out.println(scr.saveData(inputKind, inputName, inputFlavor, inputNumOf, inputPrice));
char input1 = sc.next().charAt(0);
if(input1 == 'y') {
System.out.println(scr.confirmData());
}
}
}
package com.kh.practice.snack.run;
import com.kh.practice.snack.view.SnackMenu;
public class Run {
public static void main(String[] args) {
SnackMenu snack = new SnackMenu();
snack.menu();
}
}
이런 유용한 정보를 나눠주셔서 감사합니다.