728x90

 

sql의 테이블 확인하고 

vo의 필드(전역변수) 세팅

필요한 값들을 필드에 넣기

 

package com.kh.test.model;

import java.sql.Date;

public class Test {
	
	public int seq;
	public String writer;
	public String title;
	public String content;
	public Date regDate;
	
	public Test() {}

	public Test(int seq, String writer, String title, String content, Date regDate) {
		super();
		this.seq = seq;
		this.writer = writer;
		this.title = title;
		this.content = content;
		this.regDate = regDate;
	}

	
	public int getSeq() {
		return seq;
	}

	public void setSeq(int seq) {
		this.seq = seq;
	}

	public String getWriter() {
		return writer;
	}

	public void setWriter(String writer) {
		this.writer = writer;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public Date getRegDate() {
		return regDate;
	}

	public void setRegDate(Date regDate) {
		this.regDate = regDate;
	}
	
	

}
728x90
반응형
728x90

 

 

실행 클래스(런파일, 메인메소드)

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);
	}	
}

 

728x90
반응형

+ Recent posts