commit e168d9d8dbab9cf3cda3c6c812365ffef6eb4596 Author: Logen Kain Date: Wed Nov 11 08:47:37 2020 -0500 init diff --git a/Week-11-final-start/part-1/ItemToPurchase.java b/Week-11-final-start/part-1/ItemToPurchase.java new file mode 100644 index 0000000..b942554 --- /dev/null +++ b/Week-11-final-start/part-1/ItemToPurchase.java @@ -0,0 +1,13 @@ +/* + * Following Specs: + * Init in default constructor: + * + * String itemName -- init to none + * int itemPrice - init to 0 + * int itemQuanity - init to 0 + * + * Public member mothods (mutators & accessors) + * setName() & getName() + * setPrice() & getPrice() + * setQuantity() & getQuantity() + */ diff --git a/Week-11-final-start/part-1/ShoppingCartPrinter.java b/Week-11-final-start/part-1/ShoppingCartPrinter.java new file mode 100644 index 0000000..02466f7 --- /dev/null +++ b/Week-11-final-start/part-1/ShoppingCartPrinter.java @@ -0,0 +1,41 @@ +/* + In main, ask the user for two items and create two objects of the + ItemToPurchase class. + + Before asking for the second item, call scnr.nextLine() + to allow the user to put in a new string. + +Example: +Item 1 +Enter the item name: +Chocolate Chips +Enter the item price: +3 +Enter the item quantity: +1 + +Item 2 +Enter the item name: +Bottled Water +Enter the item price: +1 +Enter the item quantity: +10 + Then add the costs of teh two items together and output + the total cost + +Example: +TOTAL COST +Chocolate Chips 1 @ $3 = $3 +Bottled Water 10 @ $1 = $10 + +Total: $13 +*/ + +import java.util.Scanner; + +public class ShoppingCartPrinter { + public static void main(String[] args) { + Scanner scnr = new Scanner(System.in); + } +} diff --git a/brute-force/main.java b/brute-force/main.java new file mode 100644 index 0000000..b3fead4 --- /dev/null +++ b/brute-force/main.java @@ -0,0 +1,36 @@ +import java.util.Scanner; + +public class LabProgram { + public static void main(String[] args) { + /* Type your code here. */ + Scanner scnr = new Scanner(System.in); + + int eq1Co1, eq1Co2, eq1Sol, eq2Co1, eq2Co2, eq2Sol; + int xSol, ySol; + boolean sol = false; + + eq1Co1 = scnr.nextInt(); + eq1Co2 = scnr.nextInt(); + eq1Sol = scnr.nextInt(); + eq2Co1 = scnr.nextInt(); + eq2Co2 = scnr.nextInt(); + eq2Sol = scnr.nextInt(); + + int x, y; + + for(x= -10; x<10; x++){ + if (sol==true){break;} + for(y= -10; y<10; y++){ + if ( ((x*eq1Co1) + (y*eq1Co2) == eq1Sol) && ((x*eq2Co1) + (y*eq2Co2) == eq2Sol)){ + xSol = x; + ySol = y; + System.out.println(""+xSol+" "+ySol); + sol=true; + } + } + } + if (sol==false){ + System.out.println("No solution"); + } + } +} diff --git a/brute-force/test.java b/brute-force/test.java new file mode 100644 index 0000000..439e503 --- /dev/null +++ b/brute-force/test.java @@ -0,0 +1,14 @@ +import java.util.Scanner; + +public class LabProgram { + public static void main(String[] args) { + /* Type your code here. */ + Scanner scnr = new Scanner(System.in); + int x; +int z = 0; +x = scnr.nextInt(); +if (x > 9) + z = 3; + z = z + 1; +System.out.print(z); + }} diff --git a/contians-character/LabProgram.java b/contians-character/LabProgram.java new file mode 100644 index 0000000..5fd4d75 --- /dev/null +++ b/contians-character/LabProgram.java @@ -0,0 +1,50 @@ +/* Joseph Green + * 7-Oct-2020 + * + * take int for number of words + * take list of words + * take a char + * + * print out every word in the list that contains the char at least once + * Assume at least one word will contain the given char + * words will be < 20 + */ + +import java.util.Scanner; + +public class LabProgram { + public static void main(String[] args) { + /* Type your code here. */ + int numWords; + char someChar; + Scanner scnr = new Scanner(System.in); + + String[] words = new String[20]; + + numWords = scnr.nextInt(); + + for (int i = 0; i= min && ints[i] <= max){ + System.out.print(ints[i] + " "); + } + } + System.out.println(); + } +} diff --git a/lab-10/10.13.1-Nutritional-Information/FoodItem.java b/lab-10/10.13.1-Nutritional-Information/FoodItem.java new file mode 100644 index 0000000..e54df98 --- /dev/null +++ b/lab-10/10.13.1-Nutritional-Information/FoodItem.java @@ -0,0 +1,52 @@ +public class FoodItem { + private String name; + private double fat; + private double carbs; + private double protein; + + // TODO: Define default constructor + public FoodItem() { + name = "None"; + fat = 0.0; + carbs = 0.0; + protein = 0.0; + } + + // TODO: Define second constructor with arguments to initialize + // private fields (name, fat, carbs, protein) + public FoodItem (String name, double fat, double carbs, double protein){ + this.name = name; + this.fat = fat; + this.carbs = carbs; + this.protein = protein; + } + + public String getName() { + return name; + } + + public double getFat() { + return fat; + } + + public double getCarbs() { + return carbs; + } + + public double getProtein() { + return protein; + } + + public double getCalories(double numServings) { + // Calorie formula + double calories = ((fat * 9) + (carbs * 4) + (protein * 4)) * numServings; + return calories; + } + + public void printInfo() { + System.out.println("Nutritional information per serving of " + name + ":"); + System.out.printf(" Fat: %.2f g\n", fat); + System.out.printf(" Carbohydrates: %.2f g\n", carbs); + System.out.printf(" Protein: %.2f g\n", protein); + } +} diff --git a/lab-10/10.13.1-Nutritional-Information/NutritionalInfo.java b/lab-10/10.13.1-Nutritional-Information/NutritionalInfo.java new file mode 100644 index 0000000..1d2944e --- /dev/null +++ b/lab-10/10.13.1-Nutritional-Information/NutritionalInfo.java @@ -0,0 +1,28 @@ +import java.util.Scanner; + +public class NutritionalInfo { + public static void main(String[] args) { + Scanner scnr = new Scanner(System.in); + + FoodItem foodItem1 = new FoodItem(); + + String itemName = scnr.next(); + double amountFat = scnr.nextDouble(); + double amountCarbs = scnr.nextDouble(); + double amountProtein = scnr.nextDouble(); + + FoodItem foodItem2 = new FoodItem(itemName, amountFat, amountCarbs, amountProtein); + + double numServings = scnr.nextDouble(); + + foodItem1.printInfo(); + System.out.printf("Number of calories for %.2f serving(s): %.2f\n", numServings, + foodItem1.getCalories(numServings)); + + System.out.println("\n"); + + foodItem2.printInfo(); + System.out.printf("Number of calories for %.2f serving(s): %.2f\n", numServings, + foodItem2.getCalories(numServings)); + } +} diff --git a/lab-8/8.33.1-turn-exp/LabProgram.java b/lab-8/8.33.1-turn-exp/LabProgram.java new file mode 100644 index 0000000..45b9395 --- /dev/null +++ b/lab-8/8.33.1-turn-exp/LabProgram.java @@ -0,0 +1,29 @@ +import java.util.Scanner; + +public class LabProgram { + + /* Define your method here */ + public static int largestNumber(int num1, int num2, int num3){ + int largest = num1; + largest = (largest < num2) ? num2:largest; + largest = (largest < num3) ? num3:largest; + return largest; + } + public static int smallestNumber(int num1, int num2, int num3){ + int smallest = num1; + smallest = (smallest > num2) ? num2:smallest; + smallest = (smallest > num3) ? num3:smallest; + return smallest; + } + + + public static void main(String[] args) { + Scanner scnr = new Scanner(System.in); + int num1, num2, num3; + num1 = scnr.nextInt(); + num2 = scnr.nextInt(); + num3 = scnr.nextInt(); + System.out.println("largest: " + largestNumber(num1,num2,num3)); + System.out.println("smallest: " + smallestNumber(num1,num2,num3)); + } +} diff --git a/lab-8/8.37-even-odd-in-array/LabProgram.java b/lab-8/8.37-even-odd-in-array/LabProgram.java new file mode 100644 index 0000000..fdb0053 --- /dev/null +++ b/lab-8/8.37-even-odd-in-array/LabProgram.java @@ -0,0 +1,41 @@ +import java.util.Scanner; + +public class LabProgram { + + public static boolean isArrayEven(int[] arrayValues, int arraySize){ + for (int i = 0; i myArr[j+1]){ + temp = myArr[j]; + myArr[j] = myArr[j+1]; + myArr[j+1] = temp; + flag = 1; + } + } + if (flag == 0){ + break; + } + } + } + public static void main(String[] args) { + Scanner scnr = new Scanner(System.in); + int[] myInts = new int[20]; + int myIntsLength = scnr.nextInt(); + for (int i=0;i < myIntsLength;i++){ + myInts[i] = scnr.nextInt(); + } + + sortArray(myInts, myIntsLength); + + for(int i=0; i= 0.5) { + System.out.println("Congratulations, Team " + team.getTeamName() + + " has a winning average!"); + } + else { + System.out.println("Team " + team.getTeamName() + + " has a losing average."); + } + } +} + diff --git a/lab-9/triangle-area/Triangle.class b/lab-9/triangle-area/Triangle.class new file mode 100644 index 0000000..47e42e2 Binary files /dev/null and b/lab-9/triangle-area/Triangle.class differ diff --git a/lab-9/triangle-area/Triangle.java b/lab-9/triangle-area/Triangle.java new file mode 100644 index 0000000..9fe54c7 --- /dev/null +++ b/lab-9/triangle-area/Triangle.java @@ -0,0 +1,22 @@ +public class Triangle { + private double base; + private double height; + + public void setBase(double userBase){ + base = userBase; + } + public void setHeight(double userHeight) { + height = userHeight; + } + + public double getArea() { + double area = 0.5 * base * height; + return area; + } + + public void printInfo() { + System.out.printf("Base: %.2f\n", base); + System.out.printf("Height: %.2f\n", height); + System.out.printf("Area: %.2f\n", getArea()); + } +} diff --git a/lab-9/triangle-area/TriangleArea.java b/lab-9/triangle-area/TriangleArea.java new file mode 100644 index 0000000..76cf7ae --- /dev/null +++ b/lab-9/triangle-area/TriangleArea.java @@ -0,0 +1,28 @@ +import java.util.Scanner; + +public class TriangleArea { + public static void main(String[] args) { + Scanner scnr = new Scanner(System.in); + + Triangle triangle1 = new Triangle(); + Triangle triangle2 = new Triangle(); + + // TODO: Read and set base and height for triangle1 (use setBase() and setHeight()) + triangle1.setBase(scnr.nextDouble()); + triangle1.setHeight(scnr.nextDouble()); + + // TODO: Read and set base and height for triangle2 (use setBase() and setHeight()) + triangle2.setBase(scnr.nextDouble()); + triangle2.setHeight(scnr.nextDouble()); + + // TODO: Determine larger triangle (use getArea()) + Triangle largest = (triangle1.getArea() > triangle2.getArea()) ? triangle1:triangle2; + + + System.out.println("Triangle with larger area:"); + // TODO: Output larger triangle's info (use printInfo()) + largest.printInfo(); + + } +} + diff --git a/output-numbers-in-reverse/main.java b/output-numbers-in-reverse/main.java new file mode 100644 index 0000000..e8982c9 --- /dev/null +++ b/output-numbers-in-reverse/main.java @@ -0,0 +1,23 @@ +import java.util.Scanner; + +public class LabProgram { + public static void main(String[] args) { + Scanner scnr = new Scanner(System.in); + int[] userList = new int[20]; // List of numElement integers specified by the user + int numElements; // Number of integers in user's list + // Add more variables as needed + int i; + numElements = scnr.nextInt(); // Input begins with number of integers that follow + + /* Type your code here. */ + + for (i =0; i-1; i--){ + System.out.print(userList[i] + " "); + } + System.out.println(); + } +} diff --git a/word-frequencies/LabProgram.java b/word-frequencies/LabProgram.java new file mode 100644 index 0000000..e936c44 --- /dev/null +++ b/word-frequencies/LabProgram.java @@ -0,0 +1,40 @@ +/* Joseph Green + * 07-Oct-2020 + * + * Read int that indicates list of words to follow + * Read in that many of words + * assume list will always contain less than 20 words + */ + +import java.util.Scanner; + +public class LabProgram { + public static void main(String[] args) { + /* Type your code here. */ + + Scanner scnr = new Scanner(System.in); + + int numOfWords; + int i; + + String[] listOfWords = new String[20]; + int[] frequency = new int[20]; + + numOfWords = scnr.nextInt(); + + for (i=0; i