Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions pycharm change java/.gitignore
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions pycharm change java/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions pycharm change java/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions pycharm change java/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions pycharm change java/pycharm change java.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
46 changes: 46 additions & 0 deletions pycharm change java/src/Java_study01.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
92 changes: 92 additions & 0 deletions pycharm change java/src/Java_study02.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import java.util.HashMap;
import java.util.Map;

public class Java_study02 {
public static class Warehouse {
private Map<String, Integer> items;
private int capacity;

public Warehouse(int capacity) {
this.items = new HashMap<>(); // 아이템 맵을 초기화
this.capacity = capacity;
}

public Map<String, Integer> 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();
}
}
47 changes: 47 additions & 0 deletions pycharm change java/src/Java_study03.java
Original file line number Diff line number Diff line change
@@ -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();
}
}

60 changes: 60 additions & 0 deletions pycharm change java/src/Java_study04.java
Original file line number Diff line number Diff line change
@@ -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(); // "야옹" 출력
}
}
60 changes: 60 additions & 0 deletions pycharm change java/src/Java_study05.java
Original file line number Diff line number Diff line change
@@ -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();

}
}
Loading