diff --git a/chapter-7-exercise/.gitignore b/chapter-7-exercise/.gitignore
new file mode 100644
index 000000000..5ff6309b7
--- /dev/null
+++ b/chapter-7-exercise/.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/chapter-7-exercise/pom.xml b/chapter-7-exercise/pom.xml
new file mode 100644
index 000000000..cac6c00cc
--- /dev/null
+++ b/chapter-7-exercise/pom.xml
@@ -0,0 +1,17 @@
+
+
+ 4.0.0
+
+ org.example
+ exercises
+ 1.0-SNAPSHOT
+
+
+ 17
+ 17
+ UTF-8
+
+
+
\ No newline at end of file
diff --git a/chapter-7-exercise/src/main/java/org/example/Main.java b/chapter-7-exercise/src/main/java/org/example/Main.java
new file mode 100644
index 000000000..910825b48
--- /dev/null
+++ b/chapter-7-exercise/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 Alt+Enter with your caret at the highlighted text to see how
+ // IntelliJ IDEA suggests fixing it.
+ System.out.printf("Hello and welcome!");
+
+ // Press Shift+F10 or click the green arrow button in the gutter to run the code.
+ for (int i = 1; i <= 5; i++) {
+
+ // Press Shift+F9 to start debugging your code. We have set one breakpoint
+ // for you, but you can always add more by pressing Ctrl+F8.
+ System.out.println("i = " + i);
+ }
+ }
+}
\ No newline at end of file
diff --git a/chapter-7-exercise/src/main/java/technology/AbstractEntity.java b/chapter-7-exercise/src/main/java/technology/AbstractEntity.java
new file mode 100644
index 000000000..bd104e532
--- /dev/null
+++ b/chapter-7-exercise/src/main/java/technology/AbstractEntity.java
@@ -0,0 +1,17 @@
+package technology;
+
+public abstract class AbstractEntity {
+ protected static int newId = 1;
+ private final int id;
+
+ public AbstractEntity(){
+ this.id = newId;
+ }
+
+ public double getId(){
+ return id;
+ }
+
+
+
+}
diff --git a/chapter-7-exercise/src/main/java/technology/Computer.java b/chapter-7-exercise/src/main/java/technology/Computer.java
new file mode 100644
index 000000000..4517ffea5
--- /dev/null
+++ b/chapter-7-exercise/src/main/java/technology/Computer.java
@@ -0,0 +1,47 @@
+package technology;
+
+public class Computer extends AbstractEntity{
+ private String operatingSystem;
+ private String brand;
+ private int yearRelease;
+ private double cost;
+
+ public Computer(String operatingSystem, String brand, int yearRelease, double cost){
+ this.operatingSystem = operatingSystem;
+ this.brand = brand;
+ this.yearRelease = yearRelease;
+ this.cost = cost;
+
+ }
+
+ public String getOperatingSystem() {
+ return operatingSystem;
+ }
+
+ public String getBrand() {
+ return brand;
+ }
+
+ public int getYearRelease() {
+ return yearRelease;
+ }
+
+ public void setCost(double cost) {
+ this.cost = cost;
+ }
+
+ public double getCost() {
+ return cost;
+
+ }
+
+ @Override
+ public String toString(){
+ String newline = System.lineSeparator();
+ return "Product Information: " + newline +
+ "ID: " + getId() + newline +
+ "OS: " + operatingSystem + newline +
+ "Released: " + yearRelease + newline +
+ "Price: $" + cost + newline;
+ }
+}
diff --git a/chapter-7-exercise/src/main/java/technology/Laptop.java b/chapter-7-exercise/src/main/java/technology/Laptop.java
new file mode 100644
index 000000000..027e24ebf
--- /dev/null
+++ b/chapter-7-exercise/src/main/java/technology/Laptop.java
@@ -0,0 +1,30 @@
+package technology;
+
+public class Laptop extends Computer {
+
+ private double screenSize;
+ private double ram;
+
+ public Laptop(String operatingSystem, String brand, int yearRelease, double cost, double screenSize, double ram){
+ super(operatingSystem, brand, yearRelease, cost);
+ this.screenSize = screenSize;
+ this.ram = ram;
+ newId++;
+ }
+
+ public double getScreenSize() {
+ return screenSize;
+ }
+
+ public double getRam() {
+ return ram;
+ }
+
+ @Override
+ public String toString(){
+ String newline = System.lineSeparator();
+ return super.toString() +
+ "Screen Size: " + screenSize + " inches" + newline +
+ "Ram: " + ram + " G" + newline;
+ }
+}
diff --git a/chapter-7-exercise/src/main/java/technology/Program.java b/chapter-7-exercise/src/main/java/technology/Program.java
new file mode 100644
index 000000000..8bddcc7a2
--- /dev/null
+++ b/chapter-7-exercise/src/main/java/technology/Program.java
@@ -0,0 +1,22 @@
+package technology;
+
+public class Program {
+
+ public static void main(String[] args){
+
+ Laptop macbook = new Laptop("MacBook", "Mac", 2002, 2000, 14.5, 4.0);
+ Laptop macbookAir = new Laptop("MacBook", "Mac", 2002, 2000, 14.5, 4.0);
+ Laptop macbook2 = new Laptop("MacBook", "Mac", 2002, 2000, 14.5, 4.0);
+ SmartPhone iphoneXR = new SmartPhone("IOS", "Iphone", 2016, 150.00, 10.00);
+
+
+
+ System.out.println(macbook.getId());
+ System.out.println(macbookAir.getId());
+ System.out.println(macbook2.getId());
+ System.out.println(iphoneXR.getId());
+ System.out.println(macbook);
+ System.out.println(iphoneXR);
+
+ }
+}
diff --git a/chapter-7-exercise/src/main/java/technology/SmartPhone.java b/chapter-7-exercise/src/main/java/technology/SmartPhone.java
new file mode 100644
index 000000000..098865130
--- /dev/null
+++ b/chapter-7-exercise/src/main/java/technology/SmartPhone.java
@@ -0,0 +1,26 @@
+package technology;
+
+public class SmartPhone extends Computer {
+
+ private double size;
+
+ public SmartPhone(String operatingSystem, String brand, int yearRelease, double cost, double size){
+ super(operatingSystem, brand, yearRelease, cost);
+ this.size = size;
+ newId++;
+ }
+
+ public double getSize(){
+ return size;
+ }
+
+ @Override
+ public String toString(){
+ String newline = System.lineSeparator();
+ return super.toString() +
+ "Size: " + size + " inches" + newline;
+ }
+
+}
+
+
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..c80090bba 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
@@ -1,17 +1,38 @@
package org.launchcode;
+import org.w3c.dom.ls.LSOutput;
+
+import java.sql.SQLOutput;
import java.util.ArrayList;
+import java.util.Objects;
public class Course {
- private String topic;
- private Teacher instructor;
- private ArrayList enrolledStudents;
+ private String title;
+ private String instructor;
+ private int credits;
+
+ public Course (String title, int credits, String instructor) {
+ this.title = title;
+ this.credits = credits;
+ this.instructor = instructor;
+ }
+
+ public String toString(){
+ return title + " Credits: " + credits + " Taught by: " + instructor;
+ }
- // TODO: Add your custom 'toString' method here. Make sure it returns a well-formatted String rather than
- // just the class fields.
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ Course course = (Course) o;
+ return Objects.equals(title, course.title) && Objects.equals(instructor, course.instructor);
+ }
+ @Override
+ public int hashCode() {
+ return Objects.hash(title, instructor);
+ }
- // TODO: Add your custom 'equals' method here. Consider which fields should match in order to call two
- // 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..fea18c838 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
@@ -1,5 +1,8 @@
package org.launchcode;
+import java.sql.SQLOutput;
+import java.util.Objects;
+
public class Student {
private static int nextStudentId = 1;
@@ -30,20 +33,44 @@ public String studentInfo() {
//TODO: Uncomment and complete the getGradeLevel method here:
-// public String getGradeLevel() {
-// // Determine the grade level of the student based on numberOfCredits
-// }
+ public String getGradeLevel(int numberOfCredits) {
+ // Determine the grade level of the student based on numberOfCredits
+ if(this.numberOfCredits < 30) {
+ return "Freshman";
+ } else if(this.numberOfCredits < 60) {
+ return "Sophomore";
+ } else if(this.numberOfCredits < 90) {
+ return "Junior";
+ } else {
+ return "Senior";
+ }
+ }
// TODO: Complete the addGrade method.
public void addGrade(int courseCredits, double grade) {
// Update the appropriate fields: numberOfCredits, gpa
+ double qualityScore = this.gpa * this.numberOfCredits;
+ qualityScore += courseCredits * grade;
+ this.numberOfCredits += courseCredits;
+ this.gpa = qualityScore/this.numberOfCredits;
}
- // TODO: Add your custom 'toString' method here. Make sure it returns a well-formatted String rather
- // than just the class fields.
+ public String toString(){
+ return String.format("%s is a %s with %d credits and a GPA of %.2f", this.name, this.getGradeLevel(this.numberOfCredits), this.getNumberOfCredits(), this.getGpa());
+ }
- // TODO: Add your custom 'equals' method here. Consider which fields should match in order to call two
- // Student objects equal.
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ Student student = (Student) o;
+ return studentId == student.studentId;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(studentId);
+ }
public String getName() {
return name;
@@ -79,11 +106,16 @@ private void setNumberOfCredits(int numberOfCredits) {
public static void main(String[] args) {
Student sally = new Student("Sally",1,1,4.0);
+ Student sal = new Student("Sal", 2, 3, 4);
System.out.println("The Student class works! " + sally.getName() + " is a student!");
System.out.println(sally);
sally.addGrade(12, 3.5);
System.out.println(sally);
sally.addGrade(25, 3.8);
System.out.println(sally);
+ System.out.println(sally.equals(sal));
+ Course trig = new Course("Trigonometry", 3, "Mater");
+ System.out.println(trig.toString());
+
}
}
\ No newline at end of file
diff --git a/classes-part-2/studio/src/main/java/org/launchcode/Main.java b/classes-part-2/studio/src/main/java/org/launchcode/Main.java
index a284b3822..5842dcd77 100644
--- a/classes-part-2/studio/src/main/java/org/launchcode/Main.java
+++ b/classes-part-2/studio/src/main/java/org/launchcode/Main.java
@@ -1,8 +1,95 @@
package org.launchcode;
+import java.sql.SQLOutput;
+import java.util.ArrayList;
+import java.util.Date;
+
public class Main {
+ static Date date = new Date();
+ static ArrayList