Skip to content

forking debugging #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: debugging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions chapter-7-exercise/.gitignore
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions chapter-7-exercise/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>exercises</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

</project>
19 changes: 19 additions & 0 deletions chapter-7-exercise/src/main/java/org/example/Main.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
17 changes: 17 additions & 0 deletions chapter-7-exercise/src/main/java/technology/AbstractEntity.java
Original file line number Diff line number Diff line change
@@ -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;
}



}
47 changes: 47 additions & 0 deletions chapter-7-exercise/src/main/java/technology/Computer.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
30 changes: 30 additions & 0 deletions chapter-7-exercise/src/main/java/technology/Laptop.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
22 changes: 22 additions & 0 deletions chapter-7-exercise/src/main/java/technology/Program.java
Original file line number Diff line number Diff line change
@@ -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);

}
}
26 changes: 26 additions & 0 deletions chapter-7-exercise/src/main/java/technology/SmartPhone.java
Original file line number Diff line number Diff line change
@@ -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;
}

}


35 changes: 28 additions & 7 deletions classes-part-2/exercises/src/main/java/org/launchcode/Course.java
Original file line number Diff line number Diff line change
@@ -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<Student> 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.

}
46 changes: 39 additions & 7 deletions classes-part-2/exercises/src/main/java/org/launchcode/Student.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.launchcode;

import java.sql.SQLOutput;
import java.util.Objects;

public class Student {

private static int nextStudentId = 1;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());

}
}
Loading