Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
silly-portugeese authored Oct 14, 2022
0 parents commit 4a4d09e
Show file tree
Hide file tree
Showing 47 changed files with 558 additions and 0 deletions.
18 changes: 18 additions & 0 deletions glue.iml
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>
25 changes: 25 additions & 0 deletions pom.xml
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>
28 changes: 28 additions & 0 deletions src/main/java/Factory.java
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);

}

}
16 changes: 16 additions & 0 deletions src/main/java/Main.java
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();
}

}
8 changes: 8 additions & 0 deletions src/main/java/display/ConsoleDisplay.java
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);
}
}
18 changes: 18 additions & 0 deletions src/main/java/display/DisplayFactory.java
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.");

}
}
32 changes: 32 additions & 0 deletions src/main/java/display/DisplayPDF.java
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();
}
}

}
22 changes: 22 additions & 0 deletions src/main/java/display/DisplayTXT.java
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);
}
}
}
5 changes: 5 additions & 0 deletions src/main/java/display/DisplayType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package display;

public enum DisplayType {
CONSOLE,TXT,PDF
}
5 changes: 5 additions & 0 deletions src/main/java/display/IDisplay.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package display;

public interface IDisplay {
void display(String output);
}
41 changes: 41 additions & 0 deletions src/main/java/glue/AbstractGlue.java
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);
}

}
30 changes: 30 additions & 0 deletions src/main/java/glue/GlueFactory.java
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.");

}

}
5 changes: 5 additions & 0 deletions src/main/java/glue/GlueType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package glue;

public enum GlueType {
PRITTSTIK, SUPERGLUE, WOODGLUE, SHITTYGLUE
}
11 changes: 11 additions & 0 deletions src/main/java/glue/Prittstik.java
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);
}
}
11 changes: 11 additions & 0 deletions src/main/java/glue/ShittyGlue.java
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);
}
}
11 changes: 11 additions & 0 deletions src/main/java/glue/SuperGlue.java
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);
}
}
11 changes: 11 additions & 0 deletions src/main/java/glue/WoodGlue.java
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);
}

}
12 changes: 12 additions & 0 deletions src/main/java/output/AbstractOutput.java
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";
}


}

36 changes: 36 additions & 0 deletions src/main/java/output/FriendlyOutput.java
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);*/
14 changes: 14 additions & 0 deletions src/main/java/output/OutputFactory.java
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.");
}
}
5 changes: 5 additions & 0 deletions src/main/java/output/OutputType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package output;

public enum OutputType {
RAW, FRIENDLY
}
Loading

0 comments on commit 4a4d09e

Please sign in to comment.