본문 바로가기

예제12

Java 추상화 예제 - 상품 정보, 할인 금액 출력 package entity;public abstract class Product { protected String productId; protected String name; protected double price; // 디폴트 생성자 public Product() { } // 매개변수가 있는 생성자 public Product(String productId, String name, double price) { this.productId = productId; this.name = name; this.price = price; } // 상품 정보를 출력하는 추상 메서드 public abstract void d.. 2024. 12. 16.
Java 작성 시 신경쓰면 좋은 Early return, Guard clause * return false가 먼저 오도록 작업 하기 Why?Early return이란?불필요한 코드 실행 방지: return false 이후의 코드는 실행되지 않으므로, 조건이 충족되지 않았을 때 불필요한 작업을 막을 수 있다.성능 최적화: 조건이 충족되지 않은 경우 즉시 함수를 종료함으로써 리소스를 절약할 수 있다. 예제 - 강의 등록, 취소 import entity.Lecture;import entity.Student;public class StudentTest { public static void main(String[] args) { // 학생 입력 Student s1=new Student("김나나","32번"); Student s2=new Student.. 2024. 12. 12.
Java if와 논리 연산자를 이용한 날짜 출력 예제 package entity;public class MyDate { private int day; private int month; private int year; //디폴트 생성자 public MyDate() { } //MyDate(int day, int month, int year) 생성자 public MyDate(int day, int month, int year) { this.day = day; this.month = month; this.year = year; } // todo 우리가 만들 메소드 public boolean isValid() { if (month 12) { .. 2024. 12. 12.
Java 메소드 예제 public class User { // 유저 이름, 나이, 전화번호를 저장하려 합니다. String userName; int age; String phone; // 유저이름, 나이, 전화번호를 출력하는 함수 void print(){ System.out.println("유저이름: "+userName+" 나이: "+age+" 전화번호: "+phone); } // 10년 후의 나이를 계산해서 리턴하는 함수 int futureAge(){ int add10=age+10; return add10; } // say("안녕?"); // 화면에 출력 : 홍길동님 안녕? void say(String sentence.. 2024. 12. 10.
Join 예제 2 더보기 INSERT INTO series (title, released_year, genre) VALUES('Archer', 2009, 'Animation'),('Arrested Development', 2003, 'Comedy'),("Bob's Burgers", 2011, 'Animation'),('Bojack Horseman', 2014, 'Animation'),("Breaking Bad", 2008, 'Drama'),('Curb Your Enthusiasm', 2000, 'Comedy'),("Fargo", 2014, 'Drama'),('Freaks and Geeks', 1999, 'Comedy'),('General Hospital', 1963, 'Drama'),('Halt and Catch Fire.. 2024. 12. 3.
Join 예제 더보기INSERT INTO students (first_name) VALUES('Caleb'), ('Samantha'), ('Raj'), ('Carlos'), ('Lisa'); INSERT INTO papers (student_id, title, grade ) VALUES(1, 'My First Book Report', 60),(1, 'My Second Book Report', 75),(2, 'Russian Lit Through The Ages', 94),(2, 'De Montaigne and The Art of The Essay', 98),(4, 'Borges and Magical Realism', 89); -- grade로 정렬하세요-- first_name, title, gradeSELECT s.fi.. 2024. 12. 2.
날짜 예제 더보기INSERT INTO orders (customer_name, product_name, order_date, delivery_date) VALUES('김철수', '노트북', '2023-10-01 14:30:00', '2023-10-05'),('이영희', '스마트폰', '2023-10-02 09:15:00', '2023-10-07'),('박준혁', '태블릿', '2023-10-03 16:45:00', '2023-10-09'),('최수진', '헤드폰', '2023-10-04 11:00:00', '2023-10-10'),('정우진', '키보드', '2023-10-05 18:20:00', '2023-10-12'),('윤지민', '스마트워치', '2023-10-06 10:30:00', '2023-10-10'.. 2024. 12. 2.
키워드 예제 3 -- 1980년 이전에 발행된 책을 가져오세요.SELECT *FROM books bwhere released_year    -- eggers 나 chabon이 쓴 책을 가져오세요.SELECT *FROM books bwhere author_lname ='Eggers' or author_lname = 'Chabon';  ★더 깔끔한 코드! 항목 추가되도 수정하기도 편하고 보기도 편한 INSELECT *FROM books bWHERE author_lname in('Eggers','Chabon');  -- lahiri가 썼고, 2000년 이후에 발행된 책을 가져오세요.SELECT *FROM books bwhere author_lname ='Lahiri' and released_year > 2000;  -- 페이.. 2024. 11. 29.
키워드 예제 2 세팅더보기INSERT INTO subscriptions (user_name, plan_name, start_date, end_date, status, price) VALUES('김철수', 'Premium', '2023-01-01', '2023-12-31', 'Active', 12000),('박준혁', 'Standard', '2023-07-01', '2023-12-31', 'Active', 9000),('최수진', 'Premium', '2023-01-01', '2023-12-31', 'Active', 12000),('김지훈', 'Premium', '2023-04-01', '2023-12-31', 'Active', 12000),('장서현', 'Standard', '2023-06-01', '2023-12-31.. 2024. 11. 29.