diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..13566b81b018ad684f3a35fee301741b2734c8f4 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/Repo.iml b/.idea/Repo.iml new file mode 100644 index 0000000000000000000000000000000000000000..d6ebd4805981b8400db3e3291c74a743fef9a824 --- /dev/null +++ b/.idea/Repo.iml @@ -0,0 +1,9 @@ +<?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$" /> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + </component> +</module> \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000000000000000000000000000000000000..639900d13c6182e452e33a3bd638e70a0146c785 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectRootManager"> + <output url="file://$PROJECT_DIR$/out" /> + </component> +</project> \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000000000000000000000000000000000..640ac764fc4db6363cb4cd0b9f6aa962c6447f7a --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/.idea/Repo.iml" filepath="$PROJECT_DIR$/.idea/Repo.iml" /> + </modules> + </component> +</project> \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000000000000000000000000000000000..35eb1ddfbbc029bcab630581847471d7f238ec53 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="" vcs="Git" /> + </component> +</project> \ No newline at end of file diff --git a/Oving 11/.gitignore b/Oving 11/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..f68d1099657e34d4e7a68aadc730b3ecad84667d --- /dev/null +++ b/Oving 11/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/Oving 11/.idea/.gitignore b/Oving 11/.idea/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..13566b81b018ad684f3a35fee301741b2734c8f4 --- /dev/null +++ b/Oving 11/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/Oving 11/.idea/misc.xml b/Oving 11/.idea/misc.xml new file mode 100644 index 0000000000000000000000000000000000000000..862d09bd69c427137b14be8c854f15fa1da97d2f --- /dev/null +++ b/Oving 11/.idea/misc.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectRootManager" version="2" languageLevel="JDK_20" default="true" project-jdk-name="20" project-jdk-type="JavaSDK"> + <output url="file://$PROJECT_DIR$/out" /> + </component> +</project> \ No newline at end of file diff --git a/Oving 11/.idea/modules.xml b/Oving 11/.idea/modules.xml new file mode 100644 index 0000000000000000000000000000000000000000..1b624e90c056da1e77c337cfb5285061ebf46301 --- /dev/null +++ b/Oving 11/.idea/modules.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/Oving 11.iml" filepath="$PROJECT_DIR$/Oving 11.iml" /> + </modules> + </component> +</project> \ No newline at end of file diff --git a/Oving 11/Oving 11.iml b/Oving 11/Oving 11.iml new file mode 100644 index 0000000000000000000000000000000000000000..c90834f2d607afe55e6104d8aa2cdfffb713f688 --- /dev/null +++ b/Oving 11/Oving 11.iml @@ -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> \ No newline at end of file diff --git a/Oving 11/src/Main.java b/Oving 11/src/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..80be45f82950464672f7a779bf5c99fc161326d5 --- /dev/null +++ b/Oving 11/src/Main.java @@ -0,0 +1,7 @@ + +public class Main { + public static void main(String[] args) { + Utils pr = new Utils(); + pr.menu(); + } +} \ No newline at end of file diff --git a/Oving 11/src/Property.java b/Oving 11/src/Property.java new file mode 100644 index 0000000000000000000000000000000000000000..ab800f9a64b9ef13efc22c47fc9eed65cb9bb0db --- /dev/null +++ b/Oving 11/src/Property.java @@ -0,0 +1,82 @@ +public class Property { + + // Oppretter objektvariabler for klassen. + private final int municipalityNumber; + private final String municipalityName; + private final int lotNumber; + private final int sectionNumber; + private String name; + private double area; + private String nameOfOwner; + + // Enkel konstruktør. + public Property(int municipalityNumber, String municipalityName, int lotNumber, int sectionNumber, String name, double area, String nameOfOwner) { + this.municipalityNumber = municipalityNumber; + this.municipalityName = municipalityName; + this.lotNumber = lotNumber; + this.sectionNumber = sectionNumber; + this.name = name; + this.area = area; + this.nameOfOwner = nameOfOwner; + } + + // Getters and setters for nødvendige variabler. + public int getMunicipalityNumber() { + return municipalityNumber; + } + + public String getMunicipalityName() { + return municipalityName; + } + + public int getLotNumber() { + return lotNumber; + } + + public int getSectionNumber() { + return sectionNumber; + } + + public String getName() { + return name; + } + + public double getArea() { + return area; + } + + public String getNameOfOwner() { + return nameOfOwner; + } + + public void setName(String name) { + this.name = name; + } + + public void setArea(double area) { + this.area = area; + } + + public void setNameOfOwner(String nameOfOwner) { + this.nameOfOwner = nameOfOwner; + } + + // Metode for å skrive ut ID. + + public String getID () { + return municipalityNumber + "-" + lotNumber + "/" + sectionNumber; + } + + @Override + public String toString() { + return "Municipality number: " + municipalityNumber + + "\nMunicipality name: " + municipalityName + + "\nLot number: " + lotNumber + + "\nSection number: " + sectionNumber + + "\nName: " + name + + "\nArea: " + area + "m2" + + "\nName of owner: " + nameOfOwner; + } +} + + diff --git a/Oving 11/src/PropertyRegister.java b/Oving 11/src/PropertyRegister.java new file mode 100644 index 0000000000000000000000000000000000000000..b8fa642d3ba186173319ec0adfc78d422660fac8 --- /dev/null +++ b/Oving 11/src/PropertyRegister.java @@ -0,0 +1,125 @@ +import java.util.HashMap; +import static javax.swing.JOptionPane.*; + +public class PropertyRegister { + + // Oppretter et hashmap fordi jeg vil at en eiendom skal hentes ut med en unik ID. + + private HashMap <String, Property> pr = new HashMap <String, Property>(); + + public PropertyRegister() { + } + + // Metode for å registrere en eiendom. + public void newProperty() { + int municipalityNumber = Integer.parseInt(showInputDialog("Municipality number:")); + String municipalityName = showInputDialog("Municipality name:"); + int lotNumber = Integer.parseInt(showInputDialog("Lot number:")); + int sectionNumber = Integer.parseInt(showInputDialog("Section number:")); + String name = showInputDialog("Name:"); + double area = Double.parseDouble(showInputDialog("Area:")); + String nameOfOwner = showInputDialog("Name of owner:"); + String iD = municipalityNumber + "-" + lotNumber + "/" + sectionNumber; + + pr.put(iD, new Property(municipalityNumber, municipalityName, lotNumber, sectionNumber, name, area, nameOfOwner)); + System.out.println(pr); + + } + + //Metode for å liste opp alle eiendommene + public void listAllProperties() { + StringBuilder output = new StringBuilder(); + for (Property property : pr.values()) { + output.append(property).append("\n------------------------------------------\n"); + } + if (output.isEmpty()) { + showMessageDialog(null, "There are no registered properties"); + } else { + showMessageDialog(null, output); + } + + } + + // Metode for å fjerne en eiendom. + public void removeProperty(String propertyID) { + boolean propertyRemoved = false; + + for (String property : pr.keySet()) { + if (property.equals(propertyID)) { + pr.remove(property); + showMessageDialog(null, "Property with ID" + property + " has been removed"); + propertyRemoved = true; + break; + } + } + + if (!propertyRemoved) { + showMessageDialog(null, "Property with ID " + propertyID + " not found."); + } + + } + + // Metode for å returnere antall eiendommer i registeret. + public void amountOfProperties(){ + showMessageDialog(null, "Amount of properties: " + pr.size()); + } + + // Metode for å finne eiendom baser på ID. + + public void findProperty() { + int municipalityNumber = Integer.parseInt(showInputDialog("Municipality number:")); + int lotNumber = Integer.parseInt(showInputDialog("Lot number:")); + int sectionNumber = Integer.parseInt(showInputDialog("Section number:")); + String propertyID = municipalityNumber + "-" + lotNumber + "/" + sectionNumber; + boolean propertyFound = false; + + for (String property : pr.keySet()) { + if (property.equals(propertyID)) { + showMessageDialog(null, pr.get(property)); + propertyFound = true; + break; + } + } + + if (!propertyFound) { + showMessageDialog(null, "Property with ID " + propertyID + " not found."); + } + + } + + public void averageArea() { + double totalArea = 0; + for (Property property : pr.values()) { + totalArea += property.getArea(); + } + double averageArea = totalArea / pr.size(); + String formattedAverageArea = String.format("%.2f", averageArea); + + showMessageDialog(null, "Average area of all the properties: " + formattedAverageArea + "m2"); + // showMessageDialog(null, "Average area of all the properties: " + averageArea + "m2"); + } + + public void findPropertyBasedOnLotNumber(int lotNumber) { + StringBuilder output = new StringBuilder(); + for (Property property : pr.values()) { + if (property.getLotNumber() == lotNumber) { + output.append(property).append("\n------------------------------------------\n"); + } + } + if (output.isEmpty()) { + showMessageDialog(null, "There is no property with lot number: " + lotNumber); + } else { + showMessageDialog(null, output); + } + } + + public void testData() { + pr.put(1445 + "-" + 77 + "/" + 631, new Property(1445, "Gloppen", 77, 631, "", 1017.6, "Jens Olsen")); + pr.put(1445 + "-" + 77 + "/" + 131, new Property(1445, "Gloppen", 77, 131, "Syningom", 661.3, "Nicolay Madsen")); + pr.put(1445 + "-" + 75 + "/" + 19, new Property(1445, "Gloppen", 75, 19, "Fugletun", 650.6, "Evilyn Jensen")); + pr.put(1445 + "-" + 74 + "/" + 188, new Property(1445, "Gloppen", 74, 188, "", 1457.2, "Karl Ove Bråten")); + pr.put(1445 + "-" + 69 + "/" + 47, new Property(1445, "Gloppen", 69, 47, "Høiberg", 1339.4, "Elsa Indregård")); + } + + +} diff --git a/Oving 11/src/Utils.java b/Oving 11/src/Utils.java new file mode 100644 index 0000000000000000000000000000000000000000..40aa195fdb7b36ee030743d0df66a8e774fcbe77 --- /dev/null +++ b/Oving 11/src/Utils.java @@ -0,0 +1,54 @@ +import static javax.swing.JOptionPane.*; + +public class Utils { + PropertyRegister pr = new PropertyRegister(); + + public Utils() { + } + + public void menu(){ + pr.testData(); + + while (true) { + String choice = showInputDialog( + "What do you want to do?\n" + + "1. Add property\n" + + "2. List all properties\n" + + "3. Search property\n" + + "4. Calculate average area\n" + + "5. Remove property\n" + + "6. List all properties based on lot number\n" + + "7. Amount of properties registered\n" + + "8. Exit"); + + switch (choice) { + case "1": + pr.newProperty(); + break; + case "2": + pr.listAllProperties(); + break; + case "3": + pr.findProperty(); + break; + case "4": + pr.averageArea(); + break; + case "5": + pr.removeProperty(showInputDialog("Property ID (Format: Municipality number-Lot number/Section number) e.g. 1504-54/73")); + break; + case "6": + pr.findPropertyBasedOnLotNumber(Integer.parseInt(showInputDialog("Lot number:"))); + break; + case "7": + pr.amountOfProperties(); + break; + case "8": + System.exit(0); + default: + showMessageDialog(null, "Please choose and option by entering a digit between 1-8"); + + } + } + } +}