package com.kh.example.practice4.run;
import com.kh.example.practice4.model.vo.Book;
public class Run {
public static void main(String[] args) {
Book b1 = new Book();
// b1.inform();
Book b2 = new Book("책1","출판사1","저자1");
// b2.inform();
Book b3 = new Book("책2","출판사2","저자2",10000,0.3);
b3.inform();
}
}
기능 클래스
package com.kh.example.practice4.model.vo;
public class Book {
private String title;
private String publisher;
private String author;
private int price;
private double discountRate;
// 기본 생성자
public Book() {
}
// 매개변수 3개인 생성자
public Book(String title, String publisher, String author) {
this.title = title; // 값넣기까지 초기화 // 값을 대입시키는게 초기화
this.publisher = publisher;
this.author = author;
}
// 매개변수 5개인 생성자
public Book(String title, String publisher, String author,
int price, double discountRate) {
this.title = title;
this.publisher = publisher;
this.author = author;
// this(title,publisher,author); 위의 세줄과 같은 코드
this.price = price;
this.discountRate = discountRate;
}
public void inform() {
System.out.printf(" title : %s%n publisher : %s%n author : %s%n price : %d%n 할인율 : %f",title,publisher,author,price,discountRate);
}
}
public void test(){
// 사용자로부터 시작 숫자와 공차를 입력 받아
// 일정한 값으로 숫자가 커지거나 작아지는 프로그램을 구현하세요.
// 단, 출력되는 숫자는 총 10개입니다 ( 공차 : 숫자들 사이에서 일정한 숫자의 차가 존재하는 것)
System.out.print("시작 숫자 : ");
int snum = sc.nextInt();
System.out.print("공차 : ");
int gnum = sc.nextInt();
int j = snum; // for문 안에서 돌면서 증가할 수의 변수
for(int i=0; i<10; i++) { // 총 0~9 i가 10번 반복
System.out.print(j+" ");
j += gnum;
}
import java.util.Scanner;
public class practice_everyday06 {
public static void main(String[] args) {
// 대문자
// hint : 아스키코드
// 65-90까지가 대문자
Scanner sc = new Scanner(System.in);
System.out.print("put in char 1ea : ");
char ch = sc.nextLine().charAt(0); // next**()중에 char값 받는 메소드는 없는듯
System.out.println("Is it capital ? " + (ch >= 'A' && ch <= 'Z'));// 문자 자동으로 순서
System.out.print("Will you continue? If you want, press Y or y : ");
char yn = sc.nextLine().charAt(0); // 메소드 체인이라고 부름
System.out.println("Hello");
}
}