general repo maint & lab 2

This commit is contained in:
2022-09-27 16:14:09 -05:00
parent d58eb989d5
commit 9c767728a4
18 changed files with 697 additions and 41 deletions

10
LAB-3/.classpath Normal file
View File

@@ -0,0 +1,10 @@
<?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">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

1
LAB-3/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/bin/

17
LAB-3/.project Normal file
View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>LAB-3</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,3 @@
module uwstout.courses.cs144 {
}

View File

@@ -0,0 +1,58 @@
package uwstout.courses.cs144.labs.lab3;
import java.util.Scanner;
/**
* This program converts a rectangular coordinate to a polar coordinate
*
* @author Brett Bender
* @version 2022.09.27
*/
public class ConvertCoordinate {
/**
* This program converts a rectangular coordinate to a polar coordinate
*
*
* TESTS
*
* INPUT1: x = 5, y = 5
*
* OUTPUT1: r = 7.071, theta = 45
*
*
* INPUT2: x = -2, y = -5
*
* OUTPUT2: r = 5.385, theta = 248.2
*
*
* INPUT3: x = 0, y = 0
*
* OUTPUT3: r = 0, theta = 0
*
*
* @param args The command line arguments (not used)
*/
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
// Input
/// X Value
System.out.print("Enter the X coordinate: ");
int x = scan.nextInt();
/// Y Value
System.out.print("Enter the Y coordinate: ");
int y = scan.nextInt();
// Create the coordinate object
Coordinate coord = new Coordinate(x, y);
// Output
/// Print (x, y) -> (r, theta\u00B0)
System.out.printf("(%d, %d) -> (%f, %f\u00B0)", coord.getX(), coord.getY(), coord.getR(), coord.getTheta());
scan.close();
}
}

View File

@@ -0,0 +1,72 @@
package uwstout.courses.cs144.labs.lab3;
/**
* Represents a coordinate in geometry. It can be accessed both as a rectangular
* (x, y) coordinate and as a polar (r, theta) coordinate.
*
* @author turners
* @version 2016-09-10
*/
public class Coordinate {
private int x;
private int y;
private static final int PI_DEGREES = 180;
private static final int TWO_PI_DEGREES = 360;
/**
* Creates a Coordinate using a rectangular (x, y) location.
*
* @param nx x part of the coordinate
* @param ny y part of the coordinate
*/
Coordinate(int nx, int ny) {
x = nx;
y = ny;
}
/**
* Gets the x value of a rectangular (x, y) coordinate
*
* @return The x coordinate
*/
public int getX() {
return x;
}
/**
* Gets the y value of a rectangular (x, y) coordinate
*
* @return The y coordinate
*/
public int getY() {
return y;
}
/**
* Gets the r value of a polar (r, theta) coordinate.
*
* @return r value of the coordinate
*/
public double getR() {
return Math.sqrt(x * x + y * y);
}
/**
* Gets the theta value of a polar (r, theta) coordinate.
*
* Theta is returned in degrees and is between 0 and 360 degrees.
*
* @return theta value of the coordinate
*/
public double getTheta() {
double radians = Math.atan2(y, x);
double degrees = radians * PI_DEGREES / Math.PI;
if (degrees < 0) {
degrees += TWO_PI_DEGREES;
}
return degrees;
}
}

View File

@@ -0,0 +1,76 @@
package uwstout.courses.cs144.labs.lab3;
/**
*
* An ingredient in a recipe.
*
* @author Brett Bender
* @version 2022.09.27
*/
public class Ingredient {
private String name;
private String units;
private int amount;
/**
* Creates an ingredient of the given name, unit, and amount
*
* @param iname The name of the ingredient
* @param iunits The unit of measurement for the ingredient
* @param iamount The amount of the ingredient (in given unit)
*/
public Ingredient(String iname, int iamount, String iunits) {
name = iname;
amount = iamount;
units = iunits;
}
/**
* Get the name of the ingredient
*
* @return The name of the ingredient
*/
public String getName() {
return name;
}
/**
* Get the unit of measurement for the ingredient
*
* @return The unit of measurement for the ingredient
*/
public String getUnits() {
return units;
}
/**
* Get the amount of the ingredient (in the unit)
*
* @return The amount of the ingredient (in the unit)
*/
public int getAmount() {
return amount;
}
/**
* Set the name of the ingredient.
*
* @param iname The new name of the ingredient
*/
public void setName(String iname) {
name = iname;
}
/**
* Set the amount of the ingredient.
*
* @param iamount The new amount of the ingredient.
* @param iunits The new unit of measurement for the ingredient.
*/
public void setAmount(int iamount, String iunits) {
amount = iamount;
units = iunits;
}
}

View File

@@ -0,0 +1,72 @@
package uwstout.courses.cs144.labs.lab3;
import java.util.Scanner;
/**
* Gets the ingredients for a 3 ingredient recipe and prints the results.
*
* Gets the ingredients for a 3 ingredient recipe and prints the results. For
* each ingredient, the user needs to specify the name, amount and units.
* Ingredients and units can have spaces in them and the amount is a whole
* number.
*
* @author turners
* @version 2022-09-26
*/
public class Recipe {
/**
* Gets the ingredients for a 3 ingredient recipe and prints the results.
*
* Gets the ingredients for a 3 ingredient recipe and prints the results. For
* each ingredient, the user needs to specify the name, amount and units.
* Ingredients and units can have spaces in them and the amount is a whole
* number.
*
* @param args Command line arguments - not used
*/
public static void main(String[] args) {
Ingredient item1 = null;
Ingredient item2 = null;
Ingredient item3 = null;
String name;
int amount;
String units;
Scanner scan = new Scanner(System.in);
System.out.println("Enter the first Ingredient's name: ");
name = scan.nextLine();
System.out.println("Enter the first Ingredient's amount: ");
amount = scan.nextInt();
System.out.println("Enter the first Ingredient's unit: ");
scan.skip("\\s*"); // skips spaces to get the input ready for the units
units = scan.nextLine();
item1 = new Ingredient(name, amount, units);
System.out.println("Enter the second Ingredient's name: ");
name = scan.nextLine();
System.out.println("Enter the second Ingredient's amount: ");
amount = scan.nextInt();
System.out.println("Enter the second Ingredient's unit: ");
scan.skip("\\s*"); // skips spaces to get the input ready for the units
units = scan.nextLine();
item2 = new Ingredient(name, amount, units);
System.out.println("Enter the third Ingredient's name: ");
name = scan.nextLine();
System.out.println("Enter the third Ingredient's amount: ");
amount = scan.nextInt();
System.out.println("Enter the third Ingredient's unit: ");
scan.skip("\\s*"); // skips spaces to get the input ready for the units
units = scan.nextLine();
item3 = new Ingredient(name, amount, units);
System.out.println("Ingredient List\n");
System.out.println(item1.getName() + "\t" + item1.getAmount() + "\t" + item1.getUnits());
System.out.println(item2.getName() + "\t" + item2.getAmount() + "\t" + item2.getUnits());
System.out.println(item3.getName() + "\t" + item3.getAmount() + "\t" + item3.getUnits());
scan.close();
}
}