diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000000000000000000000000000000000000..2b63946d5b31084bbb7dda418ceb3d75eb686373 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="Palette2"> + <group name="Swing"> + <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" /> + </item> + <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" /> + </item> + <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" /> + </item> + <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true"> + <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" /> + </item> + <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" /> + <initial-values> + <property name="text" value="Button" /> + </initial-values> + </item> + <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> + <initial-values> + <property name="text" value="RadioButton" /> + </initial-values> + </item> + <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> + <initial-values> + <property name="text" value="CheckBox" /> + </initial-values> + </item> + <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" /> + <initial-values> + <property name="text" value="Label" /> + </initial-values> + </item> + <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> + <preferred-size width="150" height="-1" /> + </default-constraints> + </item> + <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> + <preferred-size width="150" height="-1" /> + </default-constraints> + </item> + <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> + <preferred-size width="150" height="-1" /> + </default-constraints> + </item> + <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" /> + </item> + <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> + <preferred-size width="200" height="200" /> + </default-constraints> + </item> + <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> + <preferred-size width="200" height="200" /> + </default-constraints> + </item> + <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> + </item> + <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> + </item> + <item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" /> + </item> + <item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" /> + </item> + <item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1"> + <preferred-size width="-1" height="20" /> + </default-constraints> + </item> + <item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" /> + </item> + <item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" /> + </item> + </group> + </component> +</project> \ No newline at end of file diff --git a/pom.xml b/pom.xml index c6ec7694f1a39e8bbe8d06c05e20bbccad615ceb..5348f6f380445d28681a7e9b2db628e1a57ff636 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 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>nl.utwente.di</groupId> - <artifactId>bookQuote</artifactId> + <artifactId>temperatureCalculator</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <properties> diff --git a/src/main/java/nl/utwente/di/bookQuote/Quoter.java b/src/main/java/nl/utwente/di/bookQuote/Quoter.java deleted file mode 100644 index c6edd1b07e574f42766ef1543942f1e7751afa5a..0000000000000000000000000000000000000000 --- a/src/main/java/nl/utwente/di/bookQuote/Quoter.java +++ /dev/null @@ -1,24 +0,0 @@ -package nl.utwente.di.bookQuote; - -import java.util.HashMap; - -public class Quoter { - private static HashMap<String, Double> bookPrices = new HashMap<>(); - - public Quoter() { - bookPrices.put("1", 10.0); - bookPrices.put("2", 45.0); - bookPrices.put("3", 20.0); - bookPrices.put("4", 35.0); - bookPrices.put("5", 50.0); - bookPrices.put("others", 0.0); - } - - public double getBookPrice(String isbn) { - if (bookPrices.containsKey(isbn)) { - return bookPrices.get(isbn); - } else { - return 0; - } - } -} diff --git a/src/main/java/nl/utwente/di/temperatureCalculator/Calculator.java b/src/main/java/nl/utwente/di/temperatureCalculator/Calculator.java new file mode 100644 index 0000000000000000000000000000000000000000..f98cdc9cdc25046dfda8feff3598540f29262a98 --- /dev/null +++ b/src/main/java/nl/utwente/di/temperatureCalculator/Calculator.java @@ -0,0 +1,12 @@ +package nl.utwente.di.temperatureCalculator; + +public class Calculator { + public double getTemperature(String temperature) { + try { + double temperatureInt = Integer.parseInt(temperature); + return (((temperatureInt * 9) / 5) + 32); + } catch (Exception e) { + return 0; + } + } +} diff --git a/src/main/java/nl/utwente/di/bookQuote/BookQuote.java b/src/main/java/nl/utwente/di/temperatureCalculator/TemperatureCalculator.java similarity index 74% rename from src/main/java/nl/utwente/di/bookQuote/BookQuote.java rename to src/main/java/nl/utwente/di/temperatureCalculator/TemperatureCalculator.java index 3338eb104e7b17406cc229ef9625c7304719b173..d513894963a4791534d6e887f2cd2bce8bee51ad 100644 --- a/src/main/java/nl/utwente/di/bookQuote/BookQuote.java +++ b/src/main/java/nl/utwente/di/temperatureCalculator/TemperatureCalculator.java @@ -1,4 +1,4 @@ -package nl.utwente.di.bookQuote; +package nl.utwente.di.temperatureCalculator; import java.io.*; import jakarta.servlet.*; @@ -7,12 +7,12 @@ import jakarta.servlet.http.*; /** Example of a Servlet that gets an ISBN number and returns the book price */ -public class BookQuote extends HttpServlet { +public class TemperatureCalculator extends HttpServlet { private static final long serialVersionUID = 1L; - private Quoter quoter; + private Calculator calculator; public void init() throws ServletException { - quoter = new Quoter(); + calculator = new Calculator(); } public void doGet(HttpServletRequest request, @@ -21,7 +21,7 @@ public class BookQuote extends HttpServlet { response.setContentType("text/html"); PrintWriter out = response.getWriter(); - String title = "Book Quote"; + String title = "Temperature Calculator"; // Done with string concatenation only for the demo // Not expected to be done like this in the project @@ -33,9 +33,9 @@ public class BookQuote extends HttpServlet { "<BODY BGCOLOR=\"#FDF5E6\">\n" + "<H1>" + title + "</H1>\n" + " <P>ISBN number: " + - request.getParameter("isbn") + "\n" + + request.getParameter("temperature") + "\n" + " <P>Price: " + - quoter.getBookPrice(request.getParameter("isbn")) + + calculator.getTemperature(request.getParameter("temperature")) + "</BODY></HTML>"); } } diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 625a2326f2edd709db73283d66053e48676ce617..76bb957c90577eae39c48ebff26d8d3ebc3a1977 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -5,7 +5,7 @@ https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd" version="6.0"> - <display-name>di.bookQuote</display-name> + <display-name>di.Temperature</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> @@ -16,13 +16,13 @@ <welcome-file>default.jsp</welcome-file> </welcome-file-list> <servlet> - <description>BookQuote Servlet</description> - <display-name>BookQuote</display-name> - <servlet-name>BookQuote</servlet-name> - <servlet-class>nl.utwente.di.bookQuote.BookQuote</servlet-class> + <description>Temperature Servlet</description> + <display-name>Temperature</display-name> + <servlet-name>Temperature</servlet-name> + <servlet-class>nl.utwente.di.temperatureCalculator.TemperatureCalculator</servlet-class> </servlet> <servlet-mapping> - <servlet-name>BookQuote</servlet-name> - <url-pattern>/bookQuote</url-pattern> + <servlet-name>Temperature</servlet-name> + <url-pattern>/Temperature</url-pattern> </servlet-mapping> </web-app> \ No newline at end of file diff --git a/src/main/webapp/index.html b/src/main/webapp/index.html index 7240a9b36739bdc5d9eb43e8e880b83655284e58..0282b0f7c870bcb6cd48695b7e281f1dd4c72ff8 100644 --- a/src/main/webapp/index.html +++ b/src/main/webapp/index.html @@ -9,10 +9,10 @@ </head> <body> -<h1>Web Book Quote Application</h1> +<h1>Celsius to Fahrenheit Calculator</h1> -<form ACTION="./bookQuote"> - <p>Enter ISBN number: <input TYPE="TEXT" NAME="isbn"></p> +<form ACTION="./temperatureCalculator"> + <p>Enter temperature in Celsius: <input TYPE="TEXT" NAME="temperature"></p> <input TYPE="SUBMIT"> </form> diff --git a/src/test/java/nl/utwente/di/bookQuote/TestQuoter.java b/src/test/java/nl/utwente/di/bookQuote/TestCalculator.java similarity index 56% rename from src/test/java/nl/utwente/di/bookQuote/TestQuoter.java rename to src/test/java/nl/utwente/di/bookQuote/TestCalculator.java index eb60b35eceb460070c71dae64c90395bfac3013d..c4abfb9b34940b375182a311d775fadd0461db5f 100644 --- a/src/test/java/nl/utwente/di/bookQuote/TestQuoter.java +++ b/src/test/java/nl/utwente/di/bookQuote/TestCalculator.java @@ -1,14 +1,15 @@ package nl.utwente.di.bookQuote; +import nl.utwente.di.temperatureCalculator.Calculator; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -public class TestQuoter { +public class TestCalculator { @Test public void testBook1() throws Exception { - Quoter quoter = new Quoter(); - double price = quoter.getBookPrice("1"); + Calculator calculator = new Calculator(); + double price = calculator.getTemperature("1"); Assertions.assertEquals(10.0, price, 0.0, "Price of book 1"); }