diff --git a/classes-part-2/exercises/src/main/java/org/launchcode/Course.java b/classes-part-2/exercises/src/main/java/org/launchcode/Course.java index ca56bd799..e717fb234 100644 --- a/classes-part-2/exercises/src/main/java/org/launchcode/Course.java +++ b/classes-part-2/exercises/src/main/java/org/launchcode/Course.java @@ -15,3 +15,4 @@ public class Course { // Course objects equal. } + diff --git a/classes-part-2/exercises/src/main/java/org/launchcode/Student.java b/classes-part-2/exercises/src/main/java/org/launchcode/Student.java index 7e368e66e..b95afa0fb 100644 --- a/classes-part-2/exercises/src/main/java/org/launchcode/Student.java +++ b/classes-part-2/exercises/src/main/java/org/launchcode/Student.java @@ -30,13 +30,31 @@ public String studentInfo() { //TODO: Uncomment and complete the getGradeLevel method here: -// public String getGradeLevel() { + public String getGradeLevel() { + public static String getGradeLevel(int credits) { + if (credits <= 29){ + return "freshman"; + } else if (credits <= 59){ + return "sophomore"; + } else if (credits <= 89) { + return "junior"; + } else { + return "senior"; + } + } + } // // Determine the grade level of the student based on numberOfCredits // } // TODO: Complete the addGrade method. public void addGrade(int courseCredits, double grade) { // Update the appropriate fields: numberOfCredits, gpa + public void addGrade(int courseCredits, double grade) { + double totalQualityScore = this.gpa * this.numberOfCredits; + totalQualityScore += courseCredits * grade; + this.numberOfCredits += courseCredits; + this.gpa = totalQualityScore/this.numberOfCredits; + } } // TODO: Add your custom 'toString' method here. Make sure it returns a well-formatted String rather @@ -44,6 +62,28 @@ public void addGrade(int courseCredits, double grade) { // TODO: Add your custom 'equals' method here. Consider which fields should match in order to call two // Student objects equal. + public String toString() { + + String studentReport = String.format("%s is a %s with %d credits and a GPA of %.2f", this.name, this.getGradeLevel(this.numberOfCredits), this.getNumberOfCredits(), this.getGpa()); + return studentReport; + } + + public boolean equals(Object toBeCompared) { + if (toBeCompared == this) { + return true; + } + + if (toBeCompared == null) { + return false; + } + + if (toBeCompared.getClass() != getClass()) { + return false; + } + + Student theStudent = (Student) toBeCompared; + return theStudent.getStudentId() == getStudentId(); + } public String getName() { return name; diff --git a/classes-part-one/exercises/src/main/java/Student.java b/classes-part-one/exercises/src/main/java/Student.java index d06997866..56860db01 100644 --- a/classes-part-one/exercises/src/main/java/Student.java +++ b/classes-part-one/exercises/src/main/java/Student.java @@ -7,4 +7,41 @@ public class Student { // Drop your getters and setters below for the Student class. // To instantiate the Student class, add your code to the main in the file, SchoolPractice. + public void setName(String name) { + this.name = name; + } + + public void setStudentId(int studentId) { + this.studentId = studentId; + } + + public void setGpa(double gpa) { + this.gpa = gpa; + } + + private void setNumberOfCredits(int numberOfCredits) { + this.numberOfCredits = numberOfCredits; + } + + public String getName() { + return name; + } + + public int getStudentId() { + return studentId; + } + + public int getNumberOfCredits() { + return numberOfCredits; + } + + public double getGpa() { + return gpa; + } + Student student = new Student("Your Name", 12345, 1, 4.0); + public class Course { + private String topic; + private Teacher instructor; + private ArrayList enrolledStudents; + } } diff --git a/classes-part-one/exercises/src/main/java/Teacher.java b/classes-part-one/exercises/src/main/java/Teacher.java new file mode 100644 index 000000000..dc7b0a609 --- /dev/null +++ b/classes-part-one/exercises/src/main/java/Teacher.java @@ -0,0 +1,47 @@ +public class Teacher { + + + private String firstname; + private String lastname; + private String subject; + private String yearsTeaching; + + public static void main(String[] args) { + + } + + public String getFirstname() { + return firstname; + } + + public void setFirstname(String firstname) { + this.firstname = firstname; + } + + public String getLastname() { + return lastname; + } + + public void setLastname(String lastname) { + this.lastname = lastname; + } + + + public String subject () { + return subject; + } + + public void setsubject(String subject) { + this.subject = subject; + } + + public String yearsTeaching () { + return yearsTeaching; + } + + public void setyearsTeaching(String yearsTeaching) { + this.yearsTeaching = yearsTeaching; + } + } + + diff --git a/classes-part-one/studio/restaurant-menu/src/main/java/org/launchcode/Main.java b/classes-part-one/studio/restaurant-menu/src/main/java/org/launchcode/Main.java index cad5849f1..930d3994c 100644 --- a/classes-part-one/studio/restaurant-menu/src/main/java/org/launchcode/Main.java +++ b/classes-part-one/studio/restaurant-menu/src/main/java/org/launchcode/Main.java @@ -2,7 +2,24 @@ public class Main { - public static void main(String[] args) { + public static void main(String[] args) { // write your code here + MItems dessert = new MItems("ApplePie", 4.99 , "Dessert", true); + MItems mCourse = new MItems("Pasta", 10.99 ,"mainCourse", true); + MItems starter = new MItems("AvocadoTaco", 9.99 , "appetizer", true); + + dessert.setDescription("Made out of apples"); + starter.setDescription("Made out of avocados"); + mCourse.setDescription("Made out of cheese and sauce"); + + + + } + } + + + + + diff --git a/classes-part-one/studio/restaurant-menu/src/main/java/org/launchcode/Menu.java b/classes-part-one/studio/restaurant-menu/src/main/java/org/launchcode/Menu.java new file mode 100644 index 000000000..4b1de25d9 --- /dev/null +++ b/classes-part-one/studio/restaurant-menu/src/main/java/org/launchcode/Menu.java @@ -0,0 +1,28 @@ +package org.launchcode; + +public class Menu2 { + private Date lastUpdated; + private ArrayList MItems ; + + public Menu2(Date lastUpdated, ArrayList MItems) { + this.lastUpdated = lastUpdated; + this.MItems = MItems; + this.lastUpdated = new Date(); + } + + public Date getLastUpdated() { + return lastUpdated; + } + + public ArrayList getMItems() { + return MItems; + } + + public void setLastUpdated(Date lastUpdated) { + this.lastUpdated = lastUpdated; + } + + public void setMItems(ArrayList MItems) { + this.MItems = MItems; + } +} \ No newline at end of file diff --git a/classes-part-one/studio/restaurant-menu/src/main/java/org/launchcode/MenuItem.java b/classes-part-one/studio/restaurant-menu/src/main/java/org/launchcode/MenuItem.java new file mode 100644 index 000000000..4264768f1 --- /dev/null +++ b/classes-part-one/studio/restaurant-menu/src/main/java/org/launchcode/MenuItem.java @@ -0,0 +1,57 @@ +package org.launchcode; + +public class MItems { + private String itemName; + private double price; + private String description; + private String category; + private boolean isItNew; + + public MItems(String itemName, double price, String category, boolean isItNew) { + this.itemName = itemName; + this.price = price; + this.category = category; + this.isItNew = isItNew; + } + + + public String getItemName() { + return itemName; + } + + public double getPrice() { + return price; + } + + public String getDescription() { + return description; + } + + public String getCategory() { + return category; + } + + public boolean isItNew() { + return isItNew; + } + + public void setItemName(String itemName) { + this.itemName = itemName; + } + + public void setPrice(double price) { + this.price = price; + } + + public void setDescription(String description) { + this.description = description; + } + + public void setCategory(String category) { + this.category = category; + } + + public void setItNew(boolean itNew) { + isItNew = itNew; + } +} \ No newline at end of file diff --git a/control-flow-and-collections/chapter-example/student-example/src/main/java/org/launchcode/out/production/launchcode/org/launchcode/ArrayGradebook.class b/control-flow-and-collections/chapter-example/student-example/src/main/java/org/launchcode/out/production/launchcode/org/launchcode/ArrayGradebook.class new file mode 100644 index 000000000..d8a1901e2 Binary files /dev/null and b/control-flow-and-collections/chapter-example/student-example/src/main/java/org/launchcode/out/production/launchcode/org/launchcode/ArrayGradebook.class differ diff --git a/control-flow-and-collections/chapter-example/student-example/src/main/java/org/launchcode/out/production/launchcode/org/launchcode/ArrayListGradebook.class b/control-flow-and-collections/chapter-example/student-example/src/main/java/org/launchcode/out/production/launchcode/org/launchcode/ArrayListGradebook.class new file mode 100644 index 000000000..8c79590e4 Binary files /dev/null and b/control-flow-and-collections/chapter-example/student-example/src/main/java/org/launchcode/out/production/launchcode/org/launchcode/ArrayListGradebook.class differ diff --git a/control-flow-and-collections/chapter-example/student-example/src/main/java/org/launchcode/out/production/launchcode/org/launchcode/HashMapGradebook.class b/control-flow-and-collections/chapter-example/student-example/src/main/java/org/launchcode/out/production/launchcode/org/launchcode/HashMapGradebook.class new file mode 100644 index 000000000..73b311353 Binary files /dev/null and b/control-flow-and-collections/chapter-example/student-example/src/main/java/org/launchcode/out/production/launchcode/org/launchcode/HashMapGradebook.class differ diff --git a/control-flow-and-collections/exercises/collections-exercises/.gitignore b/control-flow-and-collections/exercises/collections-exercises/.gitignore new file mode 100644 index 000000000..5ff6309b7 --- /dev/null +++ b/control-flow-and-collections/exercises/collections-exercises/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/control-flow-and-collections/exercises/collections-exercises/pom.xml b/control-flow-and-collections/exercises/collections-exercises/pom.xml new file mode 100644 index 000000000..eaee8bc3a --- /dev/null +++ b/control-flow-and-collections/exercises/collections-exercises/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + org.example + collections-exercises + 1.0-SNAPSHOT + + + 17 + 17 + UTF-8 + + + \ No newline at end of file diff --git a/control-flow-and-collections/exercises/collections-exercises/src/main/java/ArrayExercise.java b/control-flow-and-collections/exercises/collections-exercises/src/main/java/ArrayExercise.java new file mode 100644 index 000000000..ced103aa5 --- /dev/null +++ b/control-flow-and-collections/exercises/collections-exercises/src/main/java/ArrayExercise.java @@ -0,0 +1,2 @@ +package PACKAGE_NAME;public class ArrayExercise { +} diff --git a/control-flow-and-collections/exercises/collections-exercises/src/main/java/org/example/Main.java b/control-flow-and-collections/exercises/collections-exercises/src/main/java/org/example/Main.java new file mode 100644 index 000000000..09efe28fe --- /dev/null +++ b/control-flow-and-collections/exercises/collections-exercises/src/main/java/org/example/Main.java @@ -0,0 +1,19 @@ +package org.example; + +// Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`, +// then press Enter. You can now see whitespace characters in your code. +public class Main { + public static void main(String[] args) { + // Press Opt+Enter with your caret at the highlighted text to see how + // IntelliJ IDEA suggests fixing it. + System.out.printf("Hello and welcome!"); + + // Press Ctrl+R or click the green arrow button in the gutter to run the code. + for (int i = 1; i <= 5; i++) { + + // Press Ctrl+D to start debugging your code. We have set one breakpoint + // for you, but you can always add more by pressing Cmd+F8. + System.out.println("i = " + i); + } + } +} \ No newline at end of file diff --git a/control-flow-and-collections/studio/counting-characters/.gitignore b/control-flow-and-collections/studio/counting-characters/.gitignore new file mode 100644 index 000000000..5ff6309b7 --- /dev/null +++ b/control-flow-and-collections/studio/counting-characters/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/control-flow-and-collections/studio/counting-characters/pom.xml b/control-flow-and-collections/studio/counting-characters/pom.xml new file mode 100644 index 000000000..792c4d470 --- /dev/null +++ b/control-flow-and-collections/studio/counting-characters/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + org.example + counting-characters + 1.0-SNAPSHOT + + + 17 + 17 + UTF-8 + + + \ No newline at end of file diff --git a/control-flow-and-collections/studio/counting-characters/src/main/java/org/example/Main.java b/control-flow-and-collections/studio/counting-characters/src/main/java/org/example/Main.java new file mode 100644 index 000000000..919f575a9 --- /dev/null +++ b/control-flow-and-collections/studio/counting-characters/src/main/java/org/example/Main.java @@ -0,0 +1,37 @@ +char[] charactersInString = myString.toUpperCase().toCharArray(); +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; + +public class CountingCharacters { + + public static void main(String[] args){ + + Scanner scanner = new Scanner(System.in); + System.out.println("Please enter $$ if you want a file or enter a string to count: "); + + + String input = scanner.nextLine(); + scanner.close(); + + if (input == "$$"){ + Scanner scans = new Scanner(filePath); + } else { + input = "If the product of two terms is zero then common sense says at least one of the two terms has to be zero to start with. " + + "So if you move all the terms over to one side, you can put the quadratics into a form that can be factored allowing that side of the equation to equal zero." + + " Once you've done that, it's pretty straightforward from there."; + + String myString = input + } + + HashMap chars = new HashMap<>(); + + for(int i = 0; i < charactersInString.length; i++){ + chars.put(charactersInString[i], chars.getOrDefault(charactersInString[i], 0) + 1); + } + + for (Map.Entry letter : chars.entrySet()) { + System.out.println(letter.getKey() + " :" + letter.getValue()); + } + } +} \ No newline at end of file diff --git a/control-flow-and-collections/studio/counting-characters1/counting-characters1/.gitignore b/control-flow-and-collections/studio/counting-characters1/counting-characters1/.gitignore new file mode 100644 index 000000000..5ff6309b7 --- /dev/null +++ b/control-flow-and-collections/studio/counting-characters1/counting-characters1/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/control-flow-and-collections/studio/counting-characters1/counting-characters1/pom.xml b/control-flow-and-collections/studio/counting-characters1/counting-characters1/pom.xml new file mode 100644 index 000000000..2704f3cec --- /dev/null +++ b/control-flow-and-collections/studio/counting-characters1/counting-characters1/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + org.example + counting-characters1 + 1.0-SNAPSHOT + + + 17 + 17 + UTF-8 + + + \ No newline at end of file diff --git a/control-flow-and-collections/studio/counting-characters1/counting-characters1/src/main/java/org/example/Main.java b/control-flow-and-collections/studio/counting-characters1/counting-characters1/src/main/java/org/example/Main.java new file mode 100644 index 000000000..bcd864b72 --- /dev/null +++ b/control-flow-and-collections/studio/counting-characters1/counting-characters1/src/main/java/org/example/Main.java @@ -0,0 +1,42 @@ +package org.example; + +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; + +// Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`, +// then press Enter. You can now see whitespace characters in your code. +public class Main { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + System.out.println("Please enter $$ if you want a file or enter a string to count: "); + + + String input = scanner.nextLine(); + scanner.close(); + + char[] charactersInString = new char[0]; + if (input == "$$") { + System.out.println("Filepath"); + // Scanner scans = new Scanner(filePath); + } else { + input = "If the product of two terms is zero then common sense says at least one of the two terms has to be zero to start with. " + + "So if you move all the terms over to one side, you can put the quadratics into a form that can be factored allowing that side of the equation to equal zero." + + " Once you've done that, it's pretty straightforward from there."; + + String myString = input; + charactersInString = myString.toUpperCase().toCharArray(); + } + + HashMap chars = new HashMap<>(); + + for (int i = 0; i < charactersInString.length; i++) { + chars.put(charactersInString[i], chars.getOrDefault(charactersInString[i], 0) + 1); + } + + for (Map.Entry letter : chars.entrySet()) { + System.out.println(letter.getKey() + " :" + letter.getValue()); + } + + } +} \ No newline at end of file diff --git a/control-flow-and-collections/unnamed.patch b/control-flow-and-collections/unnamed.patch new file mode 100644 index 000000000..ccd8f89ee --- /dev/null +++ b/control-flow-and-collections/unnamed.patch @@ -0,0 +1,49 @@ +Index: control-flow-and-collections/studio/counting-characters/.gitignore +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +diff --git a/control-flow-and-collections/studio/counting-characters/.gitignore b/control-flow-and-collections/studio/counting-characters/.gitignore +new file mode 100644 +--- /dev/null (revision 9fb2a8efeb08f99a7c98a30b4dc78eb66c59e770) ++++ b/control-flow-and-collections/studio/counting-characters/.gitignore (revision 9fb2a8efeb08f99a7c98a30b4dc78eb66c59e770) +@@ -0,0 +1,38 @@ ++target/ ++!.mvn/wrapper/maven-wrapper.jar ++!**/src/main/**/target/ ++!**/src/test/**/target/ ++ ++### IntelliJ IDEA ### ++.idea/modules.xml ++.idea/jarRepositories.xml ++.idea/compiler.xml ++.idea/libraries/ ++*.iws ++*.iml ++*.ipr ++ ++### Eclipse ### ++.apt_generated ++.classpath ++.factorypath ++.project ++.settings ++.springBeans ++.sts4-cache ++ ++### NetBeans ### ++/nbproject/private/ ++/nbbuild/ ++/dist/ ++/nbdist/ ++/.nb-gradle/ ++build/ ++!**/src/main/**/build/ ++!**/src/test/**/build/ ++ ++### VS Code ### ++.vscode/ ++ ++### Mac OS ### ++.DS_Store +\ No newline at end of file diff --git a/datatypes/datatype-examples/src/main/java/org/launchcode/TempConverter.java b/datatypes/datatype-examples/src/main/java/org/launchcode/TempConverter.java index d09ac901d..9944f7a79 100644 --- a/datatypes/datatype-examples/src/main/java/org/launchcode/TempConverter.java +++ b/datatypes/datatype-examples/src/main/java/org/launchcode/TempConverter.java @@ -2,18 +2,24 @@ import java.util.Scanner; + public class TempConverter { public static void main(String[] args) { double fahrenheit; - double celsius; + Double celsius; + String Megha; + // double input; Scanner input; input = new Scanner(System.in); System.out.println("Enter the temperature in Fahrenheit: "); fahrenheit = input.nextDouble(); + // fahrenheit = input; input.close(); celsius = (fahrenheit - 32) * 5/9; + Megha = celsius.toString(); + System.out.println(Megha); System.out.println("The temperature in Celsius is: " + celsius + "°C"); } } diff --git a/datatypes/datatypes-studio/src/main/Java/org/launchcode/Area.java b/datatypes/datatypes-studio/src/main/Java/org/launchcode/Area.java new file mode 100644 index 000000000..daf509bcf --- /dev/null +++ b/datatypes/datatypes-studio/src/main/Java/org/launchcode/Area.java @@ -0,0 +1,49 @@ +package org.launchcode; + +import studios.areaofacircle.Circle; + +import java.util.Scanner; + +public class Area { + public static void main(String[] args) { + Double radius = null; + double pi = 3.14; + Double area; + Scanner input; + + input = new Scanner(System.in); + System.out.println("Enter a radius: "); + // input.next(); + radius = input.nextDouble(); + /* + while (input.hasNext()) { + + if (input.hasNextDouble()) { + // radius = input.nextDouble(); + if (input.nextDouble() < 0) { + System.out.println("Invalid Input try again"); + input.next(); + } else { + + radius = input.nextDouble(); + // input.next(); + input.close(); + } + } + else { + System.out.println("Invalid Input try again"); + input.next(); +// input.close(); + } + } + + input.close(); + + + // area = (pi) * radius * radius; + + */ + area = Circle.getArea(radius); + System.out.println("The area of a circle of radius " + radius + " is: " + area); + } +} diff --git a/datatypes/datatypes-studio/src/main/Java/studios/areaofacircle/Circle.java b/datatypes/datatypes-studio/src/main/Java/studios/areaofacircle/Circle.java new file mode 100644 index 000000000..f3af4f1f4 --- /dev/null +++ b/datatypes/datatypes-studio/src/main/Java/studios/areaofacircle/Circle.java @@ -0,0 +1,11 @@ +package studios.areaofacircle; + +public class Circle { + + public static Double getArea (Double radius) { + + // public static Double getArea(Double radius) { + return 3.14 * radius * radius; + } + } + diff --git a/exceptions/chapter-example/temperature-example/src/main/java/org/launchcode/Temperature.java b/exceptions/chapter-example/temperature-example/src/main/java/org/launchcode/Temperature.java index 8eddaf754..24d688785 100644 --- a/exceptions/chapter-example/temperature-example/src/main/java/org/launchcode/Temperature.java +++ b/exceptions/chapter-example/temperature-example/src/main/java/org/launchcode/Temperature.java @@ -12,9 +12,15 @@ public void setFahrenheit(double aFahrenheit) { double absoluteZeroFahrenheit = -459.67; if (aFahrenheit < absoluteZeroFahrenheit) { + try { + throw new TemperatureException("That temperature is too low!"); + } catch (TemperatureException e) { + e.printStackTrace(); + } + } System.out.println("Value is below absolute zero"); } fahrenheit = aFahrenheit; } -} + diff --git a/exceptions/chapter-example/temperature-example/src/main/java/org/launchcode/TemperatureException.java b/exceptions/chapter-example/temperature-example/src/main/java/org/launchcode/TemperatureException.java index b581dc473..aa1c0b00d 100644 --- a/exceptions/chapter-example/temperature-example/src/main/java/org/launchcode/TemperatureException.java +++ b/exceptions/chapter-example/temperature-example/src/main/java/org/launchcode/TemperatureException.java @@ -1,5 +1,8 @@ package org.launchcode; -public class TemperatureException { +public class TemperatureException extends Throwable { // Write code here! + public TemperatureException(String message){ + super(); + } } diff --git a/hello-spring/src/main/java/org/launchcode/hellospring/controllers/HelloController.java b/hello-spring/src/main/java/org/launchcode/hellospring/controllers/HelloController.java new file mode 100644 index 000000000..ed416a9b3 --- /dev/null +++ b/hello-spring/src/main/java/org/launchcode/hellospring/controllers/HelloController.java @@ -0,0 +1,2 @@ +package org.launchcode.hellospring.controllers;public class HelloController { +} diff --git a/inheritance/MainHouseCat.java b/inheritance/MainHouseCat.java new file mode 100644 index 000000000..e2308f8fd --- /dev/null +++ b/inheritance/MainHouseCat.java @@ -0,0 +1,2 @@ +package PACKAGE_NAME;public class MainHouseCat { +} diff --git a/inheritance/testing-inheritance/exercises/Studio/questions/Question.java b/inheritance/testing-inheritance/exercises/Studio/questions/Question.java new file mode 100644 index 000000000..be11de6dc --- /dev/null +++ b/inheritance/testing-inheritance/exercises/Studio/questions/Question.java @@ -0,0 +1,70 @@ +package questions; + + import java.awt.*; + import java.util.HashMap; + + + public abstract class Question { + + private final String question; + private final HashMap choiceMap = new HashMap<>(); + private int maxResponses = 1; + + public Question(String question, Choice[] choiceArray) { + this.question = question; + } + + public String getQuestion() { + return question; + } + + public HashMap getChoiceMap() { + return choiceMap; + } + + public int getMaxResponses() { + return maxResponses; + //return 0; + } + + public void setMaxResponses(int maxResponses) { + this.maxResponses = maxResponses; + } + + //@Override + public abstract String toString(); + + void createRandomizedChoiceMap(Choice[] choiceArray) { + ArrayList choiceList = new ArrayList<>(); + + Collections.addAll(choiceList, choiceArray); + + collections.shuffle(choiceList); + for (int i = 0; i < choiceList.size(); i++) { + choiceMap.put(i+1, choiceList.get(i)); + } + } + + String getFormattedChoices() { + StringBuilde formattedChoices = new StringBuilder(); + String newline = System.lineSeparator(); + for (int choiceNum : choiceMap.keySet()) { + String choice = "\t" + choiceNum + " - " +choiceMap.get(choiceNum).getContent() + newline; + formattedChoices.append(choice); + } + return formattedChoices.toString(); + } + + pubic boolean isInvalid(String resp) { + try { + int respInt = Integer.parseInt(resp); + return respInt <= 0 || respInt >choiceMap.size(); + + } + catch (NumberFormatException e) { + return true; + } + } + } + + diff --git a/inheritance/testing-inheritance/exercises/Studio/questions/TrueOrFalse.java b/inheritance/testing-inheritance/exercises/Studio/questions/TrueOrFalse.java new file mode 100644 index 000000000..46ee4d014 --- /dev/null +++ b/inheritance/testing-inheritance/exercises/Studio/questions/TrueOrFalse.java @@ -0,0 +1,24 @@ +package questions; + +import java.awt.*; + +public class TrueOrFalse extends Question{ + + public TrueOrFalse(String question, Choice[] choiceArray) { + super(question, choiceArray); + } + + void publicTrueOrFalse(String question, Choice[] choiceArray) { + super(question, ChoiceArray); + + } + + @Override + public String toString() { + String newline = System.lineSeparator(); + return newline + "True Or False:" +newline + + getQuestion() + newline + + getFormattedChoices(); + // return null; + } +} diff --git a/inheritance/testing-inheritance/exercises/Studio/questions/package-info.java b/inheritance/testing-inheritance/exercises/Studio/questions/package-info.java new file mode 100644 index 000000000..54e2d9c2d --- /dev/null +++ b/inheritance/testing-inheritance/exercises/Studio/questions/package-info.java @@ -0,0 +1,19 @@ +package questions; + +import java.awt.*; + +public class MultipleChoice extends Question { + + public MultipleChoice(String question, Choice[] choiceArray) { + super(question, choiceArray); + } + + @Override + public String toString() { + String newline = System.lineSeparator(); + return newline "CHOOSE ONE:" + newline + + return getQuestion() + newline + + getFormattedChoices(); + //return null; + } +} \ No newline at end of file diff --git a/interfaces/exercises/ice-cream-exercises/src/main/java/org/launchcode/Cone.java b/interfaces/exercises/ice-cream-exercises/src/main/java/org/launchcode/Cone.java index 524d994e4..77565513e 100644 --- a/interfaces/exercises/ice-cream-exercises/src/main/java/org/launchcode/Cone.java +++ b/interfaces/exercises/ice-cream-exercises/src/main/java/org/launchcode/Cone.java @@ -6,4 +6,16 @@ public class Cone extends Ingredient { public Cone(String aName, double aCost, ArrayList someAllergens){ super (aName, aCost, someAllergens); } + public class ConeComparator implements Comparator { + //@Override + public int compare(Cone cone1, Cone cone2) { + if (cone1.getCost() - cone2.getCost() < 0){ + return -1; + } else if (cone1.getCost() - cone2.getCost() > 0) { + return 1; + } else { + return 0; + } + } + } } diff --git a/interfaces/exercises/ice-cream-exercises/src/main/java/org/launchcode/Flavor.java b/interfaces/exercises/ice-cream-exercises/src/main/java/org/launchcode/Flavor.java index 9765144b3..689e05d89 100644 --- a/interfaces/exercises/ice-cream-exercises/src/main/java/org/launchcode/Flavor.java +++ b/interfaces/exercises/ice-cream-exercises/src/main/java/org/launchcode/Flavor.java @@ -1,9 +1,14 @@ package org.launchcode; import java.util.ArrayList; - +import java.util.Comparator; public class Flavor extends Ingredient { - + public class FlavorComparator implements Comparator { + @Override + public int compare(Flavor flavor1, Flavor flavor2) { + return flavor1.getName().compareTo(flavor2.getName()); + } + } public Flavor(String aName, double aCost, ArrayList someAllergens){ super (aName, aCost, someAllergens); diff --git a/interfaces/exercises/ice-cream-exercises/src/main/java/org/launchcode/Main.java b/interfaces/exercises/ice-cream-exercises/src/main/java/org/launchcode/Main.java index 8787f2454..7432599b0 100644 --- a/interfaces/exercises/ice-cream-exercises/src/main/java/org/launchcode/Main.java +++ b/interfaces/exercises/ice-cream-exercises/src/main/java/org/launchcode/Main.java @@ -1,17 +1,47 @@ package org.launchcode; import java.util.ArrayList; +import java.util.Comparator; public class Main { + return o1.getName(). + + void compareTo(o2.getName()); + public class FlavorComparator implements Comparator { + public static void main(String[] args) { Case menu = new Case(); ArrayList flavors = menu.getFlavors(); ArrayList cones = menu.getCones(); // TODO: Use a Comparator class to sort the 'flavors' array alphabetically by the 'name' field. + public static void main(String[] args){ + Case menu = new Case(); + ArrayList flavors = menu.getFlavors(); + ArrayList cones = menu.getCones(); + } // TODO: Use a Comparator class to sort the 'cones' array in increasing order by the 'cost' field. - + public static void main(String[] args){ + Case menu = new Case(); + ArrayList flavors = menu.getFlavors(); + ArrayList cones = menu.getCones(); + Comparator comparator = new FlavorComparator(); + } // TODO: Print the 'flavors' and 'cones' lists (in a clear manner) to verify the sorting. + public static void main(String[] args){ + Case menu = new Case(); + ArrayList flavors = menu.getFlavors(); + ArrayList cones = menu.getCones(); + Comparator comparator = new FlavorComparator(); + + flavors.sort(comparator); + } + } + + @Override + public int compare(Flavor o1, Flavor o2) { + return 0; + } } -} \ No newline at end of file + } \ No newline at end of file diff --git a/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/BaseDisc.java b/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/BaseDisc.java new file mode 100644 index 000000000..1bdcbac97 --- /dev/null +++ b/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/BaseDisc.java @@ -0,0 +1,56 @@ +package org.launchcode; +import java.util.HashMap; + +public abstract class BaseDisc{ + + +//public class BaseDisc{ + private final int storageCapacity; + + private int discData; + private int spinSpeed; + private boolean isFull; + + private HashMap discInfo; + + public BaseDisc(int storageCapacity, int spinSpeed) { + //Object discData; + this.discData = discData; + this.storageCapacity = storageCapacity; + this.spinSpeed = spinSpeed; + this.isFull = false; + this.discInfo = new HashMap<>(); + + + } + + + public void getDiscData () { + System.out.println("Store it here"); + + } + + public int getStorageCapacity () { + return this.storageCapacity; + + } + + public int getSpinSpeed () { + return spinSpeed; + + + } + + public boolean isFull () { + return isFull; + } + + public HashMap getDiscInfo () { + return discInfo; + + } +} + + + + diff --git a/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/CD.java b/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/CD.java index 51781c249..6791928d9 100644 --- a/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/CD.java +++ b/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/CD.java @@ -1,8 +1,39 @@ package org.launchcode; +import java.util.HashMap; + + public class CD extends BaseDisc implements OpticalDisc { + public CD(int storageCapacity, int spinSpeed) { + super(storageCapacity, spinSpeed); + } + //public CD(int storageCapacity, int spinSpeed) { + + + @Override + public void spinDisc () { + System.out.println("A CD spins at a rate of" + this.getSpinSpeed() + "rpm."); + + } + + @Override + public void readDisc () { + System.out.println("I am reading the data here"); + + } + + @Override + public void StorageData () { + this.getDiscData(); + + } + } + + + + // TODO: Implement your custom interface. + + + // TODO: Determine which fields, methods, and constructors can be extended from the base class and which ones + // need to be declared separately. + -public class CD { - // TODO: Implement your custom interface. - // TODO: Determine which fields, methods, and constructors can be extended from the base class and which ones - // need to be declared separately. -} diff --git a/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/DVD.java b/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/DVD.java index 7c2442568..f1bc4a947 100644 --- a/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/DVD.java +++ b/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/DVD.java @@ -1,8 +1,34 @@ package org.launchcode; +import java.util.HashMap; + + public class DVD extends BaseDisc implements OpticalDisc { + public DVD(int storageCapacity, int spinSpeed) { + super(storageCapacity, spinSpeed); + } + + @Override + public void spinDisc() { + System.out.println("A DVD spins at a rate of" + this.getSpinSpeed() + "rpm."); + } + + @Override + public void readDisc() { + System.out.println("Readinggggg!!11"); + + } + + @Override + public void StorageData() { + this.getDiscData(); + + } + + } + + // TODO: Implement your custom interface. + -public class DVD { - // TODO: Implement your custom interface. // TODO: Determine which fields, methods, and constructors can be extended from the base class and which ones // need to be declared separately. -} + diff --git a/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/Main.java b/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/Main.java index 7d00acf4c..63cc93ba6 100644 --- a/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/Main.java +++ b/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/Main.java @@ -4,6 +4,14 @@ public class Main { public static void main(String[] args) { // TODO: Declare and initialize a CD and a DVD object. + CD myCD = new CD(700,500); + myCD.spinDisc(); + myCD.readDisc(); + myCD.getDiscData(); + DVD myDVD = new DVD(4000,700); + myDVD.spinDisc(); + myDVD.readDisc(); + // TODO: Call each CD and DVD method to verify that they work as expected. } diff --git a/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/OpticalDisc.java b/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/OpticalDisc.java new file mode 100644 index 000000000..3bc838f7b --- /dev/null +++ b/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/OpticalDisc.java @@ -0,0 +1,8 @@ +package org.launchcode; + +public interface OpticalDisc { + void spinDisc(); + void readDisc(); + void StorageData(); + +} diff --git a/unit-testing/exercises/car-exercises/src/main/java/org/launchcode/Car.java b/unit-testing/exercises/car-exercises/src/main/java/org/launchcode/Car.java index d10c16f72..ba6d39775 100644 --- a/unit-testing/exercises/car-exercises/src/main/java/org/launchcode/Car.java +++ b/unit-testing/exercises/car-exercises/src/main/java/org/launchcode/Car.java @@ -45,7 +45,11 @@ public double getGasTankLevel() { return gasTankLevel; } + public void setGasTankLevel(double gasTankLevel) { + if (gasTankLevel > this.getGasTankSize()) { + throw new IllegalArgumentException("Can't exceed tank size"); + } this.gasTankLevel = gasTankLevel; } @@ -72,12 +76,6 @@ public void drive(double miles) { //adjust fuel based on mpg and miles requested to drive double maxDistance = this.milesPerGallon * this.gasTankLevel; - /**the double below uses some syntax called the ternary operator. - * if the value of miles is greater than the value of maxDistance, - * then milesAbleToTravel = maxDistance. - * otherwise, if miles is not greater than maxDistance, - * then milesAbleToTravel = miles - */ double milesAbleToTravel = miles > maxDistance ? maxDistance : miles; double gallonsUsed = milesAbleToTravel / this.milesPerGallon; this.gasTankLevel = this.gasTankLevel - gallonsUsed; diff --git a/unit-testing/exercises/car-exercises/src/test/java/org/launchcode/CarTest.java b/unit-testing/exercises/car-exercises/src/test/java/org/launchcode/CarTest.java index 1a3f2a04a..0604c9af7 100644 --- a/unit-testing/exercises/car-exercises/src/test/java/org/launchcode/CarTest.java +++ b/unit-testing/exercises/car-exercises/src/test/java/org/launchcode/CarTest.java @@ -26,6 +26,22 @@ public void testInitialGasTank() { } //TODO: gasTankLevel is accurate after driving within tank range + @Test + public void testGasTankAfterDriving() { + test_car.drive(50); + assertEquals(9, test_car.getGasTankLevel(),.001); + } + //TODO: gasTankLevel is accurate after attempting to drive past tank range + @Test + public void testGasTankAfterExceedingTankRange() { + test_car.drive(501); + assertEquals(test_car.getGasTankLevel(), 0, .001); + } + //TODO: can't have more gas than tank size, expect an exception //TODO: can't have more gas than tank size, expect an exception + @Test() + public void testGasOverfillException() { + assertthrows(IllegalArgumentException.class, () -> ); + } } \ No newline at end of file diff --git a/unit-testing/studio/balanced-brackets/src/main/java/org/launchcode/BalancedBrackets.java b/unit-testing/studio/balanced-brackets/src/main/java/org/launchcode/BalancedBrackets.java index 890783e59..463fcd770 100644 --- a/unit-testing/studio/balanced-brackets/src/main/java/org/launchcode/BalancedBrackets.java +++ b/unit-testing/studio/balanced-brackets/src/main/java/org/launchcode/BalancedBrackets.java @@ -21,7 +21,8 @@ public class BalancedBrackets { */ public static boolean hasBalancedBrackets(String str) { int brackets = 0; - for (char ch : str.toCharArray()) { + final String str1 = str; + for (char ch : str1.toCharArray()) { if (ch == '[') { brackets++; } else if (ch == ']') { @@ -29,5 +30,25 @@ public static boolean hasBalancedBrackets(String str) { } } return brackets == 0; + public boolean isBalanced (String str1){ + if (null == str1 || ((str1.length() % 2) != 0)) { + return false; + } else { + char[] ch = str1.toCharArray(); + for (char c : ch) { + if (!(c == '{' || c == '[' || c == '(' || c == '}' || c == ']' || c == ')')) { + return false; + } + while (str.contains("()") || str.contains("[]") || str.contains("{}")) { + str = str.replaceAll("\\(\\)", "") + .replaceAll("\\[\\]", "") + .replaceAll("\\{\\}", ""); + } + return (str.isEmpty()); + } + } + } } -} \ No newline at end of file +} + + diff --git a/unit-testing/studio/balanced-brackets/src/test/java/org/launchcode/BalancedBracketsTest.java b/unit-testing/studio/balanced-brackets/src/test/java/org/launchcode/BalancedBracketsTest.java index a9d8821b3..9c60c09e1 100644 --- a/unit-testing/studio/balanced-brackets/src/test/java/org/launchcode/BalancedBracketsTest.java +++ b/unit-testing/studio/balanced-brackets/src/test/java/org/launchcode/BalancedBracketsTest.java @@ -10,4 +10,11 @@ class BalancedBracketsTest { public void emptyTest() { assertEquals(true, true); } + + @Test + public void onlyBracketsReturnsTrue() { + assertTrue(BalancedBrackets.hasBalancedBrackets("[]")); + } + + } \ No newline at end of file