728x90

 

 

 

728x90
반응형
728x90

 

 

 

실행 클래스

package com.kh.example.practice5.run;

import com.kh.example.practice5.model.vo.Employee;

public class Run {
	public static void main(String[] args) {

		Employee e = new Employee();
		e.setEmpNo(100);
		e.setEmpName("홍길동");
		e.setDept("영업부");
		e.setJob("과장");
		e.setAge(25);
		e.setGender('남');
		e.setSalary(2500000);
		e.setBonusPoint(0.05);
		e.setPhone("010-1234-5678");
		e.setAddress("서울시 강남구");
				
		e.getEmpNo();
		e.getEmpName();
		e.getDept();
		e.getJob();
		e.getAge();
		e.getGender();
		e.getSalary();
		e.getBonusPoint();
		e.getPhone();
		e.getAddress();
		
		int eNo = e.getEmpNo();
		String eName = e.getEmpName();
		String dept_ = e.getDept();
		String job_ = e.getJob();
		int age_= e.getAge();
		char gender_ = e.getGender();
		int salary_ = e.getSalary();
		double bonus_ = e.getBonusPoint();
		String phone_ = e.getPhone();
		String addrs = e.getAddress();
		
		System.out.println("empNo : " + eNo);
		System.out.println("empName : " + eName);
		System.out.println("dept : " + dept_);
		System.out.println("job : " + job_);
		System.out.println("age : " + age_);
		System.out.println("gender : " + gender_);
		System.out.println("salary : " + salary_);
		System.out.println("bonus : " + bonus_);
		System.out.println("phone : " + phone_);
		System.out.println("address : " + addrs);
		
	}

}

기능클래스

package com.kh.example.practice5.model.vo;
public class Employee {
	
	private int empNo;
	private String empName;
	private String dept;
	private String job;
	private int age;
	private char gender;
	private int salary;
	private double bonusPoint;
	private String phone; 
	private  String address;
	
	// 기본 생성자
	public Employee() {

	}
	
	public Employee(int empNo, String empName) {
		this.empNo = empNo;
		this.empName = empName;
	}
	public Employee(int empNo, String empName, String dept, String job,	int age, 
			char gender, int salary, double bonusPoint, String phone, String address) {
		this.empNo = empNo;
		this.empName = empName;
		this.dept = dept;
		this.job = job;
		this.age = age;
		this.gender = gender;
		this.salary = salary;
		this.bonusPoint = bonusPoint;
		this.phone = phone;
		this.address = address;
	}
	
	// setter
	public void setEmpNo(int empNo) {
		this.empNo = empNo;
	}
	public void setEmpName(String empName) {
		this.empName = empName;
	}
	public void setDept(String dept) {
		this.dept = dept;
	}
	public void setJob(String job) {
		this.job = job;
	}	
	public void setAge(int age) {
		this.age = age;
	}
	public void setGender(char gender) {
		this.gender = gender;
	}	
	public void setSalary(int salary) {
		this.salary = salary;
	}
	public void setBonusPoint(double bonusPoint) {
		this.bonusPoint = bonusPoint;
	}	
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	
	
	// getter
	public int getEmpNo() {
		return empNo;
	}
	public String getEmpName() {
		return empName;
	}
	public String getDept() {
		return dept;
	}
	public String getJob() {
		return job;
	}	
	public int getAge() {
		return age;
	}
	public char getGender() {
		return gender;
	}	
	public int getSalary() {
		return salary;
	}
	public double getBonusPoint() {
		return bonusPoint;
	}
	public String getPhone() {
		return phone;
	}
	public String getAddress() {
		return address;
	}
	
	
	
}

 

 

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
반응형
728x90

 

공차란?

숫자들 사이에서 일정한 숫자의 차가 존재하는 것

ex) 1 3 5 7 9

각 숫자들 사이의 차가 2이며 이 2가 공차이다

 

 

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

 

728x90
반응형
728x90

 

 

 

 

 

 

	public void practice9(){
		
		// 중간고사, 기말고사, 과제점수, 출석회수를 입력하고 Pass 또는 Fail을 출력하세요.
		// 평가 비율은 중간고사 20%, 기말고사 30%, 과제 30%, 출석 20%로 이루어져 있고
		// 이 때, 출석 비율은 출석 회수의 총 강의 회수 20회 중에서 출석한 날만 따진 값으로 계산하세요.
		// 70점 이상일 경우 Pass, 70점 미만이거나 전체 강의에 30% 이상 결석 시 Fail을 출력하세요.

		System.out.print("중간 고사 점수 : ");
		int midterm = sc.nextInt();
		System.out.print("기말 고사 점수 : ");
		int finals = sc.nextInt();
		System.out.print("과제 점수 : ");
		int score = sc.nextInt();
		System.out.print("출석 회수 : ");
		int attendance = sc.nextInt();
		
		double mid_proportion = midterm*0.2;	// 20%를 치환하면 *0.2
		double finals_proportion = finals*0.3;
		double score_proportion = score*0.3;
		double attendance_proportion = (100/20)*attendance*0.2;
		double sum = mid_proportion+finals_proportion+score_proportion+attendance_proportion;
		
//		100/20*attendance <= 0.7 ?
		
		System.out.println("================= 결과 =================");

		
		if(sum>=70) {
			System.out.printf("중간 고사 점수(20) : %.1f%n",mid_proportion);
			System.out.printf("기말 고사 점수(30) : %.1f%n",finals_proportion);
			System.out.printf("과제 점수            (30) : %.1f%n",score_proportion);
			System.out.printf("출석 점수            (20) : %.1f%n",attendance_proportion);
			System.out.printf("총점 : %.1f%n",sum);
			System.out.println("PASS");
		}else if (attendance*(100/20) <= 70 ) { // 비율 계산의 0.7이 아닌 출  
			System.out.printf("Fail [출석 회수 부족 (%d/20)]",attendance);
		}else if (sum<70) {
			System.out.printf("중간 고사 점수(20) : %.1f%n",mid_proportion);
			System.out.printf("기말 고사 점수(30) : %.1f%n",finals_proportion);
			System.out.printf("과제 점수            (30) : %.1f%n",score_proportion);
			System.out.printf("출석 점수            (20) : %.1f%n",attendance_proportion);
			System.out.printf("총점 : %.1f%n",sum);
			System.out.println("Fail [점수 미달]");
		}
	}
728x90
반응형
728x90

 

형변환(casting)

자동형변환과 강제 형변환이 있다

자동형변환 중에서도 char 문자 하나와 숫자간의 자동형변환을 해본다

일상에서 못보던 것이기에 생소

 

 

 

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");
		}
		
}
728x90
반응형
728x90

 

 


public class practice_everyday01 {
	public static void main(String[] args) {	
		
		// 전위, 후위 증가연산자 
		// =전치,후치
		int a = 1;
		int b = 2;
		int ab = ++a + b; // (1+1) + 2 = 4 : a=2 b=2 ab=4
		int c = 3;		  //				 c=3
		int ac = a + c--; // 2 + 3 = 5 : a=2 b=2 c=2 
		int bc = ++b - c; // 3 - 1 = 1 : a=2 b=3 c=2
		
		System.out.println(a);
		System.out.println(b);
		System.out.println(c);
		System.out.println(ab);
		System.out.println(ac);
		System.out.println(bc);
		
			
	}
}
728x90
반응형
728x90

 

 

public void method1() {
		
	// 실수형으로 국어, 영어, 수학 세 과목의 점수를 입력 받아 총점과 평균을 출력하세요.
	// 이 때 총점과 평균은 정수형으로 처리하세요.
	
		// 실수 입력3칸 총점,평균 정수처리
		Scanner sc = new Scanner(System.in);
		System.out.print("국어 : ");
		float score1 = sc.nextFloat();
		System.out.print("영어 : ");
		float score2 = sc.nextFloat();
		System.out.print("수학 : ");
		double score3 = sc.nextDouble();
		
		// 방법1 : println() + 강제 형변환(int) 
		System.out.println("총점 : "+ (int)(score1+score2+score3)); // (int)
		System.out.println("평균 : "+ (int)((score1+score2+score3)/3));
		
		// 방법2 : printf()
		System.out.printf("총점 : %.0f%n",score1+score2+score3);
		System.out.printf("평균 : %.0f",(score1+score2+score3)/3);
		
	}
728x90
반응형
728x90

 

실수 소수라고 해서 %f를 쓰면 소수점 명령어랑 겹쳐서 안먹히니 %f빼고 %.1f로!!!

 

public void method1() {
	// 키보드로 가로, 세로 값을 실수형으로 입력 받아 사각형의 면적과 둘레를 계산하여 출력하세요
		
		Scanner sc = new Scanner(System.in);
		System.out.print("가로 : ");
		float width = sc.nextFloat();
		System.out.print("세로 : ");
		double length = sc.nextDouble();
		
		// 방법1 : println()
		System.out.println("면적 : " + (width * length));
		System.out.println("둘레 : " + ((width + length)*2));
		
		// 방법2 : printf()
		System.out.printf("면적 : %.2f%n",width*length);
		System.out.printf("둘레 : %.1f" ,(width + length)*2);
		// 실수 소수라고 해서 %f를 쓰면 소수점 명령어랑 겹쳐서 안먹히니 %f빼고 %.1f로
	}
728x90
반응형
728x90

 

 

 

import java.util.Scanner;

public class VariablePractice4 {
	
	public void method1() {
		
	// 영어 문자열 값을 키보드로 입력 받아 문자에서 앞에서 세 개를 출력하세요
	// .charAt()
		
		// 방법1 : println()
		Scanner sc = new Scanner(System.in);
		System.out.print("문자열을 입력하세요 : ");
		String str = sc.nextLine();
		
		System.out.println("첫 번째 문자 : " + str.charAt(0));
		System.out.println("두 번째 문자 : " + str.charAt(1));
		System.out.println("세 번째 문자 : " + str.charAt(2));
		
		// 방법2 : printf()
		char ch1 = str.charAt(0);
		char ch2 = str.charAt(1);
		char ch3 = str.charAt(2);
		System.out.printf("첫 번째 문자 : %c%n",ch1 );
		System.out.printf("두 번째 문자 : %c%n",ch2 );
		System.out.printf("세 번째 문자 : %c",ch3 );
				
	}
}
728x90
반응형

+ Recent posts