diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e10e727 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.metadata/ diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json new file mode 100644 index 0000000..e47faa6 --- /dev/null +++ b/.vs/VSWorkspaceState.json @@ -0,0 +1,9 @@ +{ + "ExpandedNodes": [ + "", + "\\ClassClass", + "\\ClassClass\\src" + ], + "SelectedNode": "\\ClassClass\\src\\ClassClass.java", + "PreviewInSolutionExplorer": false +} \ No newline at end of file diff --git a/.vs/dell-java/v15/.suo b/.vs/dell-java/v15/.suo new file mode 100644 index 0000000..f177f05 Binary files /dev/null and b/.vs/dell-java/v15/.suo differ diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite new file mode 100644 index 0000000..4c18f1d Binary files /dev/null and b/.vs/slnx.sqlite differ diff --git a/ArrayVList/.classpath b/ArrayVList/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/ArrayVList/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/ArrayVList/.gitignore b/ArrayVList/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/ArrayVList/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/ArrayVList/.project b/ArrayVList/.project new file mode 100644 index 0000000..ec546ed --- /dev/null +++ b/ArrayVList/.project @@ -0,0 +1,17 @@ + + + ArrayVList + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/ArrayVList/.settings/org.eclipse.jdt.core.prefs b/ArrayVList/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/ArrayVList/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +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.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/ArrayVList/src/ArrayVList/ArrayVList.java b/ArrayVList/src/ArrayVList/ArrayVList.java new file mode 100644 index 0000000..0720693 --- /dev/null +++ b/ArrayVList/src/ArrayVList/ArrayVList.java @@ -0,0 +1,130 @@ +package ArrayVList; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +public class ArrayVList { + public static void main(String[] args) { + String StringOfColors[] = {"red","blue","yellow"}; + + for (int i = 0; i < StringOfColors.length; i++) + System.out.println(StringOfColors[i]); + + //just showing a two dimensional array + String[][] twoDArray = new String[3][3]; + + /* very specific because I say ArrayList rather than just List. a "special type of lightbulb"*/ + ArrayList listOfColors = new ArrayList(); + + /*I want a just a light bulb, any kind*/ + List listOfColors2 = new ArrayList(); + + listOfColors.add("red"); + listOfColors.add("blue"); + listOfColors.add("yellow"); + System.out.println("Hey Matt, it's future matt. Just checking in. Stay safe. Cheers."); + System.out.println("Do you have anything to say to him?"); + Scanner reader = new Scanner(System.in); + String yourPick = reader.nextLine(); + reader.close(); + System.out.println('"'+ yourPick + '"'); + System.out.println("me too, thanks"); + + //just examples of getting size and getting specific value of array location + int s = listOfColors2.size(); + String blue = listOfColors.get(1); + + MyList colors = new MyList(); + + colors.add("Yellow"); + colors.add("Blue"); + colors.add("Red"); + colors.add("Green"); + colors.add("Black"); + + for (int i = 0; i < colors.size(); i++) { + System.out.println(i + " " + colors.get(i)); + } + + String red = colors.get(2); + int s2 = colors.size(); + + colors.remove(4); + + for (int i = 0; i < StringOfColors.length; i++) { + System.out.println(i + " " + colors.get(i)); + } + + } + + public static class MyList { + + String[] store = new String[10]; + int size = 0; + + /** + * Adds a string to the list + * @param s the string to add to the list + */ + public void add(String s) { + //figure out the add logic + + if(size == store.length) { + String[] tmp = new String[size+10]; + + for(int i = 0; i < store.length; i++) { + tmp[i] = store[i]; + } + + store = tmp; + + } + store[size] = s; + + size += 1; + + } + + /** + * Returns the current size of the list + * @return the current size of the list + */ + public int size() { + return size; + } + + /** + * Returns the string at the position passed in + * @param i the position passed in + * @return the string at the position + */ + public String get(int i) { + return store[i]; + } + + /** + * Removes the element from the list at the given position + * @param i the position to remove from the list + */ + public void remove(int i) { + //figure out the remove element logic + if(i > size) { + return; + } else { + String[] tmp = new String[size]; + for(int j = 0; j < size-1; i++) { + if(j != i) { + tmp[j] = store[i]; + } + } + + store = tmp; + store[size] = null; + size -= 1; + } + + } + } + + +} diff --git a/Calculator/.classpath b/Calculator/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/Calculator/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Calculator/.gitignore b/Calculator/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/Calculator/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/Calculator/.project b/Calculator/.project new file mode 100644 index 0000000..afb56be --- /dev/null +++ b/Calculator/.project @@ -0,0 +1,17 @@ + + + Calculator + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Calculator/.settings/org.eclipse.jdt.core.prefs b/Calculator/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/Calculator/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +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.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/Calculator/bin/Calc/Calculator.class b/Calculator/bin/Calc/Calculator.class new file mode 100644 index 0000000..c1aed98 Binary files /dev/null and b/Calculator/bin/Calc/Calculator.class differ diff --git a/Calculator/src/Calc/Calculator.java b/Calculator/src/Calc/Calculator.java new file mode 100644 index 0000000..43b97d5 --- /dev/null +++ b/Calculator/src/Calc/Calculator.java @@ -0,0 +1,48 @@ +package Calc; +import java.util.Scanner; + +public class Calculator { + public static void main(String[] args) { + System.out.println("Please enter first number."); + + Scanner reader = new Scanner(System.in); + int firstNum = Integer.parseInt(reader.nextLine()); + + System.out.println("Please enter second number."); + + int secondNum = Integer.parseInt(reader.nextLine()); + reader.close(); + + int add = addition(firstNum, secondNum); + int sub = subtract(firstNum, secondNum); + int mult = multiply(firstNum, secondNum); + int quotient = quotient(firstNum, secondNum); + + System.out.println("Add: " + add); + System.out.println("Subtract: " + sub); + System.out.println("Multiply: " + mult); + System.out.println("Divide: " + quotient); + + } + + public static int addition(int firstNum, int secondNum) { + int result = firstNum + secondNum; + return result; + } + + public static int subtract(int firstNum, int secondNum) { + int result = firstNum - secondNum; + return result; + } + + public static int multiply(int firstNum, int secondNum) { + int result = firstNum * secondNum; + return result; + } + + public static int quotient(int firstNum, int secondNum) { + int result = firstNum / secondNum; + return result; + } + +} diff --git a/CarLots/.classpath b/CarLots/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/CarLots/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/CarLots/.gitignore b/CarLots/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/CarLots/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/CarLots/.project b/CarLots/.project new file mode 100644 index 0000000..0c19a3d --- /dev/null +++ b/CarLots/.project @@ -0,0 +1,17 @@ + + + CarLots + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/CarLots/.settings/org.eclipse.jdt.core.prefs b/CarLots/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/CarLots/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +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.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/CarLots/src/Car.java b/CarLots/src/Car.java new file mode 100644 index 0000000..c55d01f --- /dev/null +++ b/CarLots/src/Car.java @@ -0,0 +1,42 @@ +/* + * type (coupe, hatchback, or sedan) +number of doors + */ +public class Car extends Vehicle { + + private CarType type; + private int numDoors; + + /* + * car constructor that gets 4 attributes from parent super class and has to assign two attributes of its own + */ + public Car(String licenseNum, String make, String model, double price, CarType type, int numDoors) { + super(licenseNum, make, model, price); + this.type = type; + this.numDoors = numDoors; + } + + @Override + public String basicDetails() { + return "Car is a " + getType() + " and has " + getNumDoors() + " doors."; + } + + public CarType getType() { + return type; + } + + public void setType(CarType type) { + this.type = type; + } + + public int getNumDoors() { + return numDoors; + } + + public void setNumDoors(int numDoors) { + this.numDoors = numDoors; + } + + + +} diff --git a/CarLots/src/CarLot.java b/CarLots/src/CarLot.java new file mode 100644 index 0000000..25b0387 --- /dev/null +++ b/CarLots/src/CarLot.java @@ -0,0 +1,64 @@ +import java.util.List; + +/* + * CarLot should have the following fields: +name +a list of vehicles +CarLot should have methods to do the following actions: +add a vehicle to the lot +print the inventory of the car lot, including number of vehicles and details about each vehicle + */ +public class CarLot { + private String name; + private List vehicleList; + + /* + * creating constructors + */ + public CarLot() { + + } + + public CarLot(String name, List vehicleList) { + this.setName(name); + this.vehicleList = vehicleList; + } + + /* + * print lot method that prints lot details then uses print vehicle method for each vehicle in lot + */ + public void printLot() { + System.out.println("Lot: " + getName() + " has " + vehicleList.size() + " cars in it."); + for(Vehicle v: vehicleList) { + System.out.print(v.printVehicle()); + } + System.out.println(""); + } + + /** + * method to add vehicle object to vehicle list array + * @param vehicleAdding object being added + */ + public void addVehicle(Vehicle vehicleAdding) { + vehicleList.add(vehicleAdding); + } + + /* + * getters and setters + */ + public List getVehicleList() { + return vehicleList; + } + + public void setVehicleList(List vehicleList) { + this.vehicleList = vehicleList; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/CarLots/src/CarType.java b/CarLots/src/CarType.java new file mode 100644 index 0000000..c02434f --- /dev/null +++ b/CarLots/src/CarType.java @@ -0,0 +1,4 @@ + +public enum CarType { + COUPE, HATCHBACK, SEDAN +} diff --git a/CarLots/src/Program.java b/CarLots/src/Program.java new file mode 100644 index 0000000..cadebf5 --- /dev/null +++ b/CarLots/src/Program.java @@ -0,0 +1,52 @@ +import java.util.ArrayList; +import java.util.List; + +/* + * Create a CarLotProgram class that will contain your main method and act as a "driver" for your program. + +For this assignment you do not have to build an interactive program. + +In your main method: +You should instantiate 2 different car lots, and add various vehicles to the car lots. +Print out the inventory for each of the car lots, showing the details for each vehicle. +When printing out the details, print the appropriate info for a car, or a truck accordingly. + */ +public class Program { + + public static void main(String[] args) { + + /** + * instantiating car lots + */ + List mattsCarsForSale = new ArrayList(); + CarLot lot1 = new CarLot("Matt's used cars for less", mattsCarsForSale); + List ravensCarsForSale = new ArrayList(); + CarLot lot2 = new CarLot("Raven's Cars Depot", ravensCarsForSale); + + /** + * creating vehicle objects of various sub types + */ + Vehicle subaru = new Car("FJ3DK03","Subaru","Crosstrek",22000,CarType.HATCHBACK,4); + Vehicle jeep = new Car("DKE3L0D","Jeep","Patriot",17000,CarType.HATCHBACK,4); + Vehicle honda = new Car("F23DB03","Honda","Civic SI",26000,CarType.COUPE,2); + Vehicle f150 = new Truck("FJ3DK03","Ford","F-150",22000,6); + Vehicle tacoma = new Truck("FJ3DK03","Toyota","Tacoma",22000,4); + + /** + * adding vehicle objects to lots + * adds the vehicle object to list array + */ + lot2.addVehicle(jeep); + lot2.addVehicle(subaru); + lot1.addVehicle(honda); + lot1.addVehicle(f150); + lot2.addVehicle(tacoma); + + lot1.printLot(); + lot2.printLot(); + + + + } + +} diff --git a/CarLots/src/Truck.java b/CarLots/src/Truck.java new file mode 100644 index 0000000..4569924 --- /dev/null +++ b/CarLots/src/Truck.java @@ -0,0 +1,24 @@ +/* + * bed size + */ +public class Truck extends Vehicle { + private int bedSize; + + public Truck(String licenseNum, String make, String model, double price, int bedSize) { + super(licenseNum, make, model, price); + this.setBedSize(bedSize); + } + + public int getBedSize() { + return bedSize; + } + + public void setBedSize(int bedSize) { + this.bedSize = bedSize; + } + + @Override + public String basicDetails() { + return "Truck with bed size of " + Integer.toString(getBedSize()); + } +} diff --git a/CarLots/src/Vehicle.java b/CarLots/src/Vehicle.java new file mode 100644 index 0000000..8528616 --- /dev/null +++ b/CarLots/src/Vehicle.java @@ -0,0 +1,70 @@ +/* + * Vehicle should have the following fields: +license number +make +model +price +Vehicle should have methods to do the following actions: +print a description of the vehicle, including license number, make, model, and price + */ +public abstract class Vehicle { + private String licenseNum; + private String make; + private String model; + private double price; + + public Vehicle(String licenseNum, String make, String model, double price) { + this.licenseNum = licenseNum; + this.make = make; + this.model = model; + this.price = price; + } + + /** + * abstract method that every subclass will need to have + * will have specifics details for each subclass not specific to vehicle + * @return + */ + public abstract String basicDetails(); + + /** + * print vehicle method that uses the basicdetails abstract that every subclass of vehicle will have + * + * @return basic details plus attributes of every vehicle + */ + public String printVehicle() { + return basicDetails() + "\n" + getLicenseNum() + " " + getMake() + " " + getModel() + " " + getPrice() + "\n" + "\n"; + } + + /** + * getters and setters + * @return + */ + public String getLicenseNum() { + return licenseNum; + } + public void setLicenseNum(String licenseNum) { + this.licenseNum = licenseNum; + } + public String getMake() { + return make; + } + public void setMake(String make) { + this.make = make; + } + public String getModel() { + return model; + } + public void setModel(String model) { + this.model = model; + } + public double getPrice() { + return price; + } + public void setPrice(double price) { + this.price = price; + } + + + +} diff --git a/ClassClass/.classpath b/ClassClass/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/ClassClass/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/ClassClass/.gitignore b/ClassClass/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/ClassClass/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/ClassClass/.project b/ClassClass/.project new file mode 100644 index 0000000..a0e00d1 --- /dev/null +++ b/ClassClass/.project @@ -0,0 +1,17 @@ + + + ClassClass + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/ClassClass/.settings/org.eclipse.jdt.core.prefs b/ClassClass/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/ClassClass/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +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.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/ClassClass/src/ClassClass.java b/ClassClass/src/ClassClass.java new file mode 100644 index 0000000..ee679ef --- /dev/null +++ b/ClassClass/src/ClassClass.java @@ -0,0 +1,32 @@ +public class ClassClass { +//static - only 1 for all objects. property of the class, doesn't belong to instance. cookie example - cookie cutter stays same diameter +//for Integer class the min value is ____ - it always stays that +//class with all static methods only provides functionality - wouldn't need to change it + + public static void main(String[] args) { + + Integer x=2; + Integer y=7; + + //variable. asks one if taller than other + int answer = x.compareTo(y); + + //static. third part guesses height + int another = Integer.compare(x, y); + + Person jack = new Person("Captain","Jack"); + + + StringList l1 = new StringList(); + l1.add("apple"); + l1.add("pear"); + + + for(int i =0; i String, next node -> node + +/** + * implementation of linked list that stores list of strings + * @author Matthew_Hauser + * + */ +public class StringList { + + private Node root; + + private Node end; + + /*** the size of the list*/ + private int size; + + /** + * return the value at the position in the list + * @param index the position of the value to return + * @return the value at the position + */ + public String get(int index) { + Node node = getNode(index); + return node.getNodeValue(); + } + + /** + * add new string to linked list + * @param value the value to add to the list + */ + public void add(String value) { + Node newNode = new Node(value); + + if(root == null) { + root = newNode; + } else { + end.setNext(newNode); + } + + end = newNode; + size++; + } + + private Node getNode(int index) { + if(index < 0 || index > size) { + throw new IllegalArgumentException("Out of bounds of this list"); + } + + if(index == 0) { + return root; + } + + if(index == size -1) { + return end; + } + + Node currentNode = root; + for(int i=1; i size) { + throw new IllegalArgumentException("Out of bounds of this list"); + } + + if(index == 0) { + if(size == 1) { + root = null; + } else { + root = root.getNextNode(); + } + + size--; + return; + + }else if(index == size-1) { + Node newEnd = getNode(index-1); + end = newEnd; + newEnd.clearNext(); + size--; + } else { + Node prev = getNode(index -1); + Node current = prev.getNextNode(); + Node next = current.getNextNode(); + prev.setNext(next); + size--; + + } + } + + /** + * @return size of list + */ + public int size() { + return size; + } + + + +} diff --git a/CollectionsClass/.classpath b/CollectionsClass/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/CollectionsClass/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/CollectionsClass/.gitignore b/CollectionsClass/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/CollectionsClass/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/CollectionsClass/.project b/CollectionsClass/.project new file mode 100644 index 0000000..4c9c142 --- /dev/null +++ b/CollectionsClass/.project @@ -0,0 +1,17 @@ + + + CollectionsClass + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/CollectionsClass/.settings/org.eclipse.jdt.core.prefs b/CollectionsClass/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/CollectionsClass/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +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.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/CollectionsClass/src/Collections.java b/CollectionsClass/src/Collections.java new file mode 100644 index 0000000..c730eea --- /dev/null +++ b/CollectionsClass/src/Collections.java @@ -0,0 +1,55 @@ +import java.util.Collection; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Random; +import java.util.Stack; +import java.util.HashSet; + + +public class Collections { + public static void main(String[] args) { + Collection intCollection = new HashSet<>(); + System.out.println("Hey Matt. Future Matt again. DON'T eat the snacks. Your life depends on it. Cheers."); + Random randNumGen = new Random(); + for (int i=0; i <10000; i++) { + intCollection.add(randNumGen.nextInt(1000)); + } + + Iterator iterator = intCollection.iterator(); + + while(iterator.hasNext()) { + int number = iterator.next(); + //System.out.println(number); + } + + /////////////////////////////////////////// + //structure that implements stack interface. return biggest element in stack + //answer is actually to have two stacks a read and mirror, as you add to read stack, you challenge and add the + //largest to the mirror stack, everytime you add to original stack, keep push() current largest to mirror stack + + + Collection stack = new Stack<>(); + + for (int i=0; i <10000; i++) { + stack.add(randNumGen.nextInt(1000)); + } + + Iterator iter = stack.iterator(); + int currentMax = iter.next(); + System.out.println(currentMax); + + while (iter.hasNext()){ + if (iter.next() >= currentMax) { + currentMax = iter.next();; + } + } + + System.out.println(stack); + System.out.println(currentMax); + + + } + + +} diff --git a/Dao/.classpath b/Dao/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/Dao/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Dao/.gitignore b/Dao/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/Dao/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/Dao/.project b/Dao/.project new file mode 100644 index 0000000..39cd7fd --- /dev/null +++ b/Dao/.project @@ -0,0 +1,17 @@ + + + Dao + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Dao/.settings/org.eclipse.jdt.core.prefs b/Dao/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/Dao/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +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.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/DriversLicense/.classpath b/DriversLicense/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/DriversLicense/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/DriversLicense/.gitignore b/DriversLicense/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/DriversLicense/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/DriversLicense/.project b/DriversLicense/.project new file mode 100644 index 0000000..26f992f --- /dev/null +++ b/DriversLicense/.project @@ -0,0 +1,17 @@ + + + DriversLicense + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/DriversLicense/.settings/org.eclipse.jdt.core.prefs b/DriversLicense/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/DriversLicense/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +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.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/DriversLicense/src/DriversLicense.java b/DriversLicense/src/DriversLicense.java new file mode 100644 index 0000000..051bfa1 --- /dev/null +++ b/DriversLicense/src/DriversLicense.java @@ -0,0 +1,108 @@ +import java.time.LocalDate; +import java.time.Period; + + +/* + * The DriversLicense class must include the following attributes: + +First Name +Last Name +DOB +Height +Gender +Your DriversLicense class should have a getFullName() method that returns the full name by concatenating the first name and the last name attributes. + +Your DriversLicenseclass should have a getAge() method that returns the age by based on the DOB attribute. + */ +public class DriversLicense { + /** + * instantiating attributes of DL + */ + private String firstName; + private String lastName; + private LocalDate dateOfBirth; + private String height; + private String gender; + + /** + * default constructor method that takes in no parameters + */ + protected DriversLicense() { + + } + + /** + * overloaded constructor that assigns all attributes of DL + * @param fn firstname + * @param ln lastname + * @param dob dateofbirth + * @param h height + * @param g gender + */ + protected DriversLicense(String fn, String ln, LocalDate dob, String h, String g) { + firstName = fn; + lastName = ln; + dateOfBirth = dob; + height = h; + gender = g; + } + + /** + * getters and setters + * @return first name + */ + protected String getFirstName() { + return firstName; + } + + protected void setFirstName(String firstName) { + this.firstName = firstName; + } + + protected String getLastName() { + return lastName; + } + + protected void setLastName(String lastName) { + this.lastName = lastName; + } + + protected LocalDate getDOB() { + return dateOfBirth; + } + + protected void setDOB(LocalDate dateOfBirth) { + this.dateOfBirth = dateOfBirth; + } + + protected String getHeight() { + return height; + } + + protected void setHeight(String height) { + this.height = height; + } + + protected String getGender() { + return gender; + } + + protected void setGender(String gender) { + this.gender = gender; + } + + protected String getFullName() { + return firstName + " " + lastName; + } + + public int getAge() { + LocalDate currentDate = LocalDate.now(); + if ((dateOfBirth != null) && (currentDate != null)) { + return Period.between(dateOfBirth, currentDate).getYears(); + } else { + return 0; + } + } + + +} \ No newline at end of file diff --git a/DriversLicense/src/LicenseProgram.java b/DriversLicense/src/LicenseProgram.java new file mode 100644 index 0000000..96c0a32 --- /dev/null +++ b/DriversLicense/src/LicenseProgram.java @@ -0,0 +1,57 @@ +import java.time.LocalDate; + +/* + * Create a DriversLicense Java project with two classes, DriversLicense and LicenseProgram. + +You"ll use the LicenseProgram class to run your program and create DriversLicense instances. +The LicenseProgram class will contain one main method (and nothing else). +When run, LicenseProgram should create three different instances of a DriversLicense and print out the full name and age on each license. +Include comments in your code. At the minimum, include a comment for each method to explain what it does. If you submit code without any comments, 5 points will be subtracted from your assignment score. + */ +public class LicenseProgram { + public static void main(String[] args) { + + /* + * creating each persons bday objects + */ + LocalDate person1BDay = LocalDate.of(1940, 10, 9); + LocalDate person2Bday = LocalDate.of(1942, 6, 14); + LocalDate person3BDay = LocalDate.of(1942, 2, 25); + LocalDate person4BDay = LocalDate.of(1940, 7, 7); + + + /* + * instantiating person1 driverlicense object using overloaded constructor + */ + DriversLicense person1 = new DriversLicense("John","Lennon",person1BDay,"5 10","Male"); + System.out.println(person1.getFullName()); + System.out.println(person1.getAge()); + + /* + * instantiating person2 driver license object using default constructor + */ + DriversLicense person2 = new DriversLicense(); + + /* + * using setters to set attributes to person2 object + */ + person2.setFirstName("Paul"); + person2.setLastName("McCartney"); + person2.setDOB(person2Bday); + person2.setHeight("5 11"); + person2.setGender("Male"); + person2.getFullName(); + System.out.println(person2.getFullName()); + System.out.println(person2.getAge()); + + DriversLicense person3 = new DriversLicense("George","Harrison",person3BDay,"5 10","Male"); + System.out.println(person3.getFullName()); + System.out.println(person3.getAge()); + + DriversLicense person4 = new DriversLicense("Ringo","Star",person4BDay,"5 6","Male"); + System.out.println(person4.getFullName()); + System.out.println(person4.getAge()); + + + } +} diff --git a/FibonacciSeq/.classpath b/FibonacciSeq/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/FibonacciSeq/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/FibonacciSeq/.gitignore b/FibonacciSeq/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/FibonacciSeq/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/FibonacciSeq/.project b/FibonacciSeq/.project new file mode 100644 index 0000000..b8d0818 --- /dev/null +++ b/FibonacciSeq/.project @@ -0,0 +1,17 @@ + + + FibonacciSeq + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/FibonacciSeq/.settings/org.eclipse.jdt.core.prefs b/FibonacciSeq/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/FibonacciSeq/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +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.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/FibonacciSeq/bin/FibonacciSeq/FibonacciSeq.class b/FibonacciSeq/bin/FibonacciSeq/FibonacciSeq.class new file mode 100644 index 0000000..7a6d3c4 Binary files /dev/null and b/FibonacciSeq/bin/FibonacciSeq/FibonacciSeq.class differ diff --git a/FibonacciSeq/src/FibonacciSeq/FibonacciSeq.java b/FibonacciSeq/src/FibonacciSeq/FibonacciSeq.java new file mode 100644 index 0000000..e02350e --- /dev/null +++ b/FibonacciSeq/src/FibonacciSeq/FibonacciSeq.java @@ -0,0 +1,20 @@ +package FibonacciSeq; + +public class FibonacciSeq { + + public static void main(String[] args) { + // TODO Auto-generated method stub + System.out.println(getfebSeq(4)); + } + + public static int getfebSeq(int index) { + int firstsecpos = 1; + + if (index == 0 || index == 1) { + return firstsecpos; + } else { + return getfebSeq(index - 1) + getfebSeq(index - 2); + } + } + +} diff --git a/GradeBook/.classpath b/GradeBook/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/GradeBook/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/GradeBook/.gitignore b/GradeBook/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/GradeBook/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/GradeBook/.project b/GradeBook/.project new file mode 100644 index 0000000..53d01ac --- /dev/null +++ b/GradeBook/.project @@ -0,0 +1,17 @@ + + + GradeBook + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/GradeBook/.settings/org.eclipse.jdt.core.prefs b/GradeBook/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/GradeBook/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +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.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/GradeBook/src/GradeBook.java b/GradeBook/src/GradeBook.java new file mode 100644 index 0000000..ea09472 --- /dev/null +++ b/GradeBook/src/GradeBook.java @@ -0,0 +1,77 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Scanner; + +/* + * Your program should ask the user to input the total number of students in the gradebook. +Your program should ask the user to input each student's name, and a list of grades for that student (as a comma-separated string). +Your program should print out each student's name and the average grade for that student. +Guidelines: + +Your program should store the students and the associated grades (as a comma-seperated string) in a Map +Your program should compute the average grade for each student, and create a new Map that stores the students and their corresponding grade average. +Use the Map that contains the students and their average grade to retrieve and print out the results. +When implementing your solution, use helper methods and include comments in your code. + */ +public class GradeBook { + public static void main(String[] args) { + //Prompting user for input and recording response in scanner + System.out.print("Input total number of students: "); + Scanner reader = new Scanner(System.in); + String studentsInput = reader.nextLine(); + + //instantiate hashmap for students and grades + Map gradeBook = new HashMap(); + + //instantiate hashmap for students and averages + Map studentAvgs = new HashMap(); + + //creating student arraylist to add students so I can reference from map later + ArrayList students = new ArrayList(); + + //Prompting user to input student grades + for(int i=1; i<=Integer.parseInt(studentsInput);i++) { + System.out.println("Input the student name."); + String studentEntry = reader.nextLine(); + + students.add(studentEntry); + + System.out.println("Input student grades seperated by comma."); + String studentGrades = reader.nextLine(); + + List gradeArray = new ArrayList(Arrays.asList(studentGrades.split(","))); + + //add grades to mapped student and add up total of grades + int gradeTotal = 0; + for(int j=0; j < gradeArray.size(); j++) { + gradeBook.put(studentEntry, gradeArray.get(j)); + gradeTotal += Integer.parseInt(gradeArray.get(j)); + } + + //calculate average + double studentAvg = (double) gradeTotal/gradeArray.size(); + + //add student and average to avg map + studentAvgs.put(studentEntry, studentAvg); + } + + /* + Iterator itr = studentAvgs.values().iterator(); + while (itr.hasNext()) { + System.out.println(itr.next()); + } + */ + //print out student names and averages + for(int i=0; i + + + + + diff --git a/InputStreams/.gitignore b/InputStreams/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/InputStreams/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/InputStreams/.project b/InputStreams/.project new file mode 100644 index 0000000..57d3fb9 --- /dev/null +++ b/InputStreams/.project @@ -0,0 +1,17 @@ + + + InputStreams + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/InputStreams/.settings/org.eclipse.jdt.core.prefs b/InputStreams/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/InputStreams/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +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.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/InputStreams/src/IOStream.java b/InputStreams/src/IOStream.java new file mode 100644 index 0000000..b6755ab --- /dev/null +++ b/InputStreams/src/IOStream.java @@ -0,0 +1,22 @@ +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +public class IOStream { + + public static void main(String[] args) throws IOException { + InputStream jay = new FileInputStream("C://users/matthew_hauser/pictures/jay.jpg"); + OutputStream jayMovin = new FileOutputStream("C://users/matthew_hauser/desktop/jayHasMoved.jpg"); + + + + + jayMovin.write(jay.read()); + jay.close(); + jayMovin.close(); + + } +} diff --git a/ParkingGarage/.classpath b/ParkingGarage/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/ParkingGarage/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/ParkingGarage/.gitignore b/ParkingGarage/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/ParkingGarage/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/ParkingGarage/.project b/ParkingGarage/.project new file mode 100644 index 0000000..7ef66aa --- /dev/null +++ b/ParkingGarage/.project @@ -0,0 +1,17 @@ + + + ParkingGarage + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/ParkingGarage/.settings/org.eclipse.jdt.core.prefs b/ParkingGarage/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/ParkingGarage/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +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.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/ParkingGarage/src/Car.java b/ParkingGarage/src/Car.java new file mode 100644 index 0000000..310a45a --- /dev/null +++ b/ParkingGarage/src/Car.java @@ -0,0 +1,45 @@ + +public class Car { + private String color; + private String licenseNum; + private String make; + private String model; + + protected Car() { + + } + + protected Car(String myColor, String myLicenseNum, String myMake, String myModel) { + color = myColor; + licenseNum = myLicenseNum; + make = myMake; + model = myModel; + } + + public String getColor() { + return color; + } + public void setColor(String color) { + this.color = color; + } + public String getLicenseNum() { + return licenseNum; + } + public void setLicenseNum(String licenseNum) { + this.licenseNum = licenseNum; + } + public String getMake() { + return make; + } + public void setMake(String make) { + this.make = make; + } + public String getModel() { + return model; + } + public void setModel(String model) { + this.model = model; + } + + +} diff --git a/ParkingGarage/src/GarageManager.java b/ParkingGarage/src/GarageManager.java new file mode 100644 index 0000000..14485a1 --- /dev/null +++ b/ParkingGarage/src/GarageManager.java @@ -0,0 +1,85 @@ +/* + * Requirements +Your program should implement a Car class, a ParkingGarage class, and a GarageManager class. +The GarageManager Class and the Main method +The GarageManager class will contain the main(String[] args) method for your program. It doesn't need to contain anything else. + +Your main() method will act as the "driver" for this program. + +In your main() method, you should: + +Instantiate a few ParkingGarage instances with different capacities. +Instantiate a few cars, and proceed to park them and unpark them from the garages. +Guidelines +Your implementation should be broken down into different methods. + +Each method should have a well defined "job". + +Include comments in your code. At the minimum, include a comment for each method to explain what it does. If you submit code without any comments, 5 points will be subtracted from your assignment score. + */ +public class GarageManager { + public static void main(String args[]) { + /* + * instantiate a few different garages. two different ways constructor and overloaded + */ + ParkingGarage garage1 = new ParkingGarage(); + ParkingGarage garage2 = new ParkingGarage(4); + + /* + * instantiating some cars + */ + + Car car1 = new Car(); + Car car2 = new Car(); + Car car3 = new Car("white","DJK4LDK","Subaru","Crosstrek"); + Car car4 = new Car("silver","WOD3K5D","Honda","Civic"); + Car car5 = new Car("tan","FJ9DLKS","Toyota","4Runner"); + Car car6 = new Car("purple","SDHF3D","Hyundai","Elantra"); + Car car7 = new Car("green","FJD3DL","Subaru","WRX"); + + /* + * assigning attributes to parking garage + */ + + garage1.setCapacity(1); + + /* + * assigning attributes to cars + */ + + car1.setColor("red"); + car1.setLicenseNum("DJEL4K4"); + car1.setMake("Jeep"); + car1.setModel("Patriot"); + + car2.setColor("black"); + car2.setLicenseNum("DFJDS3"); + car2.setMake("Nissan"); + car2.setModel("Maxima"); + + garage1.park(car1, 0); + garage1.park(car2, 0); + garage2.park(car3, 1); + garage2.park(car4, 2); + garage2.park(car5, 3); + garage2.park(car6, 3); + garage2.park(car7, 4); + + System.out.println(""); + + garage1.printInventory(); + garage2.printInventory(); + + System.out.println(""); + + garage2.vacate(0); + garage2.vacate(0); + garage2.vacate(1); + garage2.vacate(2); + garage2.vacate(3); + garage2.vacate(10); + + + + } +} diff --git a/ParkingGarage/src/ParkingGarage.java b/ParkingGarage/src/ParkingGarage.java new file mode 100644 index 0000000..90e08db --- /dev/null +++ b/ParkingGarage/src/ParkingGarage.java @@ -0,0 +1,111 @@ +/* + * Your implementation of the ParkingGarage class should have a car array(Car[]) to represent the parking spots. The "spot number" of each parking spot is its array index (starting with spot 0). + +Your ParkingGarage constructor should take in capacity as input. This will represent the capacity of the parking garage instance. + +Your ParkingGarage class should implement: + +park(Car car, int spot) method, that will add the car to a parking spot. +If the user attempts to add the car to a spot that doesn't exist (outside the array), catch the exception and notify the user. +If there's already a car parked in the spot, notify the user that the car cannot be parked in that spot. +vacate(int spot) method, that will remove the car from the specified spot. +If the user attempts to remove a car from an empty spot, notify the user that no car is present in that spot. +printInventory() method, that prints out to the console the the listing of all the cars with a brief description. For each car, please include: +The spot number (array index) of the car in the parking garage +The car's color, license #, make, and model + */ +public class ParkingGarage { + //initiating variables that serve as attributes for the parking garage + private Car[] parkingSpots; + private int capacity; + + /* + * constructor that takes in capacity parameter, assigns to capacity attribute and initializes car array that adds spots to "Garage" + */ + protected ParkingGarage() { + + } + + protected ParkingGarage(int capacity) { + this.capacity = capacity; + parkingSpots = new Car[capacity]; + } + + /* + * park method that will adds car object to the car array. + */ + protected void park(Car parkingCar, int spot) { + try { + + if(parkingSpots[spot] == null) { + parkingSpots[spot] = parkingCar; + System.out.println(parkingCar.getMake() + " " + parkingCar.getModel() + " parked in spot "+ (spot+1)); + } else { + System.out.println("Can't park " + parkingCar.getMake() + " " + parkingCar.getModel() + ". " +"Spot " + (spot+1) + " already has a car in it."); + } + } catch (ArrayIndexOutOfBoundsException e) { + System.out.println("Exception occured. That spot doesn't exist in this parking garage."); + } finally { + System.out.println("--------------------------------"); + } + + } + + //Getters and setters + public Car[] getParkingSpots() { + return parkingSpots; + } + + public int getCapacity() { + return capacity; + } + + public void setCapacity(int capacity) { + this.capacity = capacity; + parkingSpots = new Car[capacity]; + } + + /** + * method to vacate car from parking spot + * @param spot that you want to remove car from + */ + protected void vacate(int spot) { + + try { + String carInSpot = parkingSpots[spot].getMake() + " " + parkingSpots[spot].getModel(); + if(parkingSpots[spot] != null) { + parkingSpots[spot] = null; + System.out.println(carInSpot + " has been towed."); + } else { + System.out.println("This spot is already vacated."); + } + } catch (ArrayIndexOutOfBoundsException e) { + System.out.println("Exception occured. That spot doesn't exist in this parking garage."); + } catch (NullPointerException e) { + System.out.println("There is no car to tow from this spot."); + } finally { + System.out.println("--------------------------------"); + } + + + } + + protected void printInventory() { + for(int i=0; i + + + + + diff --git a/PigLatin/.gitignore b/PigLatin/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/PigLatin/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/PigLatin/.project b/PigLatin/.project new file mode 100644 index 0000000..1221824 --- /dev/null +++ b/PigLatin/.project @@ -0,0 +1,17 @@ + + + PigLatin + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/PigLatin/.settings/org.eclipse.jdt.core.prefs b/PigLatin/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/PigLatin/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +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.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/PigLatin/bin/Main.class b/PigLatin/bin/Main.class new file mode 100644 index 0000000..7e3ab56 Binary files /dev/null and b/PigLatin/bin/Main.class differ diff --git a/PigLatin/src/Main.java b/PigLatin/src/Main.java new file mode 100644 index 0000000..d7b6d98 --- /dev/null +++ b/PigLatin/src/Main.java @@ -0,0 +1,76 @@ +import java.util.Random; +import java.util.Scanner; + +public class Main { + public static void main(String[] args) { + System.out.println("This is a pig latin translator. Please enter in a word and I will return the translation."); + + Scanner reader = new Scanner(System.in); + String userInput = reader.nextLine(); + reader.close(); + + String result = ""; + if(userInput.contains(" ")) { + String[] parts = userInput.split(" "); + for (int i = 0; i < parts.length; i++) { + result += convertPigLatin(parts[i]) + " "; + } + } else { + result = convertPigLatin(userInput); + } + + + System.out.println("Translation is " + result); + } + + public static String convertPigLatin(String input) { + if(input.charAt(0) == 'a' || input.charAt(0) == 'e' || input.charAt(0) == 'i' || input.charAt(0) == 'o' || input.charAt(0) == 'u') { + return startsWithVowel(input); + } else if (input.contains("a") || input.contains("e") || input.contains("i") || input.contains("o") || input.contains("u")) { + return startsWithConsonant(input); + } else { + return noVowels(input); + } + } + + public static String startsWithVowel(String input) { + Random randNumGen = new Random(); + int compNum = randNumGen.nextInt(3); + String ranWord; + + if (compNum == 0) { + ranWord = "way"; + } else if (compNum == 1) { + ranWord = "yay"; + } else { + ranWord = "ay"; + } + + String result = input + ranWord; + return result; + } + + public static String startsWithConsonant(String input) { + int positionOfVowel = 0; + for (int i = 0; i < input.length(); i++) { + char firstChar = input.charAt(i); + if (firstChar == 'a' || firstChar == 'e' || firstChar == 'i' || firstChar == 'o' || firstChar == 'u') { + positionOfVowel = i; + break; + } + } + + String lettersBeforeVowel = input.substring(0, positionOfVowel); + String lettersAfterVowel = input.substring(positionOfVowel); + + String result = lettersAfterVowel + lettersBeforeVowel + "ay"; + + return result; + } + + public static String noVowels(String input) { + String result = input + "ay"; + return result; + } + +} diff --git a/Program/.classpath b/Program/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/Program/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Program/.gitignore b/Program/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/Program/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/Program/.project b/Program/.project new file mode 100644 index 0000000..ca4f056 --- /dev/null +++ b/Program/.project @@ -0,0 +1,17 @@ + + + Program + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Program/.settings/org.eclipse.jdt.core.prefs b/Program/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/Program/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +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.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/Rentable/.classpath b/Rentable/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/Rentable/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Rentable/.gitignore b/Rentable/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/Rentable/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/Rentable/.project b/Rentable/.project new file mode 100644 index 0000000..f39121a --- /dev/null +++ b/Rentable/.project @@ -0,0 +1,17 @@ + + + Rentable + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Rentable/.settings/org.eclipse.jdt.core.prefs b/Rentable/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/Rentable/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +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.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/Rentable/src/Condo.java b/Rentable/src/Condo.java new file mode 100644 index 0000000..2e9a156 --- /dev/null +++ b/Rentable/src/Condo.java @@ -0,0 +1,36 @@ + +public class Condo implements Rentable { + public String name; + public double weeklyRate; + + /** + * constructor for condo, similar to room + * @param name will be description of Condo + * @param w price for condo + */ + public Condo(String name, double weeklyRate){ + this.name = name; + this.weeklyRate = weeklyRate; + } + + /** + * auto generated metods from rentable interface contract + */ + @Override + public String getDescription() { + return name; + } + + @Override + public double getDailyRate() { + // TODO Auto-generated method stub + return (double)(weeklyRate / 7.00); + } + + @Override + public double getPrice(double days) { + // TODO Auto-generated method stub + return (double)((weeklyRate / 7) * days); + } + +} diff --git a/Rentable/src/Program.java b/Rentable/src/Program.java new file mode 100644 index 0000000..84ff7f2 --- /dev/null +++ b/Rentable/src/Program.java @@ -0,0 +1,97 @@ +import java.util.Scanner; + +public class Program { + + public static void main(String[] args) { + /* + * instantiating rentable objects + */ + Rentable hotelRoom = new Room("Hilton", 125.87); + Rentable vacationCondo = new Condo("Paradise Resorts", 2380.98); + Rentable visegripTool = new Tool("Park Tools", 7.87); + Rentable hammerTool = new Tool("Hefty", 5.66); + Rentable hostelRoom = new Room("Hip Hostel", 45.43); + Rentable timeshareCondo = new Condo("Mountain Bliss", 2083.88); + + Rentable[] objectsForRent = new Rentable[8]; + + objectsForRent[0] = hotelRoom; + objectsForRent[1] = vacationCondo; + objectsForRent[2] = visegripTool; + objectsForRent[3] = hammerTool; + objectsForRent[4] = hostelRoom; + objectsForRent[5] = timeshareCondo; + + //I can also assign array value directly to object + objectsForRent[6] = new Room("Marriot", 104.56); + objectsForRent[7] = new Tool("Crank Brothers", 10.32); + + //I can also initialize array and assign objects all in one line + Rentable[] objectsForRentElsewhere = {new Condo("Cabin in the Woods", 790.43), new Room("Luxury Downtown Airbnb in Ausitn", 230.44)}; + + System.out.println("Available to rent!"); + System.out.println("-------------------------------------------------"+"\n"); + + Scanner reader = new Scanner(System.in); + String rentAnswer = "No"; + int daysOfStay = 0; + + do { + /** + * looping through each rentable object to display details, prompt user for price + */ + for(Rentable r: objectsForRent) { + + if(rentAnswer.toLowerCase().equals("no")) { + System.out.println((r.getClass().toString()).substring(6) + ": " + r.getDescription() + ", daily rate of $" + r.getDailyRate()); + } + + if(rentAnswer.toLowerCase().equals("yes")) { + if(r instanceof Room) { + System.out.println("Room: " + r.getDescription() + ", total rent cost $" + r.getPrice(daysOfStay)); + } + + if(r instanceof Condo) { + System.out.println("Condo: " + r.getDescription() + ", total rent cost $" + r.getPrice(daysOfStay)); + } + + if(r instanceof Tool) { + System.out.println("Tool: " + r.getDescription() + ", total rent cost $" + r.getPrice(daysOfStay)); + } + + } + + } + + + System.out.println("\n" + "Would you like to get price estimate for your stay?"); + boolean validPick = false; + while(!validPick) { + try { + rentAnswer = reader.next(); + checkUserInput(rentAnswer); + validPick = true; + + } catch (Exception e) { + System.out.println("Please enter a yes or no."); + } + } + + if(rentAnswer.equalsIgnoreCase("yes")) { + System.out.println("How many days?"); + daysOfStay = reader.nextInt(); + } else break; + + } + while(rentAnswer.equalsIgnoreCase("Yes")); + + reader.close(); + + } + public static void checkUserInput(String s) { + if(!(s.toLowerCase().equals("yes") || s.toLowerCase().equals("no"))) { + throw new IllegalArgumentException(); + } + } + +} diff --git a/Rentable/src/Rentable.java b/Rentable/src/Rentable.java new file mode 100644 index 0000000..b63fe57 --- /dev/null +++ b/Rentable/src/Rentable.java @@ -0,0 +1,7 @@ + +public interface Rentable { + + public String getDescription(); + public double getDailyRate(); + public double getPrice(double days); +} diff --git a/Rentable/src/Room.java b/Rentable/src/Room.java new file mode 100644 index 0000000..38ca84d --- /dev/null +++ b/Rentable/src/Room.java @@ -0,0 +1,30 @@ + +public class Room implements Rentable { + + public String name; + public double dailyRate; + + public Room(String name, double dailyRate) { + this.name = name; + this.dailyRate = dailyRate; + } + + @Override + public String getDescription() { + // TODO Auto-generated method stub + return name; + } + + @Override + public double getDailyRate() { + // TODO Auto-generated method stub + return dailyRate; + } + + @Override + public double getPrice(double days) { + // TODO Auto-generated method stub + return (double)(dailyRate * days); + } + +} diff --git a/Rentable/src/Tool.java b/Rentable/src/Tool.java new file mode 100644 index 0000000..38eae4d --- /dev/null +++ b/Rentable/src/Tool.java @@ -0,0 +1,30 @@ + +public class Tool implements Rentable { + + public String name; + public double hourlyRate; + + public Tool(String name, double hourlyRate) { + this.name = name; + this.hourlyRate = hourlyRate; + } + + @Override + public String getDescription() { + // TODO Auto-generated method stub + return name; + } + + @Override + public double getDailyRate() { + // TODO Auto-generated method stub + return (double)(hourlyRate * 24); + } + + @Override + public double getPrice(double days) { + // TODO Auto-generated method stub + return (double)(hourlyRate * 24 * days); + } + +} diff --git a/RockPaperScissors/.classpath b/RockPaperScissors/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/RockPaperScissors/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/RockPaperScissors/.gitignore b/RockPaperScissors/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/RockPaperScissors/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/RockPaperScissors/.project b/RockPaperScissors/.project new file mode 100644 index 0000000..f5d918c --- /dev/null +++ b/RockPaperScissors/.project @@ -0,0 +1,17 @@ + + + RockPaperScissors + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/RockPaperScissors/.settings/org.eclipse.jdt.core.prefs b/RockPaperScissors/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/RockPaperScissors/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +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.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/RockPaperScissors/bin/rockPS/RockPaperScissors.class b/RockPaperScissors/bin/rockPS/RockPaperScissors.class new file mode 100644 index 0000000..ceffe54 Binary files /dev/null and b/RockPaperScissors/bin/rockPS/RockPaperScissors.class differ diff --git a/RockPaperScissors/src/rockPS/RockPaperScissors.java b/RockPaperScissors/src/rockPS/RockPaperScissors.java new file mode 100644 index 0000000..19c33d3 --- /dev/null +++ b/RockPaperScissors/src/rockPS/RockPaperScissors.java @@ -0,0 +1,69 @@ +package rockPS; +import java.util.Random; +import java.util.Scanner; + +public class RockPaperScissors { + public static void main(String[] args) { + System.out.println("Rock Paper Scissors, make your pick"); + + String yourHand = yourHand(); + String computerHand = generateHand(); + + System.out.println("You: " + yourHand); + System.out.println("Opponent: " + computerHand); + + String winningMove = winningMoves(yourHand, computerHand); + + if (yourHand.equals(winningMove)) { + System.out.println("You won!"); + } else if (winningMove == computerHand) { + System.out.println("Womp, womp. The computer won."); + } else if (winningMove == "Tie"){ + System.out.println("It was a tie. Play again!"); + } + + } + + public static String yourHand() { + Scanner reader = new Scanner(System.in); + String yourPick = reader.nextLine(); + reader.close(); + + return yourPick; + } + + public static String generateHand() { + Random randNumGen = new Random(); + int compNum = randNumGen.nextInt(3); + String compHand; + + if (compNum == 0) { + compHand = "Rock"; + } else if (compNum == 1) { + compHand = "Paper"; + } else { + compHand = "Scissors"; + } + + return compHand; + } + + public static String winningMoves(String pickOne, String pickTwo) { + if (pickOne.equals(pickTwo)) { + return "Tie"; + } + else if ((pickOne.equals("Rock") || pickTwo.equals("Rock")) && (pickOne.equals("Scissors") || pickTwo.equals("Scissors"))) { + return "Rock"; + } + else if ((pickOne.equals("Rock") || pickTwo.equals("Rock")) && (pickOne.equals("Paper") || pickTwo.equals("Paper"))) { + return "Paper"; + } + else if ((pickOne.equals("Paper") || pickTwo.equals("Paper")) && (pickOne.equals("Scissors") || pickTwo.equals("Scissors"))) { + return "Scissors"; + } else { + return "Invalid"; + } + } + + +} diff --git a/Statistics/.classpath b/Statistics/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/Statistics/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Statistics/.gitignore b/Statistics/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/Statistics/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/Statistics/.project b/Statistics/.project new file mode 100644 index 0000000..e98850d --- /dev/null +++ b/Statistics/.project @@ -0,0 +1,17 @@ + + + Statistics + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Statistics/.settings/org.eclipse.jdt.core.prefs b/Statistics/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/Statistics/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +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.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/Statistics/src/Statistics.java b/Statistics/src/Statistics.java new file mode 100644 index 0000000..4832000 --- /dev/null +++ b/Statistics/src/Statistics.java @@ -0,0 +1,63 @@ +import java.util.Scanner; + +public class Statistics { + public static void main(String[] args) { + System.out.println("Please enter a list of numbers delimmited by comma."); + + Scanner reader = new Scanner(System.in); + String numberList = reader.nextLine(); + reader.close(); + + String[] numbString = numberList.split(","); + int[] numbs = new int[numbString.length]; + + for (int i = 0; i < numbs.length; i++) { + numbs[i] = Integer.parseInt(numbString[i]); + } + + int minNumb = calcMin(numbs); + int maxNumb = calcMax(numbs); + int sumNumb = calcSum(numbs); + int lengthNumb = numbs.length; + double avgNumb = (double)sumNumb / lengthNumb; + + System.out.println(minNumb); + System.out.println(maxNumb); + System.out.println(lengthNumb); + System.out.println(sumNumb); + System.out.println(avgNumb); + + + } + + public static int calcMin(int[] numbArray) { + int currentMin = numbArray[0]; + for (int i = 1; i < numbArray.length; i++) { + if (numbArray[i] <= currentMin) { + currentMin = numbArray[i]; + } + + } + return currentMin; + } + + public static int calcMax(int[] numbArray) { + int currentMax = numbArray[0]; + for (int i = 1; i < numbArray.length; i++) { + if (numbArray[i] >= currentMax) { + currentMax = numbArray[i]; + } + + } + return currentMax; + } + + public static int calcSum(int[] numbArray) { + int sum = 0; + for(int i = 0; i < numbArray.length; i++) { + sum += numbArray[i]; + } + return sum; + } + +} diff --git a/SubClassInheritanceClass/.classpath b/SubClassInheritanceClass/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/SubClassInheritanceClass/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/SubClassInheritanceClass/.gitignore b/SubClassInheritanceClass/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/SubClassInheritanceClass/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/SubClassInheritanceClass/.project b/SubClassInheritanceClass/.project new file mode 100644 index 0000000..a01089d --- /dev/null +++ b/SubClassInheritanceClass/.project @@ -0,0 +1,17 @@ + + + SubClassInheritanceClass + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/SubClassInheritanceClass/.settings/org.eclipse.jdt.core.prefs b/SubClassInheritanceClass/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/SubClassInheritanceClass/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +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.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/SubClassInheritanceClass/src/Car.java b/SubClassInheritanceClass/src/Car.java new file mode 100644 index 0000000..778ef87 --- /dev/null +++ b/SubClassInheritanceClass/src/Car.java @@ -0,0 +1,25 @@ + +public class Car extends Vehicle{ + + public int numberOfDoors; + + public Car(int numWheels, int capacity, int numberOfDoors) { + super(numWheels, capacity); + this.numberOfDoors = numberOfDoors; + } + + @Override + public String toString() { + return "Car [numberOfDoors=" + numberOfDoors + ", getNumWheels()=" + getNumWheels() + ", getCapacity()=" + + getCapacity() + "]"; + } + + @Override + public String honk() { + // TODO Auto-generated method stub + return "ERRRR ERRRRR"; + } + + + +} diff --git a/SubClassInheritanceClass/src/Motorbike.java b/SubClassInheritanceClass/src/Motorbike.java new file mode 100644 index 0000000..e26ec9e --- /dev/null +++ b/SubClassInheritanceClass/src/Motorbike.java @@ -0,0 +1,27 @@ + +public class Motorbike extends Vehicle{ + + private String type; + + public Motorbike(int capacity, String type) { + super(2, capacity); + this.type = type; + } + + @Override + public String toString() { + return "Motorbike [type=" + type + ", getNumWheels()=" + getNumWheels() + ", getCapacity()=" + getCapacity() + + "]"; + } + + public String getType() { + return type; + } + + public String honk() { + return "TOOOOOOOOT! TOOOOOOOOT!"; + } + + + +} diff --git a/SubClassInheritanceClass/src/Program.java b/SubClassInheritanceClass/src/Program.java new file mode 100644 index 0000000..556c1cf --- /dev/null +++ b/SubClassInheritanceClass/src/Program.java @@ -0,0 +1,69 @@ +import java.util.ArrayList; +import java.util.List; + +public class Program { + public static void main(String[] args) { + Vehicle subie = new Car(4, 5, 4); + + System.out.println("Showing toString print of an object and that it will receive the honk method from it's class (not parent)."); + System.out.println(subie); + System.out.println(subie.honk()); + + System.out.println("Now same thing but with motorbike."); + Vehicle moto1 = (Vehicle)new Motorbike(2, "cruiser"); + System.out.println((Vehicle)moto1); + + System.out.println(moto1.honk()); + + List vehicleList = new ArrayList<>(); + vehicleList.add(subie); + vehicleList.add(moto1); + + System.out.println("Showing that the object will print instance that it is including superclass parent"); + printClass(subie); + printClass(moto1); + + System.out.println("Showing that casting a more generic super class has no meaning."); + //just showing that casting as superclass does not change it + printClass((Vehicle)moto1); + + System.out.println("Now showing example that casting is being used to make the object more specific thus being able to access that class' method from just generic passed value."); + printDescription(subie); + printDescription(moto1); + + for(Vehicle v: vehicleList) { + System.out.println(v.rude()); + } + + } + + public static void printClass(Vehicle v) { + if(v instanceof Car) { + System.out.println("it's a car"); + } + + if(v instanceof Motorbike) { + System.out.println("it's a moto"); + } + + if(v instanceof Vehicle) { + System.out.println("it's a vehicle"); + } + } + + public static void printDescription(Vehicle v) { + if(v instanceof Car) { + System.out.println("it's a car"); + System.out.println("It has "+((Car)v).getNumWheels()+" doors"); + } + + if(v instanceof Motorbike) { + System.out.println("it's a moto"); + System.out.println("It is "+((Motorbike)v).getType()+" type of motorbike"); + } + + if(v instanceof Vehicle) { + System.out.println("it's a vehicle"); + } + } +} diff --git a/SubClassInheritanceClass/src/Vehicle.java b/SubClassInheritanceClass/src/Vehicle.java new file mode 100644 index 0000000..7755a5e --- /dev/null +++ b/SubClassInheritanceClass/src/Vehicle.java @@ -0,0 +1,52 @@ + +/* + * what abstract means is could not instantiate object of that class type. you would remove bat mobile examples. + * limitation is that you can not instantiate + * benefit is that you can make method abstract. + */ +public abstract class Vehicle { + //final: once it's set, it cannot be changed. + private final int numWheels; + private final int capacity; + + //this means that there is only one batmobile bc it's static. --commented out due to abstract addition + /* + * private static Vehicle BATMOBILE = new Vehicle(6,2); + */ + + //this says that a vehicle "type" must have honk method + public abstract String honk(); + + //rude knows that there is a honk method available to call. + public String rude() { + return "get off the rode!" + honk(); + } + + public int getNumWheels() { + return numWheels; + } + + public int getCapacity() { + return capacity; + } + + public Vehicle(int numWheels, int capacity) { + this.numWheels = numWheels; + this.capacity = capacity; + } + + /* + * method below commented out due to class now being abstract + */ + /* + * public static Vehicle getBatMobile() { + return BATMOBILE; + } + */ + + + @Override + public String toString() { + return "Vehicle [numWheels=" + numWheels + ", capacity=" + capacity + "]"; + } +} diff --git a/TicTacToe/.classpath b/TicTacToe/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/TicTacToe/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/TicTacToe/.gitignore b/TicTacToe/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/TicTacToe/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/TicTacToe/.project b/TicTacToe/.project new file mode 100644 index 0000000..d6bf9b5 --- /dev/null +++ b/TicTacToe/.project @@ -0,0 +1,17 @@ + + + TicTacToe + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/TicTacToe/.settings/org.eclipse.jdt.core.prefs b/TicTacToe/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/TicTacToe/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +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.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/TicTacToe/src/TicTacToe.java b/TicTacToe/src/TicTacToe.java new file mode 100644 index 0000000..9b41c16 --- /dev/null +++ b/TicTacToe/src/TicTacToe.java @@ -0,0 +1,88 @@ +import java.util.Scanner; + +public class TicTacToe { + + static String player = " X"; + static String[][] board = new String[][]{ + {" "," "," "}, + {" "," "," "}, + {" "," "," "} + }; + + public static void main(String[] args) { + System.out.println("Let's play tic tac toe."); + printBoard(); + + System.out.println("It's player "+player+"'s turn"); + + while(!didPlayerWin()) { + playTurn(); + } + + } + + + public static void playTurn( ) { + System.out.println("You will enter the row and column for your position placement."); + System.out.print("Enter Row: "); + + Scanner reader = new Scanner(System.in); + int playerRow = Integer.parseInt(reader.nextLine()); + + System.out.print("Enter Column: "); + int playerCol = Integer.parseInt(reader.nextLine()); + + if(board[playerRow][playerCol] != " ") { + System.out.println("Invalid move. Player already in position."); + playTurn(); + } else { + board[playerRow][playerCol] = player; + } + + + printBoard(); + + if(didPlayerWin()) { + System.out.println("Player " + player + " wins!"); + } else { + player = (player == " X") ? " O" : " X"; + System.out.println("It's player "+player+"'s turn"); + playTurn(); + } + + reader.close(); + + } + + public static void printBoard() { + System.out.println(" 0 1 2"); + System.out.println("0 " + String.join(" |",board[0])); + System.out.println(" -----------"); + System.out.println("1 " + String.join(" |",board[1])); + System.out.println(" -----------"); + System.out.println("2 " + String.join(" |",board[2])); + } + + public static boolean didPlayerWin() { + if ((board[0][0] == player && board[0][1] == player && board[0][2] == player) || + (board[1][0] == player && board[1][1] == player && board[1][2] == player) || + (board[2][0] == player && board[2][1] == player && board[2][2] == player) + ) { + return true; + } else if ((board[0][0] == player && board[1][0] == player && board[2][0] == player) || + (board[0][1] == player && board[1][1] == player && board[2][1] == player) || + (board[0][2] == player && board[1][2] == player && board[2][2] == player) + ) { + return true; + } else if ((board[0][0] == player && board[1][1] == player && board[2][2] == player) || + (board[0][2] == player && board[1][1] == player && board[2][0] == player) + ) { + return true; + + } + + return false; + } + + +} diff --git a/TimesheetApp/.classpath b/TimesheetApp/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/TimesheetApp/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/TimesheetApp/.gitignore b/TimesheetApp/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/TimesheetApp/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/TimesheetApp/.project b/TimesheetApp/.project new file mode 100644 index 0000000..c5b5e8c --- /dev/null +++ b/TimesheetApp/.project @@ -0,0 +1,17 @@ + + + TimesheetApp + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/TimesheetApp/.settings/org.eclipse.jdt.core.prefs b/TimesheetApp/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/TimesheetApp/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +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.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/TimesheetApp/src/ConsoleUtils.java b/TimesheetApp/src/ConsoleUtils.java new file mode 100644 index 0000000..5553163 --- /dev/null +++ b/TimesheetApp/src/ConsoleUtils.java @@ -0,0 +1,112 @@ +import java.time.format.DateTimeFormatter; +import java.util.List; +import java.util.Scanner; + +public class ConsoleUtils { + + /* Member variables */ + + private Scanner scanner; + private DateTimeFormatter timeFormatter; + + /* Constructor */ + + public ConsoleUtils(){ + scanner = new Scanner(System.in); + timeFormatter = DateTimeFormatter.ofPattern("MM/dd/yy HH:mm"); + } + + /* Methods */ + + /* + * Prints the menu of actions to the console + */ + public void printHelp(){ + System.out.println("Valid commands: "); + System.out.println(" list [PROJECT] [-a] list entries; project and/or active flag are optional"); + System.out.println(" add add an entry, and set the start time"); + System.out.println(" stop ID update the entry's end time"); + System.out.println(" delete ID delete entry with the ID"); + System.out.println(" help print help"); + System.out.println(" quit quit the app"); + System.out.println(); + + } + + /* + * Prints an informational message to the console + */ + public void info(String msg){ + System.out.println("["+msg+"]"); + System.out.println(); + } + + /* + * Prints an error message to the console + */ + public void error(String msg){ + System.out.println("[ERROR: "+msg+"]"); + System.out.println(); + } + + /* + * Prompts the user to enter input + * Returns the text entered by the user + */ + public String promptString(String label){ + System.out.print(label+" "); + return scanner.nextLine(); + } + + /* + * Prints a list of TimesheetEntry objects in a pretty table + */ + public void printList(List entries){ + int longestProject = 7; + int longestTask = 4; + + for(TimesheetEntry entry : entries){ + if(entry.getProjectName().length() > longestProject){ + longestProject = entry.getProjectName().length(); + } + if(entry.getTask().length() > longestTask) { + longestTask = entry.getTask().length(); + } + } + + String projectHeader = String.format("%"+longestProject+"s", "Project"); + String projectUnderline = ""; + for(int i=0;i "); + String[] actionParts = input.split(" "); + String action = actionParts[0].trim(); // Primary action + + // Figure out what to do depending on the user's primary action + if (action.equals("add")) { + + processAddAction(); + + } else if (action.equals("delete")) { + + processDeleteAction(actionParts); + + } else if (action.equals("stop")) { + + processStopAction(actionParts); + + } else if (action.equals("list")) { + + processListAction(actionParts); + + } else if (action.equals("quit")) { + + quit = true; + + } else if (action.equals("help")) { + + ConsoleUtils helper = new ConsoleUtils(); + helper.printHelp(); + + } else if(action.length() ==0 ){ + + // do nothing. + + } else { + + // Your code here + + } + } + + } + + /* + * The user requested that a given TimesheetEntry be stopped (marked as complete) + * This method conveys that request to the Timesheet + */ + public void processStopAction(String[] actionParts){ + + if(actionParts.length > 2){ + consoleUtils.error("Too many inputs to stop command"); + return; + } + + int id = Integer.parseInt(actionParts[1]); + + timesheet.stop(timesheet.get(id)); + } + + /* + * The user requested that a given TimesheetEntry be deleted + * This method conveys that request to the Timesheet + */ + public void processDeleteAction(String[] actionParts){ + + if(actionParts.length > 2){ + consoleUtils.error("Too many inputs to delete command"); + return; + } + + int id = Integer.parseInt(actionParts[1]); + + timesheet.delete(timesheet.get(id)); + } + + /* + * The user wants to view a list of timesheet entries + * This method conveys that request to the Timesheet, + * along with any special options (active-only, filter by project name) + */ + public void processListAction(String[] actionParts){ + + if(actionParts.length > 3){ + consoleUtils.error("Too many inputs to list command"); + return; + } else { + List entry = new ArrayList(); + if(actionParts.length == 2) { + if(actionParts[1].equals("-a")) { + entry = timesheet.list(true, null); + consoleUtils.printList(entry); + } else { + entry = timesheet.list(false, actionParts[1].toString()); + consoleUtils.printList(entry); + } + } else if (actionParts.length == 3) { + if(actionParts[1].equals("-a")) { + entry = timesheet.list(true, actionParts[2].toString()); + consoleUtils.printList(entry); + } else if(actionParts[2].equals("-a")) { + entry = timesheet.list(true, actionParts[1].toString()); + consoleUtils.printList(entry); + } + } else { + entry = timesheet.list(false, null); + consoleUtils.printList(entry); + } + + } + + + } + + /* + * The user wants to add a new entry to the Timesheet + * This method conveys that request to the Timesheet, along with + * the specified project name and task description + */ + public void processAddAction(){ + + String project = null; + + //implementing try catch to ensure user only enters one word + boolean oneWord = false; + while(!oneWord) { + try { + project = consoleUtils.promptString("Project Name (one word only):"); + verifyOneWord(project); + oneWord = true; + + } catch (Exception e) { + System.out.println("Program is throwing an exception: " + e); + System.out.println("Please enter only one word for project name."); + } + } + + String description = consoleUtils.promptString("Task:"); + timesheet.add(project, description); + + } + + //method that checks if user only enters one word it trims the string, and then checks if it contains a space + public static void verifyOneWord (String s) { + if(s.trim().contains(" ")) { + throw new IllegalArgumentException(); + } + } +} \ No newline at end of file diff --git a/TimesheetApp/src/Main.java b/TimesheetApp/src/Main.java new file mode 100644 index 0000000..e6e23e3 --- /dev/null +++ b/TimesheetApp/src/Main.java @@ -0,0 +1,9 @@ + +public class Main { + public static void main(String[] args) { + + Controller menuActions = new Controller(); + + menuActions.start(); + } +} diff --git a/TimesheetApp/src/Timesheet.java b/TimesheetApp/src/Timesheet.java new file mode 100644 index 0000000..c8124aa --- /dev/null +++ b/TimesheetApp/src/Timesheet.java @@ -0,0 +1,82 @@ +import java.util.List; +import java.time.LocalDateTime; +import java.util.ArrayList; + +public class Timesheet { + private List database; + + /** + * constructor initializes a new list of type arraylist + */ + public Timesheet() { + database = new ArrayList(); + } + + public void add(String project, String task) { + TimesheetEntry userTimesheet = new TimesheetEntry(project, task); + database.add(userTimesheet); + } + + /** + * when called + * @return the list array of current timesheet entries + */ + public List list(boolean activeOnly, String name){ + if(activeOnly && (name != null)) { + List activeProjectDatabase = new ArrayList(); + for (TimesheetEntry e : database) { + LocalDateTime listEndTime = e.getEndTime(); + if(listEndTime == null && (e.getProjectName().equals(name))) { + activeProjectDatabase.add(e); + } + } + return activeProjectDatabase; + } else if(name != null) { + List projectDatabase = new ArrayList(); + for(TimesheetEntry e: database) { + if(e.getProjectName().equals(name)) { + projectDatabase.add(e); + } + } + return projectDatabase; + } else if(activeOnly) { + List activeDatabase = new ArrayList(); + for (TimesheetEntry e : database) { + LocalDateTime listEndTime = e.getEndTime(); + if(listEndTime == null) { + activeDatabase.add(e); + } + } + return activeDatabase; + } else { + return database; + } + + } + + /** + * method that will return timesheet entry from id entry + * @param id is given + * @return the timesheet entry for that id + */ + public TimesheetEntry get(int id) { + if(database.get(id-1) != null) { + return database.get(id-1); + } else + return null; + + } + + /** + * deletes a timesheetentry + * @param entry to delete + */ + public void delete(TimesheetEntry entry) { + int entryDelete = database.indexOf(entry); + database.remove(entryDelete); + } + + public void stop(TimesheetEntry entry) { + entry.updateEndTime(); + } +} diff --git a/TimesheetApp/src/TimesheetEntry.java b/TimesheetApp/src/TimesheetEntry.java new file mode 100644 index 0000000..36ec94d --- /dev/null +++ b/TimesheetApp/src/TimesheetEntry.java @@ -0,0 +1,91 @@ +import java.time.LocalDateTime; + +public class TimesheetEntry { + private String projectName; + private String task; + private int id; + private LocalDateTime startTime; + private LocalDateTime endTime; + + private static int NEXTID = 1; + + //constructor that initializes timesheet + public TimesheetEntry(String myProject, String myTask) { + this.projectName = myProject; + this.task = myTask; + this.startTime = LocalDateTime.now(); + this.id = NEXTID; + NEXTID++; + } + + //getters and setters + public String getProjectName() { + return projectName; + } + + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + public String getTask() { + return task; + } + + public void setTask(String task) { + this.task = task; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public LocalDateTime getStartTime() { + return startTime; + } + + public void setStartTime(LocalDateTime startTime) { + this.startTime = startTime; + } + + public LocalDateTime getEndTime() { + return endTime; + } + + public void setEndTime(LocalDateTime endTime) { + this.endTime = endTime; + } + + public static int getNEXTID() { + return NEXTID; + } + + public static void setNEXTID(int nEXTID) { + NEXTID = nEXTID; + } + + /* + * + */ + public void updateEndTime() { + try { + checkEndTime(endTime); + if(this.endTime == null) { + endTime = LocalDateTime.now(); + } + } catch (Exception e) { + System.out.println(e); + } + + } + + public static void checkEndTime (LocalDateTime dt) { + if(dt != null) { + throw new IllegalArgumentException("The task has already ended."); + } + } + +} diff --git a/ToDo App/.classpath b/ToDo App/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/ToDo App/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/ToDo App/.gitignore b/ToDo App/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/ToDo App/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/ToDo App/.project b/ToDo App/.project new file mode 100644 index 0000000..8470140 --- /dev/null +++ b/ToDo App/.project @@ -0,0 +1,17 @@ + + + ToDo App + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/ToDo App/.settings/org.eclipse.jdt.core.prefs b/ToDo App/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/ToDo App/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +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.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/ToDo App/src/ConsoleUtils.java b/ToDo App/src/ConsoleUtils.java new file mode 100644 index 0000000..6cfa3e9 --- /dev/null +++ b/ToDo App/src/ConsoleUtils.java @@ -0,0 +1,104 @@ +import java.time.format.DateTimeFormatter; +import java.util.List; +import java.util.Scanner; + +public class ConsoleUtils { + + /* Member variables */ + + private Scanner scanner; + private DateTimeFormatter timeFormatter; + + /* Constructor */ + + public ConsoleUtils(){ + scanner = new Scanner(System.in); + } + + /* Methods */ + + /* + * Prints the menu of actions to the console + */ + public void printHelp(){ + System.out.println("Valid commands: "); + System.out.println(" list [pending] list all items that are pending"); + System.out.println(" list [complete] list all items that are complete"); + System.out.println(" list list all itmes"); + System.out.println(" add add an entry, and set the start time"); + System.out.println(" complete update entry with the ID"); + System.out.println(" delete delete entry with the ID"); + System.out.println(" help display all available functions"); + System.out.println(" quit to exit"); + System.out.println(); + + } + + /* + * Prints an informational message to the console + */ + public void info(String msg){ + System.out.println("["+msg+"]"); + System.out.println(); + } + + /* + * Prints an error message to the console + */ + public void error(String msg){ + System.out.println("[ERROR: "+msg+"]"); + System.out.println(); + } + + /* + * Prompts the user to enter input + * Returns the text entered by the user + */ + public String promptString(String label){ + System.out.print(label+" "); + return scanner.nextLine(); + } + + /* + * Prints a list of TimesheetEntry objects in a pretty table + */ + public void printList(List items){ + int longestDesc = 11; + + for(ToDoItem item : items){ + if(item.getDescription().length() > longestDesc){ + longestDesc = item.getDescription().length(); + } + } + + String itemDescHeader = String.format("%"+longestDesc+"s", "Description"); + String projectUnderline = ""; + for(int i=0;i "); + String[] actionParts = input.split(" "); + String action = actionParts[0].trim(); // Primary action + + // Figure out what to do depending on the user's primary action + if (action.equals("add")) { + + processAddAction(); + + } else if (action.equals("delete")) { + + processDeleteAction(actionParts); + } else if (action.equals("complete")) { + + processUpdateAction(actionParts); + + } else if (action.equals("list")) { + + processListAction(actionParts); + + } else if (action.equals("quit")) { + + quit = true; + + } else if (action.equals("help")) { + + ConsoleUtils helper = new ConsoleUtils(); + helper.printHelp(); + + } else if(action.length() ==0 ){ + + // do nothing. + + } else { + + consoleUtils.error("Invalid action"); + + } + } + + } + /** + * takes ID and uses dao method to mark item as complete + * @param actionParts input user enters aka item id + */ + private void processUpdateAction(String[] actionParts) { + if(actionParts.length > 2){ + consoleUtils.error("Too many inputs to stop command"); + return; + } + + int id = 0; + + + boolean validID = false; + while(!validID) { + try { + id = Integer.parseInt(consoleUtils.promptString("Id to update:")); + checkIDExists(id); + validID = true; + dao.markComplete(dao.find(id)); + consoleUtils.info("item marked complete"); + + } catch (Exception e) { + consoleUtils.error("id does not exist"); + } + } + + } + + private void checkIDExists(int id) { + if(dao.find(id) == null) { + throw new IndexOutOfBoundsException(); + } + } + + /* + * The user wants to view a list of timesheet entries + * This method conveys that request to the Timesheet, + * along with any special options (active-only, filter by project name) + */ + public void processListAction(String[] actionParts){ + + if(actionParts.length > 5){ + consoleUtils.error("Too much stuff to do, just take the day off :)"); + return; + } else { + List item = new ArrayList(); + if(actionParts.length>1) { + if(actionParts[1].toLowerCase().equals("complete")) { + item = dao.listToDoItem(true); + consoleUtils.printList(item); + } else if (actionParts[1].toLowerCase().equals("pending")) { + System.out.println("hey"); + item = dao.listToDoItem(false); + consoleUtils.printList(item); + } + } else { + item = dao.listToDoItem(); + consoleUtils.printList(item); + } + + + } + + + } + + private void processDeleteAction(String[] actionParts) { + if(actionParts.length > 2){ + consoleUtils.error("Too many inputs to stop command"); + return; + } + + int id = 0; + + + boolean validID = false; + while(!validID) { + try { + id = Integer.parseInt(consoleUtils.promptString("Id to delete:")); + checkIDExists(id); + validID = true; + dao.deleteToDoItem(dao.find(id)); + consoleUtils.info("item deleted"); + + } catch (Exception e) { + consoleUtils.error("id does not exist"); + } + } + + } + + private void processAddAction() { + String description = consoleUtils.promptString("Description:"); + dao.addToDoItem(description); + consoleUtils.info("item added"); + } + + +} diff --git a/ToDo App/src/Dao.java b/ToDo App/src/Dao.java new file mode 100644 index 0000000..ddaa65f --- /dev/null +++ b/ToDo App/src/Dao.java @@ -0,0 +1,79 @@ +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +/* + * + * Create a class that drives all the updates to the database. This class is usually called a DAO (Data Access Object). The Dao.java class should have the following member variable: +For database Version 1, use an ArrayList to store the user's to-do items. +For database Version 2, store a Connection to the SQLite database file. + */ +public class Dao { + //declare database that is just array list + protected ArrayList database; + protected int idCount = 1;; + + //constructor to instantiate new database + public Dao() { + database = new ArrayList(); + } + + /** + * method that will return timesheet entry from id entry + * @param id is given + * @return the timesheet entry for that id + */ + public ToDoItem find(int id) { + if(database.get(id-1) != null) { + return database.get(id-1); + } else + return null; + + } + + //marks complete for a given todo item + public void markComplete(ToDoItem item) { + item.setCompletedFlag(true); + } + + //adds todo item to the database + public void addToDoItem(String desc) { + ToDoItem item = new ToDoItem(idCount, desc); + database.add(item); + idCount++; + } + + //delete todo object frorm database array + public void deleteToDoItem(ToDoItem item) { + int entryDelete = database.indexOf(item); + database.remove(entryDelete); + } + public List listToDoItem(){ + return database; + + } + //given pending true or false will show all pending todo items or all todo items + public List listToDoItem(boolean complete){ + //if given false, list items that are not completed, iscompletedflag = false + if(!complete) { + List pendingDatabase = new ArrayList(); + for (ToDoItem e : database) { + boolean completed = e.isCompletedFlag(); + if(!completed) { + pendingDatabase.add(e); + } + } + return pendingDatabase; + //else, return everything in database + } else { + List completeDatabase = new ArrayList(); + for (ToDoItem e : database) { + boolean completed = e.isCompletedFlag(); + if(completed) { + completeDatabase.add(e); + } + } + return completeDatabase; + } + } +} diff --git a/ToDo App/src/Main.java b/ToDo App/src/Main.java new file mode 100644 index 0000000..e6e23e3 --- /dev/null +++ b/ToDo App/src/Main.java @@ -0,0 +1,9 @@ + +public class Main { + public static void main(String[] args) { + + Controller menuActions = new Controller(); + + menuActions.start(); + } +} diff --git a/ToDo App/src/ToDoItem.java b/ToDo App/src/ToDoItem.java new file mode 100644 index 0000000..1582802 --- /dev/null +++ b/ToDo App/src/ToDoItem.java @@ -0,0 +1,43 @@ +/* + * id +description +completed flag + */ +public class ToDoItem { + protected int id; + protected String description; + protected boolean completedFlag; + + public ToDoItem(int id, String description) { + this.id = id; + this.description = description; + this.completedFlag = false; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public boolean isCompletedFlag() { + return completedFlag; + } + + public void setCompletedFlag(boolean completedFlag) { + this.completedFlag = completedFlag; + } + + + +} diff --git a/TryCatch/.classpath b/TryCatch/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/TryCatch/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/TryCatch/.gitignore b/TryCatch/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/TryCatch/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/TryCatch/.project b/TryCatch/.project new file mode 100644 index 0000000..4ec7e44 --- /dev/null +++ b/TryCatch/.project @@ -0,0 +1,17 @@ + + + TryCatch + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/TryCatch/.settings/org.eclipse.jdt.core.prefs b/TryCatch/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/TryCatch/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +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.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/TryCatch/src/TryCatch.java b/TryCatch/src/TryCatch.java new file mode 100644 index 0000000..b537ebf --- /dev/null +++ b/TryCatch/src/TryCatch.java @@ -0,0 +1,97 @@ +/*ur program should: + +Should meet all the requirements of the previous Rock Paper Scissors assignment. +This implementation should make of use to the try catch mechanism to capture and handle incorrect user input. +Guidelines: + +The method that accepts input from the user should throw an exception if the user enters invalid input. +The calling method should use a try/catch block to handle the bad input and print a nice message to the user. +*/ +import java.util.Random; +import java.util.Scanner; + +public class TryCatch { + public static void main(String[] args) { + + System.out.println("Rock Paper Scissors, make your pick"); + + String yourHand = yourHand(); + String computerHand = generateHand(); + + System.out.println("You: " + yourHand); + System.out.println("Opponent: " + computerHand); + + String winningMove = winningMoves(yourHand, computerHand); + + if (yourHand.toLowerCase().equals(winningMove)) { + System.out.println("You won!"); + } else if (winningMove.contentEquals(computerHand.toLowerCase())) { + System.out.println("Womp, womp. The computer won."); + } else if (winningMove == "Tie"){ + System.out.println("It was a tie. Play again!"); + } + + + } + + public static void checkUserInput (String s) { + if(!(s.toLowerCase().equals("rock") || s.toLowerCase().equals("paper") || s.toLowerCase().equals("scissors"))) { + throw new IllegalArgumentException(); + } + } + + public static String yourHand() { + Scanner reader = new Scanner(System.in); + String yourPick = ""; + + boolean validPick = true; + while(validPick) { + try { + yourPick = reader.nextLine(); + checkUserInput(yourPick); + validPick = false; + + } catch (Exception e) { + System.out.println("Program is throwing an exception: " + e); + System.out.println("Please enter a valid move: Rock, Paper, or Scissors."); + } + } + + reader.close(); + return yourPick; + } + + public static String generateHand() { + Random randNumGen = new Random(); + int compNum = randNumGen.nextInt(3); + String compHand; + + if (compNum == 0) { + compHand = "Rock"; + } else if (compNum == 1) { + compHand = "Paper"; + } else { + compHand = "Scissors"; + } + + return compHand; + } + + public static String winningMoves(String pickOne, String pickTwo) { + if (pickOne.toLowerCase().equals(pickTwo.toLowerCase())) { + return "Tie"; + } + else if ((pickOne.toLowerCase().equals("rock") || pickTwo.toLowerCase().equals("rock")) && (pickOne.toLowerCase().equals("scissors") || pickTwo.toLowerCase().equals("scissors"))) { + return "rock"; + } + else if ((pickOne.toLowerCase().equals("rock") || pickTwo.toLowerCase().equals("rock")) && (pickOne.toLowerCase().equals("paper") || pickTwo.toLowerCase().equals("paper"))) { + return "paper"; + } + else if ((pickOne.toLowerCase().equals("paper") || pickTwo.toLowerCase().equals("paper")) && (pickOne.toLowerCase().equals("scissors") || pickTwo.toLowerCase().equals("scissors"))) { + return "scissors"; + } else { + return "Invalid"; + } + + } +} diff --git a/Vehicle/.classpath b/Vehicle/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/Vehicle/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Vehicle/.gitignore b/Vehicle/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/Vehicle/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/Vehicle/.project b/Vehicle/.project new file mode 100644 index 0000000..e7de825 --- /dev/null +++ b/Vehicle/.project @@ -0,0 +1,17 @@ + + + Vehicle + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Vehicle/.settings/org.eclipse.jdt.core.prefs b/Vehicle/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/Vehicle/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +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.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/WordGuess/.classpath b/WordGuess/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/WordGuess/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/WordGuess/.gitignore b/WordGuess/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/WordGuess/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/WordGuess/.project b/WordGuess/.project new file mode 100644 index 0000000..5ebc43e --- /dev/null +++ b/WordGuess/.project @@ -0,0 +1,17 @@ + + + WordGuess + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/WordGuess/.settings/org.eclipse.jdt.core.prefs b/WordGuess/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/WordGuess/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +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.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/WordGuess/src/WordGuessGame.java b/WordGuess/src/WordGuessGame.java new file mode 100644 index 0000000..b25cea2 --- /dev/null +++ b/WordGuess/src/WordGuessGame.java @@ -0,0 +1,169 @@ +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Random; +import java.util.Scanner; + +public class WordGuessGame { + static String wordProgress = ""; + static String word = generateWord(); + + public static void main(String[] args) { + //prints initial word, should show as hidden + printWordProgress(); + + //prompt user to enter letter + System.out.println("Choose a lower-case letter."); + Scanner reader = new Scanner(System.in); + String chosenLetter = ""; + + + //keep prompting until user enters valid letter + //program will run until word is complete + while(!wordComplete()) { + boolean isLetter = false; + while(!isLetter) { + try { + chosenLetter = reader.nextLine(); + checkUserInput(chosenLetter); + isLetter = true; + //catch if user doesn't enter letter + } catch (IllegalArgumentException e) { + System.out.println("Please enter a letter."); + //catch if user enters same letter + } catch (IllegalStateException e) { + System.out.println("You've already entered that letter."); + } + } + playTurn(chosenLetter); + + } + + reader.close(); + + + } + + /** + * method run. tests letter + * @param chosenLetter given to test + */ + private static void playTurn(CharSequence chosenLetter) { + //check if word contains the letter + if(word.contains(chosenLetter)) { + System.out.println("you guessed right!"); + //loop through word + for(int i=0; i