initial commit
This commit is contained in:
6
CS144-007-EXAMPLE/.classpath
Normal file
6
CS144-007-EXAMPLE/.classpath
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
1
CS144-007-EXAMPLE/.gitignore
vendored
Normal file
1
CS144-007-EXAMPLE/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/bin/
|
||||
17
CS144-007-EXAMPLE/.project
Normal file
17
CS144-007-EXAMPLE/.project
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>CS144-007-EXAMPLE</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>
|
||||
@@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
||||
14
CS144-007-EXAMPLE/.settings/org.eclipse.jdt.core.prefs
Normal file
14
CS144-007-EXAMPLE/.settings/org.eclipse.jdt.core.prefs
Normal file
@@ -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
|
||||
3
CS144-007-EXAMPLE/src/module-info.java
Normal file
3
CS144-007-EXAMPLE/src/module-info.java
Normal file
@@ -0,0 +1,3 @@
|
||||
module uwstout.courses.cs144 {
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// Package Declaration -- says where the file should be
|
||||
package uwstout.courses.cs144.examples;
|
||||
|
||||
// <visibility> class <name> { }
|
||||
/**
|
||||
* 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");
|
||||
}
|
||||
|
||||
}
|
||||
106
CS144-007-EXAMPLE/src/uwstout/courses/cs144/examples/Stop.java
Normal file
106
CS144-007-EXAMPLE/src/uwstout/courses/cs144/examples/Stop.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user