idk ive done too much
This commit is contained in:
@@ -7,18 +7,27 @@ public class CheckIfLetter {
|
||||
public static void main(String[] args) {
|
||||
Scanner scan = new Scanner(System.in);
|
||||
|
||||
String input = scan.nextLine();
|
||||
// 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);
|
||||
// }
|
||||
|
||||
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);
|
||||
double avg = 0;
|
||||
double totalNum = 0;
|
||||
while (scan.hasNextDouble()) {
|
||||
avg += scan.nextDouble();
|
||||
totalNum++;
|
||||
}
|
||||
|
||||
avg = avg / totalNum;
|
||||
|
||||
scan.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package uwstout.courses.cs144.examples;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Loops {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
System.out.println(createSimpleHistrogram(sc));
|
||||
sc.close();
|
||||
}
|
||||
|
||||
public static String createSimpleHistrogram(Scanner vals) {
|
||||
String histoString = "";
|
||||
|
||||
while (vals.hasNextInt()) {
|
||||
int n = vals.nextInt();
|
||||
for (int i = 0; i <= n; i++) {
|
||||
histoString += "*";
|
||||
}
|
||||
histoString += "\n";
|
||||
}
|
||||
|
||||
return histoString;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,8 +20,8 @@ public class Stop {
|
||||
* @param y The Y coordinate of this point
|
||||
*/
|
||||
public Stop(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.x = (-100 <= x && x <= 100) ? x : 0;
|
||||
this.y = (-100 <= y && y <= 100) ? y : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,10 +101,12 @@ public class Stop {
|
||||
*/
|
||||
public int getBlockDistance(Stop otherStop) {
|
||||
/// No Diagonals, city blocks
|
||||
return Math.abs(otherStop.getX() - this.x) + Math.abs(otherStop.getY() - this.y);
|
||||
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));
|
||||
return Math.sqrt(Math.pow(otherStop.getX() - this.x, 2)
|
||||
+ Math.pow(otherStop.getY() - this.y, 2));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package uwstout.courses.cs144.examples.characters;
|
||||
|
||||
public class Character {
|
||||
|
||||
private String name;
|
||||
private int level;
|
||||
private Item left;
|
||||
private Item right;
|
||||
|
||||
public Character(String nName, int nLevel) {
|
||||
name = nName;
|
||||
level = nLevel;
|
||||
left = null;
|
||||
right = null;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public Item getLeftHand() {
|
||||
return left;
|
||||
}
|
||||
|
||||
public Item getRightHand() {
|
||||
return right;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setLevel(int level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public void setLeftHand(Item left) {
|
||||
this.left = left;
|
||||
}
|
||||
|
||||
public void setRightHand(Item right) {
|
||||
this.right = right;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package uwstout.courses.cs144.examples.characters;
|
||||
|
||||
public class CharacterList {
|
||||
|
||||
private Character[] actors;
|
||||
private int count;
|
||||
|
||||
public CharacterList() {
|
||||
actors = new Character[5];
|
||||
count = 0;
|
||||
}
|
||||
|
||||
public int getCharacterCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public Character getCharacter(int pos) {
|
||||
if (pos >= 0 && pos < count) {
|
||||
return actors[pos];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addCharacter(Character person) {
|
||||
if (count == actors.length) {
|
||||
Character[] temp = new Character[actors.length + 5];
|
||||
for (int i = 0; i < actors.length; i++) {
|
||||
temp[i] = actors[i];
|
||||
}
|
||||
actors = temp;
|
||||
}
|
||||
actors[count++] = person;
|
||||
}
|
||||
|
||||
public void removeCharacter(String name) {
|
||||
int charPos = findCharacter(name);
|
||||
if (charPos >= 0) {
|
||||
for (int i = charPos; i < count - 1; i++) {
|
||||
actors[i] = actors[i + 1];
|
||||
}
|
||||
count--;
|
||||
}
|
||||
}
|
||||
|
||||
public int findCharacter(String name) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (actors[i].getName().equals(name)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package uwstout.courses.cs144.examples.characters;
|
||||
|
||||
public class Item {
|
||||
|
||||
private int type;
|
||||
private String name;
|
||||
|
||||
public Item(int nType, String nName) {
|
||||
type = nType;
|
||||
name = nName;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user