GRASP-Creator: Initial commit

This commit is contained in:
2022-05-07 23:26:40 +02:00
parent c939aacf1b
commit df8e71ad1b
6 changed files with 97 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>GRASP-Creator</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>

View File

@@ -0,0 +1,15 @@
public class Creator {
public static void main(String[] args) {
// TODO Auto-generated method stub
Sale theSale = new Sale();
theSale.Order(1, 1);
theSale.Order(2, 2);
theSale.Order(3, 3);
System.out.println("Total = " + theSale.Total());
}
}

View File

@@ -0,0 +1,26 @@
public class ProductSpecification {
public String description;
public double price;
public int itemID;
ProductSpecification(int i) {
itemID = i;
switch (i) {
case 1:
description = "Hammer";
price = 10.85;
break;
case 2:
description = "Screw";
price = 1.85;
break;
case 3:
description = "Nail";
price = 0.85;
break;
default:
break;
}
}
}

View File

@@ -0,0 +1,21 @@
import java.util.ArrayList;
import java.util.List;
public class Sale {
List<SalesLineltem> theSale = new ArrayList<>();
public void Order(int itemNo, int count) {
theSale.add( new SalesLineltem(itemNo, count) );
}
public double Total() {
double theTotal = 0.00;
for (SalesLineltem item: theSale) {
theTotal += item.price * item.numberOrdered;
System.out.println(item.description + " " + item.price + " " + item.numberOrdered + " " + item.price*item.numberOrdered);
}
return theTotal;
}
}

View File

@@ -0,0 +1,8 @@
public class SalesLineltem extends ProductSpecification {
public int numberOrdered;
public SalesLineltem(int item, int count) {
super(item);
numberOrdered = count;
}
}