package ex1111;
import java.util.ArrayList;
import java.util.Scanner;
public class ex1 {
public static void main(String[] args) {
ArrayList<Piggybank> e2 = new ArrayList<Piggybank>();
Piggybank p = new Piggybank();
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("================무었을 선택 하시겠습니까?================");
System.out.print("[1]입금 [2]출금 [3]잔액확인 [4]종료하기[5]효창이 한테 기부하기 : ");
int a = sc.nextInt();
if (a == 1) {
System.out.print("얼마를 기부하시겠어요?");
p.deposit(sc.nextInt());
} else if (a == 2) {
System.out.print("얼마를 출금하시겠어요?");
p.withdraw(sc.nextInt());
} else if (a == 3) {
p.showmoney();
} else if (a == 4) {
} else {
System.out.print("얼마를 기부하시겠어요?");
p.donation(sc.nextInt());
}
System.out.println();
}
}
}
package ex1111;
import java.util.ArrayList;
public class contactmain {
public static void main(String[] args) {
ArrayList<contact> contacts = new ArrayList<contact>();
// 객체생성
// contact c1 = new contact("윤효창", 20,"010-3228-5850");
contacts.add(new contact("윤효창", 20, "010-3228-5850"));
contacts.add(new contact("강로운", 20, "010-3232-5850"));
contacts.add(new contact("임소완", 22, "010-1232-5850"));
contacts.add(new contact("김종현", 20, "010-2232-5850"));
for (int i = 0; i < contacts.size(); i++) {
String name = contacts.get(i).getName();
int age = contacts.get(i).getAge();
String tel = contacts.get(i).getTel();
System.out.printf(i + 1 + ".%s(%d): %s : %n", name, age, tel);
}
}
=================================
-- 기타객체 : 테이블, 뷰, 인데스, 시퀀스, 동의어,
-- 함수(Function), 트리거(Trigger)
---------------------------------
-- 데이터 사전
-- user_xxxx ,all_xxxx
select table_name, num_rows from user_tables;
select owner,table_name, num_rows from all_tables
where owner = 'HR';
select object_name from user_objects
where object_type = 'VIEW';
---------------------------------
-- 객체의 생성
-- create 객체종류(table, view..)
---------------------------------
-- 1.view
-- 보안상 데이테를 부분적 접근이 필요할때..
-- 복잡한 질의를 쉽게 접근
-- 데이터의 독립성을 보장할때..
-- 뷰의 생성
create view vw_emp5080 as (
select last_name, job_id, (salary*12) annsal
from employees
where department_id in (50, 80)
);
select * from vw_emp5080;
-- 생성한뷰 삭제
drop view emp5080;
-- 데이터 사정을 통한 조회
select object_name from user_objects
where object_type = 'VIEW';
create view vw_emp50 as (
select last_name, job_id
,to_char(hire_date, 'yyyy-mm-dd') as hire_date
,(salary*12) annsal
from employees
where department_id in (50)
);
select * from vw_emp50;
-- inLine 뷰
-- 상위 급여 5명을 조회
select rownum, emp.*
from (select last_name, salary
from employees
order by salary desc) emp
where rownum < 6
;
-- 2.index
-- 검색속도를 높인다.
-- 물리적인 저장 공간이 차지.
-- 검색의 속도를 높이는 반면, insert, delete 작업속도를 저하시킨다.
-- index의 생성시 고려사항
-- 1) 열의 정보가 광범위하게 포함된경우
-- 2) 조건절, 조인이 자주일어나는 경우
-- 3) 대부분의 질의 결과가 2-4%미만의 경우
create index tmp_emp20_idx
on tmp_emp20 (lname);
select object_name from user_objects;
select object_name from user_objects
where object_type = 'INDEX';
select * from tmp_emp20
where lname like 'L%';
drop index tmp_emp20_idx;
-- 3.시퀀스(Sequence)
-- 고유의 번호흫 자동으로 생성한다.
-- 공유가 가능하다.
-- 일반적으로 PK에 많이 사용한다.
create sequence emp20_seq
increment by 10
start with 100
maxvalue 999999
nocache
nocycle;
select emp20_seq.nextval from dual;
select emp20_seq.currval from dual;
insert into tmp_emp20 (empid, lname,cdate)
values (emp20_seq.nextval, 'Shin inho', sysdate);
select * from tmp_emp20;
drop sequence emp20_seq;
-- 4.동의어(Synonym)
create synonym emps for employees;
select * from emps;
drop synonym emps;
-- 5.함수(Function)
--. 내장함수, 사용자 함수
create or replace function fn_dname (dept_id in int)
return varchar
is
dnm varchar2(30);
begin
select department_name into dnm
from departments
where department_id = dept_id;
return dnm;
end;
/
select fn_dname(50) from dual;
select last_name, fn_dname(department_id) as deptnm, salary
from employees;
drop function fn_dname;
-- 6.트리거(trigger)
--.
-- 백업 테이블의 생성
create table tmp_emp20Bak as
select * from tmp_emp20 where 1 <> 1;
select * from tmp_emp20bak
;
-- 트리거의 생성
drop trigger emp_del;
create or replace trigger emp_del
before delete on tmp_emp20 for each row
begin
insert into tmp_emp20Bak values (
:old.EMPID, :old.LNAME, :old.SAL, :old.BONUS, sysdate
);
end;
/
-- 트리거 운영
select * from tmp_emp20
where empid =200;
delete tmp_emp20
where empid = 200;
select * from tmp_emp20bak
where empid =200;
commit;
---------------------------------
-- DCL(Data Controll Language)
-- system 계정에서 실행
show user;
-- 사용자의 생성
create user inho identified by inho;
alter user inho identified by inho account unlock;
-- 연결 권한 부여
grant create session to inho;
-- 테이블 생성권한 부여
grant create TABLE to inho;
-- 자원 사용권한 부여
grant resource to inho;
-- 암호 변경
alter user inho identified by shinho;
grant create session, resource,
create TABLE, create view,
create sequence
to inho;
-- 사용자 계정에서 실행
create table emp_ho
( id number,
name varchar(20)
);
create view vw_emp as (
select * from emp_ho);
-- 데이터 사전의 조회
select * from user_sys_privs;
트리거와 함수 로직 매우 부족 시험문제 많이 풀 필요함
package ex1107;
import java.util.ArrayList;
import java.util.Scanner;
public class Ex03_musicplayList {
public static void main(String[] args) {
ArrayList<String> ml = new ArrayList<String>();
Scanner sc = new Scanner(System.in);
while (true) {
System.out.print("[1] 노래 추가 [2] 노래조회 [3] 노래삭제 [4] 종료>>");
int menu = sc.nextInt();
if (menu == 1) {
// 노래추가
System.out.println("==================================");
System.out.print("[1]원하는 위치에추가 [2]마지막위치에추가 >> ");
int num = sc.nextInt();
if (num == 1) {
// 원하는 위치추가
System.out.print("원하는 위치 입력 : ");
int index = sc.nextInt();
System.out.print("추가할 노래 입력 : ");
String title = sc.next();
ml.add(index - 1, title);
} else if (num == 2) {
// 마지막위치 추가
System.out.print("추가할 노래 입력 : ");
String title = sc.next();
ml.add(title);
} else {
}
System.out.print("다시입력");
} else if (menu == 2) {
// 노래조회기능
System.out.println("====현재재생목록====");
if (ml.size() == 0) {
System.out.print("재생목록이 없습니다!");
} else {
for (int i = 0; i < ml.size(); i++) {
System.out.println(i + 1 + "." + ml.get(i));
}
}
} else if (menu == 3) {
// 노래삭제기능
System.out.println("==========================");
System.out.print("[1]선택삭제 [2]전체삭제 >>> ");
int num = sc.nextInt();
if (num == 1) {
System.out.print("삭제할 번호 입력 : ");
int index = sc.nextInt();
ml.remove(index - 1);
System.out.print("삭제되었습니다.~");
} else if (num == 2) {
// 전체삭제
ml.clear();
System.out.println("전체 삭제 되었습니다.~ ");
} else {
System.out.print("다시입력");
}
} else if (menu == 4) {
// 종료
System.out.print("프로그램을 종료합니다");
break;
} else {
System.out.print("다시입력");
}
}
}
}
간단한 로직이지만 많아 지닌깐 복잡해서 실수 자주함 큰거 먼저 만들면서 주석을 달필요성 느낌
package ex1111;
public class contact {
// 필드
private String name;
private int age;
private String tel;
//생성자 메소드
public contact(String name, int age, String tel) {
this.name = name;
this.age = age;
this.tel = tel;
}
// getter / setter 메소드
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
//메소드
}
클래스에 필드와 메소드 만든다
package ex1111;
import java.util.ArrayList;
public class contactmain {
public static void main(String[] args) {
ArrayList<contact> contacts = new ArrayList<contact>();
// 객체생성
// contact c1 = new contact("윤효창", 20,"010-3228-5850");
contacts.add(new contact("윤효창", 20, "010-3228-5850"));
contacts.add(new contact("강로운", 20, "010-3232-5850"));
contacts.add(new contact("임소완", 22, "010-1232-5850"));
contacts.add(new contact("김종현", 20, "010-2232-5850"));
for (int i = 0; i < contacts.size(); i++) {
String name = contacts.get(i).getName();
int age = contacts.get(i).getAge();
String tel = contacts.get(i).getTel();
System.out.printf(i + 1 + ".%s(%d): %s : %n", name, age, tel);
}
}
배열을 만들어소 for 문을 사용하여 출력하여야함
package ex1111;
public class Piggybank {
//저금통 클래스
// 필드
int money;
int don;
//메소드
//1. 저금하는 메소드
//사용자가 입금할 돈을 입력하면(매개변수) 현재자산(money)에 추가하는 기능
public void deposit (int input) {
money += input;
}
//2.출금하는 메소드
//사용자가 출금할 돈을 입력하면(매개변수) 현재자산(money)에서 출금하는 기능
public void withdraw (int output) {
money -= output;
}
//3. 잔액을 보여주는 메소드
// 현재 재산을 출력하는 메소드
public void showmoney () {
System.out.print("현재잔액은 : " + money + "입니다.");
}
public void donation (int input) {
don+=input;
System.out.print("현재 뽀찌는 : " + input+ "입니다.");
}
}
저금통 수업까지 하는데 심심해서 끝까지 풀어봄
확실히 풀어 보닌깐 대충 이해가 가기 시작함