Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1차 세미나 기본과제 #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions Seminar 1/JavaOOPExample/.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 Seminar 1/JavaOOPExample/.idea/modules.xml

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

6 changes: 6 additions & 0 deletions Seminar 1/JavaOOPExample/.idea/vcs.xml

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

106 changes: 106 additions & 0 deletions Seminar 1/JavaOOPExample/.idea/workspace.xml

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

11 changes: 11 additions & 0 deletions Seminar 1/JavaOOPExample/JavaOOPExample.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>
25 changes: 25 additions & 0 deletions Seminar 1/JavaOOPExample/src/AbstractClass/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package AbstractClass;

public abstract class Car {
private String type;
private double fuelEfficiency;
private double oilAmount;

public Car(String type, double fuelEfficiency, double oilAmount) {
this.type = type;
this.fuelEfficiency = fuelEfficiency;
this.oilAmount = oilAmount;
}

public abstract void go();

public abstract void stop();

public void fuelUp(int amount) {
this.oilAmount += (double)amount;
}

public void fuelUp(double amount) {
this.oilAmount += amount;
}
}
24 changes: 24 additions & 0 deletions Seminar 1/JavaOOPExample/src/Class/Avante.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package Class;

import AbstractClass.Car;

public class Avante extends Car {
private int price;

public Avante(String type, double fuelEfficiency, double oilAmount, int price) {
super(type, fuelEfficiency, oilAmount);
this.price = price;
}

public void go() {
System.out.println("아반떼 주행하다");
}

public void stop() {
System.out.println("아반떼 정지하다");
}

public void goBack() {
System.out.println("후진하다");
}
}
19 changes: 19 additions & 0 deletions Seminar 1/JavaOOPExample/src/Class/Box.java
05AM marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package Class;

public class Box<E, V> {
private E[] contents;
private V amount;

public Box(E[] contents, V amount) {
this.contents = contents;
this.amount = amount;
}

public E[] getContents() {
return this.contents;
}

public V getAmount() {
return this.amount;
}
}
31 changes: 31 additions & 0 deletions Seminar 1/JavaOOPExample/src/Class/Ferrari.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package Class;

import Interface.SportsCar;

public class Ferrari implements SportsCar {
private int maxSpeed;

public Ferrari(int maxSpeed) {
maxSpeed = this.maxSpeed;
}

public void go() {
System.out.println("페라리 주행하다");
}

public void stop() {
System.out.println("페라리 정지하다");
}

public void drift() {
System.out.println("드리프트!!");
}

public void open() {
System.out.println("차량커버 열기");
}

public void close() {
System.out.println("차량커버 닫기");
}
}
24 changes: 24 additions & 0 deletions Seminar 1/JavaOOPExample/src/Class/Morning.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package Class;

import AbstractClass.Car;

public class Morning extends Car {
private int price;

public Morning(String type, double fuelEfficiency, double oilAmount, int price) {
super(type, fuelEfficiency, oilAmount);
this.price = price;
}

public void go() {
System.out.println("모닝 주행하다");
}

public void stop() {
System.out.println("모닝 정지하다");
}

public void goBack() {
System.out.println("후진하다");
}
}
7 changes: 7 additions & 0 deletions Seminar 1/JavaOOPExample/src/Interface/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package Interface;

public interface Car {
void go();

void stop();
}
5 changes: 5 additions & 0 deletions Seminar 1/JavaOOPExample/src/Interface/SportsCar.java
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

인터페이스와 상속을 이해도 있게 잘 다루신 것 같아요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package Interface;

public interface SportsCar extends Car {
void drift();
}
30 changes: 30 additions & 0 deletions Seminar 1/JavaOOPExample/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Class.Box;
import Class.Ferrari;
import Class.Morning;
import Class.Avante;
import AbstractClass.Car;

public class Main {
public static void main(String[] args) {
Avante avante = new Avante("mid size", 15.2, 122.0, 19600000);
Morning morning = new Morning("small size", 12.7, 35.0, 9000000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

size에 관한 부분을 Enum을 통해 정적으로 구현해보면 어떨까요?

go(avante);
go(morning);
Ferrari ferrari = new Ferrari(330);
ferrari.go();
ferrari.drift();
Box<String, Integer> box = new Box(new String[]{"인형", "태블릿", "노트북"}, 3);
printArray((String[])box.getContents());
}

public static <T> void printArray(T[] array) {
for(T element : array) {
System.out.println(element);
}
}

public static void go(Car car) {
car.go();
}
}

6 changes: 6 additions & 0 deletions Seminar1/JavaOOPExample/.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 Seminar1/JavaOOPExample/.idea/modules.xml

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

6 changes: 6 additions & 0 deletions Seminar1/JavaOOPExample/.idea/vcs.xml

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

Loading