728x90

 

 

 

public class practice_everyday01 {
	public static void main(String[] args) {	
		
		int[] arr = new int[4];
		for(int i = 0; i<arr.length;i++) {
			System.out.println(arr[i] += (10+i));
		}
			
	}
}
728x90
반응형
728x90

 

오늘 코딩으로 

다량의 주문이나 DB관리 때 런파일에서 간단하게 수치만 바꿔서 관리할 수 있는 아주 편리한 기능을 배웠다!!

 

실행 클래스

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

}

 

 

기능 클래스

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() 생성자
		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

 

println()

printf()

두가지로 추가 연습

 

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

+ Recent posts