Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public class HelloMethods {

public static void main(String[] args) {
String message = Message.getMessage("fr");
String message = Message.getMessage("de");
System.out.println(message);
}

Expand Down
2 changes: 2 additions & 0 deletions src/org/launchcode/java/demos/lsn1datatypes/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public static String getMessage(String lang) {
return "¡Hola, Mundo!";
} else if (lang.equals("fr")) {
return "Bonjour, le monde!";
} else if (lang.equals("de")) {
return "Hallo, Welt!";
} else {
return "Hello, World!";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.launchcode.java.demos.lsn1datatypes;

import java.util.Scanner;
//import java.util.Scanner;

public class TempConverter {
public static void main(String[] args) {
double fahrenheit;
double celsius;
Scanner input;
java.util.Scanner input;

input = new Scanner(System.in);
input = new java.util.Scanner(System.in);
System.out.println("Enter the temperature in Fahrenheit: ");
fahrenheit = input.nextDouble();
input.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
public class SchoolPractice {
public static void main(String[] args) {
// Instantiate your Student class for part 2 here!
Student amit = new Student("Amit Kapila",3,1,4.0);
}
}
49 changes: 49 additions & 0 deletions src/org/launchcode/java/demos/lsn3classes1/Student.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,55 @@
public class Student {

private String name;

public String getName() {
return name;
}

public Student(String name) {
this.name = name;
}

public Student(String name, int studentId, int numberOfCredits, double gpa) {
this.name = name;
this.studentId = studentId;
this.numberOfCredits = numberOfCredits;
this.gpa = gpa;
}

public int getStudentId() {
return studentId;
}

public void setStudentId(int studentId) {
this.studentId = studentId;
}

public int getNumberOfCredits() {
return numberOfCredits;
}

private void setNumberOfCredits(int numberOfCredits) {
this.numberOfCredits = numberOfCredits;
}

public double getGpa() {
return gpa;
}

public void setGpa(double gpa) {
this.gpa = gpa;
}

public Student(String name, int studentId) {
this.name = name;
this.studentId = studentId;
}

public void setName(String aName) {
name = aName;
}

private int studentId;
private int numberOfCredits = 0;
private double gpa = 0.0;
Expand Down
16 changes: 15 additions & 1 deletion src/org/launchcode/java/demos/lsn4classes2/Course.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.launchcode.java.demos.lsn4classes2;

import java.util.ArrayList;
import java.util.Objects;

public class Course {
private String topic;
Expand All @@ -10,8 +11,21 @@ public class Course {
// 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(topic, course.topic) && Objects.equals(instructor, course.instructor) && Objects.equals(enrolledStudents, course.enrolledStudents);
}

@Override
public int hashCode() {
return Objects.hash(topic, instructor, enrolledStudents);
}


// TODO: Add your custom 'equals' method here. Consider which fields should match in order to call two
// Course objects equal.

}
}
36 changes: 33 additions & 3 deletions src/org/launchcode/java/demos/lsn4classes2/Student.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.launchcode.java.demos.lsn4classes2;

import java.util.Objects;

public class Student {

private static int nextStudentId = 1;
Expand Down Expand Up @@ -30,21 +32,49 @@ 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 credits) {
// Determine the grade level of the student based on numberOfCredits
if(credits <= 29) {
return "Freshman";
} else if (credits <= 59) {
return "Sophomore";
} else if (credits <= 89) {
return "Junior";
} else {
return "Senior";
}
}

// TODO: Complete the addGrade method.
public void addGrade(int courseCredits, double grade) {
// Update the appropriate fields: numberOfCredits, gpa
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
// than just the class fields.

@Override
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;
}


// 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 getStudentId() == student.getStudentId();}

public String getName() {
return name;
}
Expand Down
24 changes: 24 additions & 0 deletions src/org/launchcode/java/demos/lsn5unittesting/test/CarTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
package org.launchcode.java.demos.lsn5unittesting.test;

import org.junit.Before;
import org.junit.Test;
import org.launchcode.java.demos.lsn5unittesting.main.Car;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

public class CarTest {

Car test_car;

@Before
public void createCarObject() {
test_car = new Car("Toyota","Prius",10,50);
}

//TODO: add emptyTest so we can configure our runtime environment (remove this test before pushing to your personal GitLab account)
@Test
public void emptyTest() {
assertEquals(10,10,.001);
}
//TODO: constructor sets gasTankLevel properly
@Test
public void testInitialGasTank() {
//Car test_car = new Car("Toyota","Prius",10,50);
//assertEquals(10, test_car.getGasTankLevel(),.001);
assertFalse(test_car.getGasTankLevel() == 0);
}
//TODO: gasTankLevel is accurate after driving within tank range
//TODO: gasTankLevel is accurate after attempting to drive past tank range
//TODO: can't have more gas than tank size, expect an exception
Expand Down