일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- 가변인자
- 다운캐스팅
- 자바
- 페이징
- 로또
- angular2
- 형변환
- 업캐스팅
- 전체
- 이클립스
- 전체텍스트
- 스프링
- Validations
- 추상클래스
- Login with OAuth Authentication
- 25가지 효율적인 sql작성법
- full text indexing
- Random
- 상속예제
- Full text
- 야구게임
- 전자정부
- while
- IBatis procedure
- 다형성
- 상속
- jquery
- 단축키
- 자바 야구게임
Archives
- Today
- Total
nalaolla
Method 예제 4 본문
728x90
반응형
- package test.com;
- public class Test04ScoreMain {
- public static void main(String[] args) {
- // Score 값 전달 객체를 만들고
- // 출력하시오. getters and setters 만들것
- System.out.println("============== Score =============");
- ScoreVO sv = new ScoreVO();
- sv.setName("KIM");
- sv.setKor(90);
- sv.setEng(88);
- sv.setMath(75);
- System.out.println("name : " + sv.getName());
- System.out.println("kor : " + sv.getKor());
- System.out.println("eng : " + sv.getEng());
- System.out.println("math : " + sv.getMath());
- System.out.println("total : " + sv.getTotal());
- System.out.println("avg : " + (int) (sv.getAvg() * 10) / 10d);
- System.out.println("grade : " + sv.getGrade());
- //sv 여러개 >>> svos : Test04ScoreVO[]
- //svo 3개짜리 배열을 만들고 임의의 값으로 저장 후 출력
- ScoreVO svos1 = new ScoreVO("KIM", 90, 95, 97);
- ScoreVO svos2 = new ScoreVO("PARK", 80, 83, 81);
- ScoreVO svos3 = new ScoreVO("LEE", 85, 83, 81);
- ScoreVO[] svos = new ScoreVO[]{svos1, svos2, svos3};
- System.out.println("============== Score array1 =============");
- for (int i = 0; i < svos.length; i++) {
- System.out.println(svos[i].getName());
- System.out.println(svos[i].getKor());
- System.out.println(svos[i].getEng());
- System.out.println(svos[i].getMath());
- System.out.println(svos[i].getTotal());
- System.out.println(svos[i].getAvg());
- System.out.println(svos[i].getGrade());
- }
- System.out.println("============== Member =============");
- MemberVO mv = new MemberVO();
- mv.setId("IDSSS");
- mv.setPw("0123");
- mv.setName("daniel kim");
- mv.setTel("010-1234-4567");
- System.out.println("num : " + mv.getNum());
- System.out.println("ID : " + mv.getId());
- System.out.println("PW : " + mv.getPw());
- System.out.println("name : " + mv.getName());
- System.out.println("tel : " + mv.getTel());
- MemberVO mv1 = new MemberVO();
- mv1.setId("IDSSS1");
- mv1.setPw("01231");
- mv1.setName("daniel kim1");
- mv1.setTel("010-1234-45671");
- MemberVO[] mvos = new MemberVO[3];
- mvos[0] = mv;
- mvos[1] = mv1;
- mvos[2] = mv1;
- mvos[0].setName("danielkim00");
- mvos[1].setName("danielkim01");
- mvos[2].setName("danielkim02");
- for (int i = 0; i < mvos.length; i++) {
- System.out.println(mvos[i].getName());
- }
- System.out.println("============== Board =============");
- BoardVO bv = new BoardVO();
- bv.setTitle("제목");
- bv.setContent("내용");
- bv.setWriter("김덕중");
- BoardVO bv1 = new BoardVO();
- bv1.setTitle("제목1");
- bv1.setContent("내용1");
- bv1.setWriter("김덕중1");
- BoardVO bv2 = new BoardVO();
- bv2.setTitle("제목2");
- bv2.setContent("내용2");
- bv2.setWriter("김덕중2");
- System.out.println("num : " + bv.getNum());
- System.out.println("title : " + bv.getTitle());
- System.out.println("content : " + bv.getContent());
- System.out.println("writer : " + bv.getWriter());
- System.out.println("date : " + bv.getRegDate());
- BoardVO[] bvs = new BoardVO[]{bv, bv1, bv2};
- for (int i = 0; i < bvs.length; i++) {
- System.out.println(bvs[i].getWriter());
- }
- }
- }
- package test.com;
- import java.util.Date;
- public class BoardVO {
- private int num;
- private String title;
- private String content;
- private String writer;
- private Date regDate;
- 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 String getWriter() {
- return writer;
- }
- public void setWriter(String writer) {
- this.writer = writer;
- }
- public int getNum() {
- return ++num;
- }
- public Date getRegDate() {
- Date today = new Date();
- return today;
- }
- }
- package test.com;
- public class MemberVO {
- private int num;
- private String id;
- private String pw;
- private String name;
- private String tel;
- public String getId() {
- return id;
- }
- public void setId(String id) {
- this.id = id;
- }
- public String getPw() {
- return pw;
- }
- public void setPw(String pw) {
- this.pw = pw;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getTel() {
- return tel;
- }
- public void setTel(String tel) {
- this.tel = tel;
- }
- public int getNum() {
- return ++num;
- }
- }
- package test.com;
- public class ScoreVO {
- private String name;
- private int kor;
- private int eng;
- private int math;
- private int total;
- private double avg;
- private String grade;
- private ScoreVO[] svos;
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public int getKor() {
- return kor;
- }
- public void setKor(int kor) {
- this.kor = kor;
- }
- public int getEng() {
- return eng;
- }
- public void setEng(int eng) {
- this.eng = eng;
- }
- public int getMath() {
- return math;
- }
- public void setMath(int math) {
- this.math = math;
- }
- public int getTotal() {
- total = this.kor + this.eng + this.math;
- return total;
- }
- public double getAvg() {
- avg = total / 3.0;
- return avg;
- }
- public String getGrade() {
- if (avg >= 90) {
- grade = "A";
- } else if(avg >= 80) {
- grade = "B";
- } else if(avg >= 70) {
- grade = "C";
- } else if(avg >= 60) {
- grade = "D";
- } else {
- grade = "Otehr";
- }
- return grade;
- }
- public ScoreVO(String name, int kor, int eng, int math) {
- this.name = name;
- this.kor = kor;
- this.eng = eng;
- this.math = math;
- }
- public ScoreVO() {
- }
- }
728x90
반응형
'JAVA > 9. Method2' 카테고리의 다른 글
Method 예제 2 (0) | 2016.06.22 |
---|---|
Method 예제 1 (0) | 2016.06.22 |