diff --git a/pycharm change java/.gitignore b/pycharm change java/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/pycharm change java/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/pycharm change java/.idea/.gitignore b/pycharm change java/.idea/.gitignore new file mode 100644 index 0000000..c3f502a --- /dev/null +++ b/pycharm change java/.idea/.gitignore @@ -0,0 +1,8 @@ +# 디폴트 무시된 파일 +/shelf/ +/workspace.xml +# 에디터 기반 HTTP 클라이언트 요청 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/pycharm change java/.idea/misc.xml b/pycharm change java/.idea/misc.xml new file mode 100644 index 0000000..f03c948 --- /dev/null +++ b/pycharm change java/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pycharm change java/.idea/modules.xml b/pycharm change java/.idea/modules.xml new file mode 100644 index 0000000..720d4b8 --- /dev/null +++ b/pycharm change java/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/pycharm change java/pycharm change java.iml b/pycharm change java/pycharm change java.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/pycharm change java/pycharm change java.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/pycharm change java/src/Java_study01.java b/pycharm change java/src/Java_study01.java new file mode 100644 index 0000000..6f3cc08 --- /dev/null +++ b/pycharm change java/src/Java_study01.java @@ -0,0 +1,46 @@ +public class Java_study01 { + + public static class StudentGrade { + private String name; + private int studentId; + private int grade; + public StudentGrade(String name, int studentId, int grade) { + this.name = name; + this.studentId = studentId; + this.grade = grade; + } + public String getName() { + return name; + } + public int getStudentId() { + return studentId; + } + public int getGrade() { + return grade; + } + public void setName(String newName) { + this.name = newName; + } + public void setStudentId(int newStudentId) { + this.studentId = newStudentId; + } + public void setGrade(int newGrade) { + if (newGrade >= 0 && newGrade <= 100) { + this.grade = newGrade; + } else { + System.out.println("잘못된 값임"); + } + } + public void displayInfo() { + System.out.println("이름: " + name + ", 학번: " + studentId + ", 성적: " + grade); + } + } + public static void main(String[] args) { + StudentGrade a = new StudentGrade("홍길동", 1111, 100); + a.displayInfo(); + a.setName("홍킬동"); + a.setStudentId(1211); + a.setGrade(11); + a.displayInfo(); + } +} diff --git a/pycharm change java/src/Java_study02.java b/pycharm change java/src/Java_study02.java new file mode 100644 index 0000000..8c7e938 --- /dev/null +++ b/pycharm change java/src/Java_study02.java @@ -0,0 +1,92 @@ +import java.util.HashMap; +import java.util.Map; + +public class Java_study02 { + public static class Warehouse { + private Map items; + private int capacity; + + public Warehouse(int capacity) { + this.items = new HashMap<>(); // 아이템 맵을 초기화 + this.capacity = capacity; + } + + public Map get_items() { + return items; + } + + public int get_capacity() { + return capacity; + } + + public int set_capacity(int new_capacity) { + if (new_capacity <= 0) { + System.out.println("잘못된 수량 입니다"); + } else { + capacity = new_capacity; + } + return capacity; + } + + public void add_item(String item, int quantity) { + if (quantity <= 0) { + System.out.println("양수여야 함"); + return; + } + + int currentTotal = getTotalQuantity(); + + if (currentTotal + quantity > capacity) { + System.out.println("창고 다 참"); + } else { + items.put(item, quantity); + System.out.println(item + "가 " + quantity + "만큼 추가됨"); + } + } + + private int getTotalQuantity() { + int total = 0; + for (int quantity : items.values()) { + total += quantity; + } + return total; + } + + public void remove_item(String item, int quantity) { + if (items.containsKey(item)) { + int currentQuantity = items.get(item); + if (quantity > currentQuantity) { + System.out.println("상품이 부족합니다."); + } else { + currentQuantity -= quantity; + if (currentQuantity == 0) { + items.remove(item); + } else { + items.put(item, currentQuantity); + } + System.out.println(item + "가 " + quantity + "만큼 제거됨"); + } + } else { + System.out.println("해당 아이템이 존재하지 않습니다."); + } + } + + public void display_items() { + System.out.println("현재 창고 상태: " + items); + } + } + + public static void main(String[] args) { + Warehouse warehouse = new Warehouse(100); + warehouse.add_item("사과", 30); + warehouse.add_item("바나나", 20); + warehouse.add_item("오렌지", 60); + warehouse.display_items(); + warehouse.remove_item("사과", 10); + warehouse.remove_item("바나나", 25); // 부족한 상품을 제거하려고 하면 "상품이 부족합니다"가 출력됨 + warehouse.display_items(); + warehouse.set_capacity(150); + warehouse.add_item("오렌지", 50); + warehouse.display_items(); + } +} diff --git a/pycharm change java/src/Java_study03.java b/pycharm change java/src/Java_study03.java new file mode 100644 index 0000000..34eed67 --- /dev/null +++ b/pycharm change java/src/Java_study03.java @@ -0,0 +1,47 @@ +public class Java_study03 { + public static class Library { + int totalBook = 0; + private String name; + private int books; + public Library(String name, int books) { + this.name = name; + this.books = books; + totalBook += books; + } + + public void add_book(int count){ + totalBook += count; + books += count; + System.out.println("책이 "+count+"만큼 추가됌"); + } + public void remove_book(int count){ + totalBook -= count; + books -= count; + System.out.println("책이 "+count+"만큼 삭제됌"); + } + public void display_info(){ + System.out.println(name); + System.out.println(books); + System.out.println(totalBook); + } + } + public static void main(String[] args) { + // Library 객체 생성 + Library library1 = new Library("중앙 도서관", 100); + Library library2 = new Library("서부 도서관", 50); + + // 도서관 정보 출력 + library1.display_info(); + library2.display_info(); + + // 책 추가 및 제거 + library1.add_book(30); + library2.remove_book(20); + + // 도서관 정보 출력 + System.out.println("\n책 추가 및 제거 후:"); + library1.display_info(); + library2.display_info(); + } +} + diff --git a/pycharm change java/src/Java_study04.java b/pycharm change java/src/Java_study04.java new file mode 100644 index 0000000..3733a47 --- /dev/null +++ b/pycharm change java/src/Java_study04.java @@ -0,0 +1,60 @@ +public class Java_study04 { + public static class Animal{ + String name; + + public Animal(String name){ + this.name = name; + } + public void speak(){ + System.out.println("동물이 울음 소리를 냅니다"); + } + public void display_info(){ + System.out.println(name); + } + } + public static class Dog extends Animal{ + + public Dog(String name) { + super(name); // 부모 클래스의 생성자 호출 + } + + public void speak(){ + System.out.println("멍멍"); + } + public void display_info(){ + System.out.println(name); + } + } + public static class Cat extends Animal{ + + public Cat(String name) { + super(name); // 부모 클래스의 생성자 호출 + } + + public void speak(){ + System.out.println("야옹"); + } + public void display_info(){ + System.out.println(name); + } + } + + public static void main(String[] args) { + // Animal, Dog, Cat 객체 생성 + Animal animal = new Animal("동물"); + Dog dog = new Dog("바둑이"); + Cat cat = new Cat("나비"); + + // Animal 클래스 메서드 호출 + animal.display_info(); // "이름: 동물" 출력 + animal.speak(); // "동물이 울음 소리를 냅니다" 출력 + + // Dog 클래스 메서드 호출 + dog.display_info(); // "이름: 바둑이" 출력 + dog.speak(); // "멍멍" 출력 + + // Cat 클래스 메서드 호출 + cat.display_info(); // "이름: 나비" 출력 + cat.speak(); // "야옹" 출력 + } +} diff --git a/pycharm change java/src/Java_study05.java b/pycharm change java/src/Java_study05.java new file mode 100644 index 0000000..f3d4da7 --- /dev/null +++ b/pycharm change java/src/Java_study05.java @@ -0,0 +1,60 @@ +public class Java_study05 { + public static class Car{ + String model; + int max_speed; + + public Car(String model, int max_speed){ + this.model = model; + this.max_speed = max_speed; + } + public void display_info(){ + System.out.println(model); + System.out.println(max_speed); + } + public void start(){ + System.out.println("자동차가 주행을 시작했습니다"); + } + public static class SuperCar extends Car{ + public SuperCar(String model, int max_speed) { + super(model, max_speed); + } + public void turbo_boost(){ + System.out.println("터보 부스트! 최고 속도가 50km/h 증가합니다."); + max_speed += 50; + } + public void display_info(){ + System.out.println(model); + System.out.println(max_speed); + } + } + public static class SportCar extends Car{ + public SportCar(String model, int max_speed) { + super(model, max_speed); + } + public void drift(){ + System.out.println("스포츠카가 드리프트를 시작합니다"); + } + + public void display_info() { + System.out.println(model); + System.out.println(max_speed); + } + } + } + + public static void main(String[] args) { + Car car = new Car("일반 자동차", 180); + car.display_info(); + car.start(); + + Car.SuperCar superCar = new Car.SuperCar("슈퍼카", 300); + superCar.display_info(); + superCar.turbo_boost(); + superCar.display_info(); + + Car.SportCar sportCar = new Car.SportCar("스포츠카", 250); + sportCar.display_info(); + sportCar.drift(); + + } +} diff --git a/pycharm change java/src/Java_study06.java b/pycharm change java/src/Java_study06.java new file mode 100644 index 0000000..153e83f --- /dev/null +++ b/pycharm change java/src/Java_study06.java @@ -0,0 +1,50 @@ +public class Java_study06 { + public static class person{ + String name; + int ssn; + String subjects; + String grade; + int salary; + public person(String name, int ssn){ + this.name = name; + this.ssn = ssn; + } + public void display_info(){ + System.out.println(name); + System.out.println(ssn); + } + } + public static class Student extends person { + public Student(String name, int ssn,String subjects, String grade){ + super(name,ssn); + this.subjects = subjects; + this.grade = grade; + } + public void display_info(){ + System.out.println(name); + System.out.println(ssn); + System.out.println(subjects); + System.out.println(grade); + } + } + public static class Teacher extends person{ + public Teacher(String name, int ssn,String subjects,int salary){ + super(name,ssn); + this.subjects = subjects; + this.salary = salary; + } + public void display_info(){ + System.out.println(name); + System.out.println(ssn); + System.out.println(subjects); + System.out.println(salary); + } + } + + public static void main(String[] args) { + Student student = new Student("홍길동", 12345678, "자료구조", "A"); + Teacher teacher = new Teacher("김철수", 123456790, "Python", 3000000); + student.display_info(); + teacher.display_info(); + } +} diff --git a/pycharm change java/src/Java_study07.java b/pycharm change java/src/Java_study07.java new file mode 100644 index 0000000..96aed8f --- /dev/null +++ b/pycharm change java/src/Java_study07.java @@ -0,0 +1,40 @@ +public class Java_study07 { + public static class Movie{ + String title; + String director; + int rating; + int viewers; + public Movie(String title, String director, int rating, int viewers){ + this.director = director; + this.title = title; + this.rating =rating; + this.viewers = viewers; + } + public int add_viewers(int count){ + viewers += count; + return viewers; + } + public String update_rating(int new_rating){ + if(new_rating < 1 || new_rating>5){ + return "잘못된 평점 입니다"; + } + else{ + rating = new_rating; + return "현재 평점"+this.rating; + } + } + public void display_info(){ + System.out.println(title); + System.out.println(director); + System.out.println(rating); + System.out.println(viewers); + } + } + + public static void main(String[] args) { + Movie movie = new Movie("너의 이름은","신카이 마코토",0,0); + movie.add_viewers(10000); + movie.update_rating(5); + movie.display_info(); + } +} diff --git a/pycharm change java/src/Java_study08.java b/pycharm change java/src/Java_study08.java new file mode 100644 index 0000000..c3c212c --- /dev/null +++ b/pycharm change java/src/Java_study08.java @@ -0,0 +1,29 @@ +import java.util.ArrayList; + +public class Java_study08 { + public static class ShoppingCart{ + private ArrayList items; + public ShoppingCart(){ + this.items = new ArrayList<>(); + } + public void add_item(String item){ + items.add(item); + } + public void remove_item(String item){ + if(items.contains(item)){ + items.remove(item); + } + } + public void view_cart(){ + System.out.println("장바구니 :"+items); + } + } + + public static void main(String[] args) { + ShoppingCart shoppingCart = new ShoppingCart(); + shoppingCart.add_item("apple"); + shoppingCart.view_cart(); + shoppingCart.remove_item("apple"); + shoppingCart.view_cart(); + } +} diff --git a/pycharm change java/src/Java_study09.java b/pycharm change java/src/Java_study09.java new file mode 100644 index 0000000..f0c20cc --- /dev/null +++ b/pycharm change java/src/Java_study09.java @@ -0,0 +1,57 @@ +import java.util.ArrayList; +import java.util.HashMap; + +public class Java_study09 { + public static class Classroom { + private ArrayList students; + private HashMap attendance; + + public Classroom(ArrayList students) { + this.students = students; + this.attendance = new HashMap<>(); + // 출석 초기화 + for (String student : students) { + attendance.put(student, 0); + } + } + + // 학생 추가 메서드 + public void add_student(String name) { + students.add(name); + attendance.put(name, 0); // 새 학생의 출석 초기화 + } + + // 출석 체크 메서드 + public void mark_attendance(String name) { + if (attendance.containsKey(name)) { + attendance.put(name, attendance.get(name) + 1); // 출석 1 증가 + } else { + System.out.println("학생을 찾을 수 없습니다"); + } + } + + // 출석 정보 출력 메서드 + public void print_attendance() { + for (String student : students) { + System.out.println(student + ": " + attendance.get(student) + "회"); + } + } + } + + public static void main(String[] args) { + ArrayList studentList = new ArrayList<>(); + studentList.add("홍길동"); + studentList.add("김철수"); + + // Classroom 객체 생성 + Classroom classroom = new Classroom(studentList); + + // 출석 체크 + classroom.mark_attendance("홍길동"); + classroom.mark_attendance("김철수"); + classroom.mark_attendance("홍kill동"); + + // 출석 정보 출력 + classroom.print_attendance(); + } +} diff --git a/pycharm change java/src/Java_study10.java b/pycharm change java/src/Java_study10.java new file mode 100644 index 0000000..8dbf743 --- /dev/null +++ b/pycharm change java/src/Java_study10.java @@ -0,0 +1,42 @@ +public class Java_study10 { + public static class Car{ + String color; + String model; + int fuel_level= 0; + int fuel_efficeny = 0; + int use_fuel; + public Car(String color, String model, int fuel_efficeny, int fuel_level){ + this.color = color; + this.fuel_efficeny = fuel_efficeny; + this.fuel_level = fuel_level; + this.model = model; + } + public int drive(int distance){ + use_fuel = distance / fuel_efficeny; + fuel_level -= use_fuel; + if(fuel_level<0){ + System.out.println("연료가 부족합니다, 주유가 필요 합니다"); + } + else{ + return fuel_level; + } + return fuel_level; + } + public int reful(int amount){ + fuel_level += amount; + return fuel_level; + } + public void check_fuel(){ + System.out.println(fuel_level); + } + } + + public static void main(String[] args) { + Car car = new Car("blue","E-class",20,100); + System.out.println(car.color); + System.out.println(car.model); + car.drive(20); + car.reful(100); + car.check_fuel(); + } +} diff --git a/pycharm change java/src/Java_study11.java b/pycharm change java/src/Java_study11.java new file mode 100644 index 0000000..36fcf5c --- /dev/null +++ b/pycharm change java/src/Java_study11.java @@ -0,0 +1,47 @@ +public class Java_study11 { + public static class Employee{ + String name; + String position; + double salary; + int hours_worked; + double total_pay; + int overtime_hours; + public Employee(String name, String position, double salary, int hours_worked){ + this.name = name; + this.position = position; + this.salary = salary; + this.hours_worked = hours_worked; + } + public void log_hours(int hours){ + hours_worked += hours; + } + public double calculate_pay(){ + if(hours_worked <= 40){ + total_pay = salary * hours_worked; + } + else{ + overtime_hours = hours_worked - 40; + total_pay = (salary * 40) + (salary * 1.5*overtime_hours); + } + return total_pay; + } + public void promote(String new_position, double raise_amount){ + position = new_position; + salary += raise_amount; + System.out.println(name+"님이 "+position+"으로 승진 하셨으며, 급여가 "+raise_amount+"만큼 인상 되었습니다"); + } + public void display_info(){ + System.out.println("이름: "+name); + System.out.println("직위: "+position); + System.out.println("시급: "+salary); + System.out.println("근무시간: "+hours_worked); + } + } + public static void main(String[] args) { + Employee employee = new Employee("홍길동","대리",9870,0); + employee.log_hours(45); + System.out.println("급여: "+employee.calculate_pay()); + employee.promote("과장",2000); + employee.display_info(); + } +} diff --git a/pycharm change java/src/Java_study12.java b/pycharm change java/src/Java_study12.java new file mode 100644 index 0000000..b789392 --- /dev/null +++ b/pycharm change java/src/Java_study12.java @@ -0,0 +1,63 @@ +import java.util.ArrayList; +import java.util.List; + +public class Java_study12 { + // Account 클래스 정의 + public static class Account { + private String accountNumber; + private String owner; + private int balance; + private List transactions; + + // 생성자 + public Account(String accountNumber, String owner, int balance) { + this.accountNumber = accountNumber; + this.owner = owner; + this.balance = balance; + this.transactions = new ArrayList<>(); + } + + // 입금 메서드 + public int deposit(int amount) { + balance += amount; + System.out.println(amount + "가 입금 되었습니다"); + transactions.add("입금: " + amount + ", 잔액: " + balance); + return balance; + } + + // 출금 메서드 + public int withdraw(int amount) { + if (balance >= amount) { + balance -= amount; + System.out.println(amount + "가 출금 되었습니다"); + transactions.add("출금: " + amount + ", 잔액: " + balance); + return balance; + } else { + System.out.println("잔액이 부족합니다"); + return balance; + } + } + + // 잔액 확인 메서드 + public int checkBalance() { + System.out.println("현재 잔액: " + balance); + return balance; + } + + // 거래 내역 출력 메서드 + public void transactionsHistory() { + System.out.println("거래 내역:"); + for (String transaction : transactions) { + System.out.println(transaction); + } + } + } + + // 메인 메서드 + public static void main(String[] args) { + Account account = new Account("12345", "홍kill동", 0); + account.deposit(100); + account.withdraw(10); + account.transactionsHistory(); + } +}