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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 12 additions & 0 deletions java-oop-design-pattern/RemoteSystemsTempFiles/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>RemoteSystemsTempFiles</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
<nature>org.eclipse.rse.ui.remoteSystemsTempNature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions java-oop-design-pattern/ch1-Student-Transcript-Course/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ch1-Student-Transcript-Course</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import java.util.Iterator;
import java.util.Vector;


public class Course {
private Vector<Transcript> transcripts;
private String name;

public Course(String name) {
this.name = name;
transcripts = new Vector<Transcript>();
}
public void addTranscript(Transcript transcript) {
transcripts.add(transcript);
}
public String getName() {
return name;
}

public Vector<Student> getStudents() {
Vector<Student> students = new Vector<Student>();
Iterator<Transcript> itor = transcripts.iterator();

while (itor.hasNext()) {
Transcript tr = itor.next();
students.add(tr.getStudent());
}
return students;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import java.util.Vector;


public class Main {


public static void main(String[] args) {
Student s1 = new Student("ManSup");
Student s2 = new Student("GilDong");
Student s3 = new Student("GilSeo");
Course se = new Course("Software Engineering");
Course designPattern = new Course("Design Pattern");
Transcript t1 = new Transcript(s1, se);
Transcript t2 = new Transcript(s1, designPattern);
Transcript t3 = new Transcript(s2, designPattern);
Transcript t4 = new Transcript(s1, designPattern);

t1.setDate("2012");
t1.setGrade("B0");
t3.setDate("2013");
t3.setGrade("C+");
t2.setDate("2012");
t2.setGrade("D+");
t4.setDate("2013");
t4.setGrade("A+");

Vector<Course> courses;

courses = s1.getCourses();
for (int i=0; i<courses.size(); i++)
System.out.println(courses.get(i).getName());

Vector<Student> students;

students = designPattern.getStudents();
for (int i=0; i<students.size(); i++)
System.out.println(students.get(i).getName());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import java.util.Iterator;
import java.util.Vector;




public class Student {
private Vector<Transcript> transcripts;
private String name;

public Student(String name) {
this.name = name;
transcripts = new Vector<Transcript>();
}
public void addTranscript(Transcript transcript) {
transcripts.add(transcript);
}
public Vector<Course> getCourses() {
Vector<Course> courses = new Vector<Course>();
Iterator<Transcript> itor = transcripts.iterator();

while (itor.hasNext()) {
Transcript tr = itor.next();
courses.add(tr.getCourse());
}
return courses;
}
public String getName() {
// TODO Auto-generated method stub
return this.name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

public class Transcript {
private Student student;
private Course course;

private String date;
private String grade;
public Transcript(Student student, Course course) {
this.student = student;
this.student.addTranscript(this);
this.course = course;
this.course.addTranscript(this);
}

public Student getStudent() {
return student;
}

public Course getCourse() {
return course;
}

public void setDate(String date) {
this.date = date;
}

public String getDate() {
return date;
}

public void setGrade(String grade) {
this.grade = grade;
}

public String getGrade() {
return grade;
}
}
6 changes: 6 additions & 0 deletions java-oop-design-pattern/ch2-문제4-답/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions java-oop-design-pattern/ch2-문제4-답/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ch2-문제4-답</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
26 changes: 26 additions & 0 deletions java-oop-design-pattern/ch2-문제4-답/src/CartForSongs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Iterator;


public class CartForSongs {

ArrayList<Song> cart = new ArrayList<Song>();
public double calculateTotalPrice() {

double total = 0.0;
Iterator<Song> itr = cart.iterator();

while (itr.hasNext()) {
Song s = itr.next();
total = total+s.getPrice();

}
return total;
}

public void add(Song s) {
cart.add(s);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

public abstract class DiscountedMode {
public abstract double getDiscountRate();

}
27 changes: 27 additions & 0 deletions java-oop-design-pattern/ch2-문제4-답/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

public class Main {

/**
* @param args
*/
public static void main(String[] args) {
Song s1 = new Song();
s1.setMode(new NonDiscounted());
Song s2 = new Song();
s2.setMode(new NonDiscounted());
Song s3 = new Song();
s3.setMode(new OnSale());
Song s4 = new Song();
s4.setMode(new TodayEvent());

CartForSongs c = new CartForSongs();
c.add(s1);
c.add(s2);
c.add(s3);
c.add(s4);

System.out.println(c.calculateTotalPrice());

}

}
10 changes: 10 additions & 0 deletions java-oop-design-pattern/ch2-문제4-답/src/NonDiscounted.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

public class NonDiscounted extends DiscountedMode {

@Override
public double getDiscountRate() {
// TODO Auto-generated method stub
return 0.0;
}

}
10 changes: 10 additions & 0 deletions java-oop-design-pattern/ch2-문제4-답/src/OnSale.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

public class OnSale extends DiscountedMode {

@Override
public double getDiscountRate() {
// TODO Auto-generated method stub
return 0.1;
}

}
10 changes: 10 additions & 0 deletions java-oop-design-pattern/ch2-문제4-답/src/Song.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

public class Song {
private DiscountedMode mode;
public void setMode(DiscountedMode mode) {
this.mode = mode;
}
public double getPrice() {
return 10.0-(10.0*this.mode.getDiscountRate());
}
}
10 changes: 10 additions & 0 deletions java-oop-design-pattern/ch2-문제4-답/src/TodayEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

public class TodayEvent extends DiscountedMode {

@Override
public double getDiscountRate() {
// TODO Auto-generated method stub
return 0.3;
}

}
6 changes: 6 additions & 0 deletions java-oop-design-pattern/ch2-문제4/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions java-oop-design-pattern/ch2-문제4/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ch2-문제4</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
Binary file not shown.
Binary file added java-oop-design-pattern/ch2-문제4/bin/Main.class
Binary file not shown.
Binary file added java-oop-design-pattern/ch2-문제4/bin/Song.class
Binary file not shown.
Loading