I don't know what changes I've made lol

This commit is contained in:
2022-11-01 14:30:06 -05:00
parent 8d1ef61699
commit 9a1bc9cfb5
26 changed files with 1013 additions and 3 deletions

View File

@@ -0,0 +1,25 @@
package uwstout.courses.cs144.examples;
import java.util.Scanner;
public class CheckIfLetter {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String input = scan.nextLine();
char firstChar = input.charAt(0);
if ((firstChar >= 'a' && firstChar <= 'z') || (firstChar >= 'A' && firstChar <= 'Z')) {
System.out.printf("%s is a letter!", firstChar);
} else if (firstChar >= '0' && firstChar <= '9') {
System.out.printf("%s is a number!", firstChar);
} else {
System.out.printf("%s is of unknown type!", firstChar);
}
scan.close();
}
}

View File

@@ -1,5 +1,6 @@
package uwstout.courses.cs144.examples;
import java.text.DecimalFormat;
import java.util.Scanner;
/**
@@ -30,6 +31,7 @@ public class Distance {
*/
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("#,##0.00");
// Read in route name
System.out.print("Enter route name: ");
@@ -43,10 +45,14 @@ public class Distance {
// Calculate
/// Starting at 0,0 and going to the two stops in sequence
int distanceTraveled = ORIGIN_STOP.distanceTo(stop1) + stop1.distanceTo(stop2);
int blockDistanceTraveled = ORIGIN_STOP.getBlockDistance(stop1) + stop1.getBlockDistance(stop2);
double directDistanceTraveled = ORIGIN_STOP.getDistance(stop1) + stop1.getDistance(stop2);
// Output
System.out.printf("Total distance travelled (in city blocks) for route %s: %d\n", routeName, distanceTraveled);
System.out.println("Stop 1: " + stop1);
System.out.println("Stop 2: " + stop2);
System.out.printf("Total distance travelled (in city blocks) for route %s: %d\n", routeName, blockDistanceTraveled);
System.out.printf("The direct distance is: %s\n", df.format(directDistanceTraveled));
scnr.close();
}

View File

@@ -0,0 +1,23 @@
package uwstout.courses.cs144.examples;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Scanner;
public class Formatter {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("Enter a value: ");
double val = scan.nextDouble();
System.out.println(val);
System.out.println(NumberFormat.getCurrencyInstance().format(val));
System.out.println(NumberFormat.getPercentInstance().format(val));
System.out.println(new DecimalFormat("#,##0.000,0").format(val));
scan.close();
}
}

View File

@@ -0,0 +1,33 @@
package uwstout.courses.cs144.examples;
import java.util.Scanner;
public class SphereVolume {
/**
* Calculates the volume of a sphere given the radius.
*
* TESTS:
*
* TEST1IN: 1; TEST1OUT: 4.189
*
* TEST2IN: -2, TEST2OUT: -33.510
*
* TEST3IN: 0, TEST3OUT: 0.000
*
* TEST4IN: 0.5, TEST4OUT: 0.524
*
* @param args Command line arguments - not used
*/
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("Enter the radius of the sphere: ");
double radius = Math.abs(scan.nextDouble());
double volume = (4.0 / 3.0) * Math.pow(radius, 3) * Math.PI;
System.out.printf("A sphere with radius %.2f has a volume of %.2f", radius, volume);
scan.close();
}
}

View File

@@ -99,8 +99,12 @@ public class Stop {
* @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) {
public int getBlockDistance(Stop otherStop) {
/// No Diagonals, city blocks
return Math.abs(otherStop.getX() - this.x) + Math.abs(otherStop.getY() - this.y);
}
public double getDistance(Stop otherStop) {
return Math.sqrt(Math.pow(otherStop.getX() - this.x, 2) + Math.pow(otherStop.getY() - this.y, 2));
}
}

View File

@@ -0,0 +1,22 @@
package uwstout.courses.cs144.examples;
import java.util.Scanner;
public class StringSplit {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String inputString = scan.nextLine().toLowerCase().strip();
int splitAt = inputString.length() / 2;
String stringHalf1 = inputString.substring(0, splitAt);
String stringHalf2 = inputString.substring(splitAt, inputString.length());
System.out.println(stringHalf1);
System.out.println(stringHalf2);
scan.close();
}
}