From d58eb989d5b5fa5677bacaaf64d35b14ae98823f Mon Sep 17 00:00:00 2001 From: Bender Date: Tue, 27 Sep 2022 14:28:54 -0500 Subject: [PATCH] initial commit --- .gitignore | 1 + .idea/.gitignore | 8 ++ CS144-007-EXAMPLE/.classpath | 6 + CS144-007-EXAMPLE/.gitignore | 1 + CS144-007-EXAMPLE/.project | 17 +++ .../org.eclipse.core.resources.prefs | 2 + .../.settings/org.eclipse.jdt.core.prefs | 14 +++ CS144-007-EXAMPLE/src/module-info.java | 3 + .../courses/cs144/examples/Distance.java | 54 +++++++++ .../courses/cs144/examples/Example.java | 29 +++++ .../uwstout/courses/cs144/examples/Stop.java | 106 ++++++++++++++++++ LAB-2/.classpath | 10 ++ LAB-2/.gitignore | 1 + LAB-2/.project | 17 +++ .../org.eclipse.core.resources.prefs | 2 + LAB-2/.settings/org.eclipse.jdt.core.prefs | 14 +++ LAB-2/Lab2.zip | Bin 0 -> 1950 bytes LAB-2/src/module-info.java | 3 + .../cs144/labs/lab2/MessageOutput.java | 27 +++++ .../cs144/labs/lab2/RectangleValues.java | 57 ++++++++++ .../courses/cs144/labs/lab2/Stones.java | 46 ++++++++ 21 files changed, 418 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 CS144-007-EXAMPLE/.classpath create mode 100644 CS144-007-EXAMPLE/.gitignore create mode 100644 CS144-007-EXAMPLE/.project create mode 100644 CS144-007-EXAMPLE/.settings/org.eclipse.core.resources.prefs create mode 100644 CS144-007-EXAMPLE/.settings/org.eclipse.jdt.core.prefs create mode 100644 CS144-007-EXAMPLE/src/module-info.java create mode 100644 CS144-007-EXAMPLE/src/uwstout/courses/cs144/examples/Distance.java create mode 100644 CS144-007-EXAMPLE/src/uwstout/courses/cs144/examples/Example.java create mode 100644 CS144-007-EXAMPLE/src/uwstout/courses/cs144/examples/Stop.java create mode 100644 LAB-2/.classpath create mode 100644 LAB-2/.gitignore create mode 100644 LAB-2/.project create mode 100644 LAB-2/.settings/org.eclipse.core.resources.prefs create mode 100644 LAB-2/.settings/org.eclipse.jdt.core.prefs create mode 100644 LAB-2/Lab2.zip create mode 100644 LAB-2/src/module-info.java create mode 100644 LAB-2/src/uwstout/courses/cs144/labs/lab2/MessageOutput.java create mode 100644 LAB-2/src/uwstout/courses/cs144/labs/lab2/RectangleValues.java create mode 100644 LAB-2/src/uwstout/courses/cs144/labs/lab2/Stones.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e10e727 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.metadata/ diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /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/CS144-007-EXAMPLE/.classpath b/CS144-007-EXAMPLE/.classpath new file mode 100644 index 0000000..a253136 --- /dev/null +++ b/CS144-007-EXAMPLE/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/CS144-007-EXAMPLE/.gitignore b/CS144-007-EXAMPLE/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/CS144-007-EXAMPLE/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/CS144-007-EXAMPLE/.project b/CS144-007-EXAMPLE/.project new file mode 100644 index 0000000..d9c401d --- /dev/null +++ b/CS144-007-EXAMPLE/.project @@ -0,0 +1,17 @@ + + + CS144-007-EXAMPLE + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/CS144-007-EXAMPLE/.settings/org.eclipse.core.resources.prefs b/CS144-007-EXAMPLE/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/CS144-007-EXAMPLE/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/CS144-007-EXAMPLE/.settings/org.eclipse.jdt.core.prefs b/CS144-007-EXAMPLE/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..8c9943d --- /dev/null +++ b/CS144-007-EXAMPLE/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,14 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=17 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=17 diff --git a/CS144-007-EXAMPLE/src/module-info.java b/CS144-007-EXAMPLE/src/module-info.java new file mode 100644 index 0000000..9214388 --- /dev/null +++ b/CS144-007-EXAMPLE/src/module-info.java @@ -0,0 +1,3 @@ +module uwstout.courses.cs144 { + +} \ No newline at end of file diff --git a/CS144-007-EXAMPLE/src/uwstout/courses/cs144/examples/Distance.java b/CS144-007-EXAMPLE/src/uwstout/courses/cs144/examples/Distance.java new file mode 100644 index 0000000..65550a3 --- /dev/null +++ b/CS144-007-EXAMPLE/src/uwstout/courses/cs144/examples/Distance.java @@ -0,0 +1,54 @@ +package uwstout.courses.cs144.examples; + +import java.util.Scanner; + +/** + * Reads two delivery points from the user, and outputs the distance between the + * origin, and the two in city blocks. + * + * Reads in two delivery points (X Y) from the user on, and calculates the + * distance between (0,0), the first point, and the last point in city blocks. + * This calculated value is then output to the console. + * + * @author Brett Bender + * @version 2022.09.15 + * + */ +public class Distance { + + private final static Stop ORIGIN_STOP = new Stop(0, 0); + + /** + * Calculates the city block distance between points. + * + * Reads in two delivery points from System.in, entered in an X Y pair. These + * points are then used to calculate the distance (in city blocks) between + * (0,0), the first point, and the last point. This calculated value is then + * output to the console. + * + * @param args The arguments passed from the command line - not used + */ + public static void main(String[] args) { + Scanner scnr = new Scanner(System.in); + + // Read in route name + System.out.print("Enter route name: "); + String routeName = scnr.nextLine(); + + Stop stop1 = Stop.readStop(scnr, "Enter first delivery point X Y coordinates: "); + + Stop stop2 = Stop.readStop(scnr, "Enter second delivery point X Y coordinates: "); + + System.out.printf("%s to %s to %s\n", ORIGIN_STOP, stop1, stop2); + + // Calculate + /// Starting at 0,0 and going to the two stops in sequence + int distanceTraveled = ORIGIN_STOP.distanceTo(stop1) + stop1.distanceTo(stop2); + + // Output + System.out.printf("Total distance travelled (in city blocks) for route %s: %d\n", routeName, distanceTraveled); + + scnr.close(); + } + +} \ No newline at end of file diff --git a/CS144-007-EXAMPLE/src/uwstout/courses/cs144/examples/Example.java b/CS144-007-EXAMPLE/src/uwstout/courses/cs144/examples/Example.java new file mode 100644 index 0000000..b3c14ad --- /dev/null +++ b/CS144-007-EXAMPLE/src/uwstout/courses/cs144/examples/Example.java @@ -0,0 +1,29 @@ +// Package Declaration -- says where the file should be +package uwstout.courses.cs144.examples; + +// class { } +/** + * This is the primary entry point into our program + * + * @author Brett Bender + * @version 2022.9.15 + * + */ +public class Example { + // add code here + + /** + * Provides the primary entry point into the program + * + * @param args Command line arguments + */ + public static void main(String[] args) { + System.out.println("Hello, World!"); + + // The answer is 42. + System.out.printf("The answer is %d.\n", 42); + + System.out.println("Name\tAge\nBilly\t15"); + } + +} diff --git a/CS144-007-EXAMPLE/src/uwstout/courses/cs144/examples/Stop.java b/CS144-007-EXAMPLE/src/uwstout/courses/cs144/examples/Stop.java new file mode 100644 index 0000000..e719f5f --- /dev/null +++ b/CS144-007-EXAMPLE/src/uwstout/courses/cs144/examples/Stop.java @@ -0,0 +1,106 @@ +package uwstout.courses.cs144.examples; + +import java.util.Scanner; + +/** + * Stop represents a stop on a route. + * + * @author Brett Bender + * @version 2022.09.15 + */ +public class Stop { + + private int x; + private int y; + + /** + * A constructor for Stop that takes in an X and Y coordinate + * + * @param x The X coordinate of this point + * @param y The Y coordinate of this point + */ + public Stop(int x, int y) { + this.x = x; + this.y = y; + } + + /** + * Prints a prompt, reads in two integers, and returns a Stop. + * + * @param scan A scanner for input + * @param prompt The prompt to print to the user + * + * @return The stop given by the user + */ + public static Stop readStop(Scanner scan, String prompt) { + int x, y; + System.out.print(prompt); + x = scan.nextInt(); + y = scan.nextInt(); + + return new Stop(x, y); + } + + /** + * Set the X coordinate of this stop + * + * @param x The new X coordinate + */ + public void setX(int x) { + this.x = x; + } + + /** + * Get the X coordinate of this stop + * + * @return The X coordinate of this stop + */ + public int getX() { + return x; + } + + /** + * Set the Y coordinate of this stop + * + * @param y The new Y coordinate + */ + public void setY(int y) { + this.y = y; + } + + /** + * Get the Y coordinate of this stop + * + * @return The Y coordinate of this point + */ + public int getY() { + return y; + } + + /** + * Set the X and Y coordinate of this stop + * + * @param x The new X coordinate + * @param y The new Y coordinate + */ + public void setXY(int x, int y) { + this.x = x; + this.y = y; + } + + @Override + public String toString() { + return "(" + x + ", " + y + ")"; + } + + /** + * Calculate the distance between two stops in city blocks + * + * @param otherStop The stop we are attempting to measure the distance to + * @return The distance (in city blocks) between this object and otherPoint + */ + public int distanceTo(Stop otherStop) { + /// No Diagonals, city blocks + return Math.abs(otherStop.getX() - this.x) + Math.abs(otherStop.getY() - this.y); + } +} \ No newline at end of file diff --git a/LAB-2/.classpath b/LAB-2/.classpath new file mode 100644 index 0000000..57bca72 --- /dev/null +++ b/LAB-2/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/LAB-2/.gitignore b/LAB-2/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/LAB-2/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/LAB-2/.project b/LAB-2/.project new file mode 100644 index 0000000..91ba517 --- /dev/null +++ b/LAB-2/.project @@ -0,0 +1,17 @@ + + + LAB-2 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/LAB-2/.settings/org.eclipse.core.resources.prefs b/LAB-2/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/LAB-2/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/LAB-2/.settings/org.eclipse.jdt.core.prefs b/LAB-2/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..8c9943d --- /dev/null +++ b/LAB-2/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,14 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=17 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=17 diff --git a/LAB-2/Lab2.zip b/LAB-2/Lab2.zip new file mode 100644 index 0000000000000000000000000000000000000000..3a7bd0d227efadd71e99ec143fff9938090e2dc2 GIT binary patch literal 1950 zcmZwIc{Cg7769-BA(m)ri=~39wV|dmN-U+upeZtl3avdNO7KXkHKL8RT2zgqmP$)4 zEvnQ`1*2junWAdnHB)OW&rx|g^Uj-|^ZI>%+;hM0-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% zu}#fr)v#NRlO(r)buJJ+ ztr-vfX{=U3oa^w*Q9rj%Tz>*)zsFhvA^>Hm`NZ~ArMJ}VScdn ze5O*=H?l?*^HxhyT;>ROw|u?{zW%Ph?N2x23oqL_ii+7%FgIaBf8{~jpg?7`)~iK$ z9Z$0blyJ&%Bw!}31#s4$NMdUmS+;bz(t7@fESIdsdKWqCtl?l z4Zm7zt9_VpfgXg|TNxid;K87QJQ9CRsPC_{BQ^jaK=ErhI{&}izODb>-1}PfcRlP# j;`gTDw;jHx_MZ;fM~=TSj6s9=zkc!_-NvKX_gD5Gi&k2$ literal 0 HcmV?d00001 diff --git a/LAB-2/src/module-info.java b/LAB-2/src/module-info.java new file mode 100644 index 0000000..9214388 --- /dev/null +++ b/LAB-2/src/module-info.java @@ -0,0 +1,3 @@ +module uwstout.courses.cs144 { + +} \ No newline at end of file diff --git a/LAB-2/src/uwstout/courses/cs144/labs/lab2/MessageOutput.java b/LAB-2/src/uwstout/courses/cs144/labs/lab2/MessageOutput.java new file mode 100644 index 0000000..ac71e5d --- /dev/null +++ b/LAB-2/src/uwstout/courses/cs144/labs/lab2/MessageOutput.java @@ -0,0 +1,27 @@ +package uwstout.courses.cs144.labs.lab2; + +/** + * This outputs a message that tests your ability to escape strings. + * + * @author Brett Bender + * @version 2022.09.20 + * + */ +public class MessageOutput { + + /** + * This outputs a message that tests your ability to escape strings. + * + * @param args The command line arguments (not used) + */ + public static void main(String[] args) { + System.out.println("\tIn Windows, putting the path to a file into the code is a little"); + System.out.println("difficult as each \"\\\" in the path must be escaped. So, if your"); + System.out.println("file is located at C:\\temp\\data.csv, then you would need to"); + System.out.println("escape it so that it looks like C:\\\\temp\\\\data.csv. It is also"); + System.out.println("good practice to put \"'s around the path. This avoids problems"); + System.out.println("with spaces in the file name or the path. The \"'s would have"); + System.out.println("to be escaped as well."); + } + +} diff --git a/LAB-2/src/uwstout/courses/cs144/labs/lab2/RectangleValues.java b/LAB-2/src/uwstout/courses/cs144/labs/lab2/RectangleValues.java new file mode 100644 index 0000000..dc40ede --- /dev/null +++ b/LAB-2/src/uwstout/courses/cs144/labs/lab2/RectangleValues.java @@ -0,0 +1,57 @@ +package uwstout.courses.cs144.labs.lab2; + +import java.util.Scanner; + +/** + * This computes the area and perimeter of a rectangle given the rectangle's + * length and width. + * + * @author turners + * @version 1.0 + * + */ +public class RectangleValues { + + /** + * This computes the area and perimeter of a rectangle given the rectangle's + * length and width. + * + * + * @param args Command line arguments (not used) + * + * + * Input: (length: 10, width: 10) Expected: (perim: 40, area: 100) + * + * Input: (length: 0, width: 9) Expected: (perim: 18, area: 0) + * + * Input: (length: -2, width: 4) Expected: (perim: 4, area: -8) + * + * + * + */ + public static void main(String[] args) { + double length; + double width; + double perimeter; + double area; + + // Create an object to read in data from the keyboard + Scanner scan = new Scanner(System.in); + // prompt for and read in length and width + System.out.println("Enter the length of the rectangle: "); + length = scan.nextDouble(); + + System.out.println("Enter the width of the rectangle: "); + width = scan.nextDouble(); + + // compute perimeter and area + perimeter = 2 * (length + width); + area = length * width; + + // output results + System.out.println("For a " + length + " x " + width + " rectangle, the perimeter is " + perimeter + + " and the area is " + area + "."); + + scan.close(); + } +} diff --git a/LAB-2/src/uwstout/courses/cs144/labs/lab2/Stones.java b/LAB-2/src/uwstout/courses/cs144/labs/lab2/Stones.java new file mode 100644 index 0000000..5891fd7 --- /dev/null +++ b/LAB-2/src/uwstout/courses/cs144/labs/lab2/Stones.java @@ -0,0 +1,46 @@ +package uwstout.courses.cs144.labs.lab2; + +import java.util.Scanner; + +/** + * Reads in a value (in stones) and converts it to ounces. + * + * @author Brett Bender + * @version 2022.09.20 + */ +public class Stones { + + private static final int STONE_POUNDS_CF = 14; + private static final int POUNDS_OUNCES_CF = 16; + private static final int STONE_OUNCES_CF = STONE_POUNDS_CF * POUNDS_OUNCES_CF; + + /** + * Reads in a value (in stones) and converts it to ounces. + * + * @param args Command line arguments (not used) + * + * + * Input: 2 stones Expected: 448 ounces + * + * Input: -1 stones Expected: -224 ounces + * + * Input: 0 stones Expected: 0 ounces + */ + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + + System.out.println("How heavy is the object in stones?"); + + // Read in the weight in stones + int stonesIn = scan.nextInt(); + + // Calculate the weight in ounces + int ouncesOut = stonesIn * STONE_OUNCES_CF; + + // Output it to the user + System.out.printf("%d stones in ounces is %d ounces.\n", stonesIn, ouncesOut); + + scan.close(); + } + +}