-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4a4d09e
Showing
47 changed files
with
558 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_19"> | ||
<output url="file://$MODULE_DIR$/target/classes" /> | ||
<output-test url="file://$MODULE_DIR$/target/test-classes" /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> | ||
<excludeFolder url="file://$MODULE_DIR$/target" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="library" name="junit.jupiter" level="project" /> | ||
<orderEntry type="library" name="assertj.core" level="project" /> | ||
<orderEntry type="library" name="Maven: com.itextpdf:itextpdf:5.5.13.3" level="project" /> | ||
</component> | ||
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>groupId</groupId> | ||
<artifactId>Glues</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.itextpdf</groupId> | ||
<artifactId>itextpdf</artifactId> | ||
<version>5.5.13.3</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<properties> | ||
<maven.compiler.source>19</maven.compiler.source> | ||
<maven.compiler.target>19</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import display.DisplayFactory; | ||
import display.DisplayType; | ||
import display.IDisplay; | ||
import glue.AbstractGlue; | ||
import glue.GlueFactory; | ||
import glue.GlueType; | ||
import output.AbstractOutput; | ||
import output.OutputFactory; | ||
import output.OutputType; | ||
|
||
public class Factory { | ||
DisplayFactory displayFactory = new DisplayFactory(); | ||
OutputFactory outputFactory = new OutputFactory(); | ||
|
||
public AbstractGlue createGlue(GlueType g, DisplayType d, OutputType o) { | ||
return new GlueFactory().makeGlue(g, createDisplay(d), createOutput(o)); | ||
} | ||
|
||
private IDisplay createDisplay(DisplayType dType) { | ||
return displayFactory.makeDisplay(dType); | ||
} | ||
|
||
private AbstractOutput createOutput(OutputType oType) { | ||
return outputFactory.makeOutput(oType); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import display.DisplayType; | ||
import glue.AbstractGlue; | ||
import glue.GlueType; | ||
import output.OutputType; | ||
|
||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
Factory myFactory = new Factory(); | ||
AbstractGlue superglue = myFactory.createGlue(GlueType.SUPERGLUE, DisplayType.CONSOLE, OutputType.FRIENDLY); | ||
AbstractGlue prittstik = myFactory.createGlue(GlueType.PRITTSTIK, DisplayType.TXT, OutputType.RAW); | ||
superglue.display(); | ||
prittstik.display(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package display; | ||
|
||
public class ConsoleDisplay implements IDisplay { | ||
@Override | ||
public void display(String output) { | ||
System.out.println(output); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package display; | ||
|
||
public class DisplayFactory { | ||
|
||
public IDisplay makeDisplay(DisplayType displayType) { | ||
if (displayType == DisplayType.CONSOLE) | ||
return new ConsoleDisplay(); | ||
|
||
if (displayType == DisplayType.TXT) | ||
return new DisplayTXT(); | ||
|
||
if (displayType == DisplayType.PDF) | ||
return new DisplayPDF(); | ||
|
||
throw new RuntimeException("The specified display type does not exist."); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package display; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
|
||
import com.itextpdf.text.Document; | ||
import com.itextpdf.text.DocumentException; | ||
import com.itextpdf.text.Paragraph; | ||
import com.itextpdf.text.pdf.PdfWriter; | ||
|
||
public class DisplayPDF implements IDisplay { | ||
|
||
@Override | ||
public void display(String output){ | ||
|
||
String fileName = "/Output" + ".pdf"; | ||
String filePath = System.getProperty("user.dir") + fileName; | ||
|
||
try { | ||
Document document = new Document(); | ||
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filePath)); | ||
document.open(); | ||
document.add(new Paragraph(output)); | ||
document.close(); | ||
writer.close(); | ||
} | ||
catch (DocumentException | FileNotFoundException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package display; | ||
|
||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
|
||
public class DisplayTXT implements IDisplay { | ||
|
||
@Override | ||
public void display(String output){ | ||
try { | ||
String fileName = "/Output" + ".txt"; | ||
String filePath = System.getProperty("user.dir") + fileName; | ||
PrintWriter writer = new PrintWriter(new FileWriter(filePath)); | ||
writer.write(output); | ||
writer.close(); | ||
} | ||
catch (IOException ex) { | ||
throw new RuntimeException(ex); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package display; | ||
|
||
public enum DisplayType { | ||
CONSOLE,TXT,PDF | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package display; | ||
|
||
public interface IDisplay { | ||
void display(String output); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package glue; | ||
|
||
import display.IDisplay; | ||
import output.AbstractOutput; | ||
|
||
public abstract class AbstractGlue { | ||
|
||
private String Name; | ||
private String Type; | ||
private int SizeInMillis; | ||
private boolean AdheresToPlastic; | ||
private boolean AdheresToWood; | ||
private boolean AdheresToMetal; | ||
private boolean AdheresToGlass; | ||
private boolean AdheresToPottery; | ||
private int CuringTimeInMinutes; | ||
private double Price; | ||
private IDisplay ThisDisplay; | ||
private AbstractOutput ThisOutput; | ||
|
||
public AbstractGlue(AbstractOutput output, IDisplay display, String name, String type, int size, boolean plastic, boolean wood, boolean metal, boolean glass, boolean pottery, int curing, double price) { | ||
Name = name; | ||
Type = type; | ||
SizeInMillis = size; | ||
AdheresToWood = wood; | ||
AdheresToMetal = metal; | ||
AdheresToGlass = glass; | ||
AdheresToPlastic = plastic; | ||
AdheresToPottery = pottery; | ||
CuringTimeInMinutes = curing; | ||
Price = price; | ||
ThisDisplay = display; | ||
ThisOutput = output; | ||
} | ||
|
||
public void display(){ | ||
ThisOutput.createOutput(Name, Type, SizeInMillis,AdheresToWood,AdheresToMetal,AdheresToGlass,AdheresToPlastic,AdheresToPottery,CuringTimeInMinutes,Price); | ||
ThisDisplay.display(ThisOutput.output); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package glue; | ||
|
||
import display.IDisplay; | ||
import output.AbstractOutput; | ||
|
||
public class GlueFactory { | ||
|
||
|
||
public AbstractGlue makeGlue(GlueType glueType, IDisplay display, AbstractOutput output) { | ||
|
||
if (glueType==GlueType.PRITTSTIK) { | ||
return new Prittstik(display,output); | ||
} | ||
if (glueType==GlueType.SUPERGLUE) { | ||
return new SuperGlue(display,output); | ||
|
||
} | ||
if (glueType==GlueType.WOODGLUE) { | ||
return new WoodGlue(display,output); | ||
|
||
} | ||
if (glueType==GlueType.SHITTYGLUE) { | ||
return new ShittyGlue(display,output); | ||
|
||
} | ||
throw new RuntimeException("The specified glue type does not exist."); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package glue; | ||
|
||
public enum GlueType { | ||
PRITTSTIK, SUPERGLUE, WOODGLUE, SHITTYGLUE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package glue; | ||
|
||
import display.IDisplay; | ||
import output.AbstractOutput; | ||
|
||
public class Prittstik extends AbstractGlue { | ||
|
||
public Prittstik(IDisplay display, AbstractOutput output) { | ||
super(output,display,"Prittstik", "Metal", 10, true, true, false, false, true, 14, 4.00); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package glue; | ||
|
||
import display.IDisplay; | ||
import output.AbstractOutput; | ||
|
||
|
||
public class ShittyGlue extends AbstractGlue{ | ||
public ShittyGlue(IDisplay display, AbstractOutput output) { | ||
super(output,display,"ShittyGlue", "Tube", 5, false, false, false, false, false, 9, 3.00); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package glue; | ||
|
||
import display.IDisplay; | ||
import output.AbstractOutput; | ||
|
||
|
||
public class SuperGlue extends AbstractGlue { | ||
public SuperGlue(IDisplay display, AbstractOutput output) { | ||
super(output,display,"SuperGlue", "Bottle", 5, true, true, true, true, true, 9, 6.00); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package glue; | ||
|
||
import display.IDisplay; | ||
import output.AbstractOutput; | ||
|
||
public class WoodGlue extends AbstractGlue { | ||
public WoodGlue(IDisplay display, AbstractOutput output) { | ||
super(output,display,"WoodGlue", "Tube", 13, false, true, false, true, false, 17, 7.00); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package output; | ||
|
||
public abstract class AbstractOutput { | ||
public String output; | ||
abstract public void createOutput(String name, String type, int size, boolean plastic, boolean wood, boolean metal, boolean glass, boolean pottery, int curing, double price); | ||
public void writeOutput(String text) { | ||
output += text + "\r\n"; | ||
} | ||
|
||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package output; | ||
|
||
public class FriendlyOutput extends AbstractOutput { | ||
|
||
public void createOutput(String name, String type, int size, boolean plastic, boolean wood, boolean metal, boolean glass, boolean pottery, int curing, double price) { | ||
output = ""; | ||
this.writeOutput("Glue Name: " + name); | ||
this.writeOutput("Glue Type: " + type); | ||
this.writeOutput("Glue Size: " + size + " mm"); | ||
|
||
String ad = Adherants(plastic, wood, metal, glass, pottery); | ||
if (!ad.isEmpty()) this.writeOutput("Glue Adheres to: " + ad); | ||
String notAd = NotAdherants(plastic, wood, metal, glass, pottery); | ||
if (!notAd.isEmpty()) this.writeOutput("Glue Not to be used on: " + notAd); | ||
this.writeOutput("Glue Curing Time: " + curing + " min"); | ||
this.writeOutput("Glue Price: " + price + "£"); | ||
} | ||
|
||
public String Adherants(boolean plastic, boolean wood, boolean metal, boolean glass, boolean pottery) { | ||
String adherents = (plastic ? "Plastic ":"") + (wood ? "Wood ":"") + (metal ? "Metal ":"") + (glass ? "Glass ":"") + (pottery ? "Pottery ":""); | ||
return adherents.trim().replace(" ",", "); | ||
} | ||
|
||
public String NotAdherants(boolean plastic, boolean wood, boolean metal, boolean glass, boolean pottery) { | ||
String adherents = (!plastic ? "Plastic ":"") + (!wood ? "Wood ":"") + (!metal ? "Metal ":"") + (!glass ? "Glass ":"") + (!pottery ? "Pottery ":""); | ||
return adherents.trim().replace(" ",", "); | ||
} | ||
|
||
} | ||
|
||
/* Dictionary<String, Boolean> Adhere = new Hashtable<>(); | ||
Adhere.put("Plastic",plastic); | ||
Adhere.put("Wood",wood); | ||
Adhere.put("Metal",metal); | ||
Adhere.put("Glass",glass); | ||
Adhere.put("Pottery",pottery);*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package output; | ||
|
||
public class OutputFactory { | ||
|
||
public AbstractOutput makeOutput(OutputType outputType) { | ||
if (outputType == OutputType.RAW) | ||
return new RawOutput(); | ||
|
||
if (outputType == OutputType.FRIENDLY) | ||
return new FriendlyOutput(); | ||
|
||
throw new RuntimeException("The specified output type does not exist."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package output; | ||
|
||
public enum OutputType { | ||
RAW, FRIENDLY | ||
} |
Oops, something went wrong.