Skip to content

Commit

Permalink
ASSIGNMENT LaunchCodeEducation#2: TECH JOBS OO
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaBuehrer committed Jan 19, 2024
1 parent 9873e51 commit 0c590f3
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 163 deletions.
38 changes: 2 additions & 36 deletions src/main/java/org/launchcode/techjobs/oo/CoreCompetency.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,9 @@

import java.util.Objects;

public class CoreCompetency {

private int id;
private static int nextId = 1;
private String value;

public CoreCompetency() {
this.id = nextId;
nextId++;
}
public class CoreCompetency extends JobField {

public CoreCompetency(String value) {
this();
this.value = value;
}

// Custom toString, equals, and hashCode methods:

@Override
public String toString() {
return value;
super(value);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CoreCompetency)) return false;
CoreCompetency that = (CoreCompetency) o;
return id == that.id;
}

@Override
public int hashCode() {
return Objects.hash(id);
}

// TODO: Use the "Generate" tool to add a getter and setter for the 'value' field but
// ONLY a getter for the 'id' field.

}
49 changes: 2 additions & 47 deletions src/main/java/org/launchcode/techjobs/oo/Employer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,9 @@

import java.util.Objects;

public class Employer {

private int id;
private static int nextId = 1;
private String value;

public Employer() {
id = nextId;
nextId++;
}
public class Employer extends JobField{

public Employer(String value) {
this();
this.value = value;
}

// Custom toString, equals, and hashCode methods:

@Override
public String toString() {
return value;
}

@Override
public boolean equals(Object o) { // Two objects are equal if they have the same id.
if (this == o) return true;
if (!(o instanceof Employer)) return false;
Employer employer = (Employer) o;
return getId() == employer.getId();
}

@Override
public int hashCode() {
return Objects.hash(getId());
super(value);
}

// Getters and Setters:

public int getId() {
return id;
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}

}
90 changes: 90 additions & 0 deletions src/main/java/org/launchcode/techjobs/oo/Job.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,99 @@ public class Job {
// other five fields. The second constructor should also call the first in order to initialize
// the 'id' field.

public Job() {
id = nextId;
nextId++;
}

public Job(String aName, Employer aEmployer, Location aLocation, PositionType aPositionType, CoreCompetency someCoreCompetency){
this();
this.name = aName;
this.employer = aEmployer;
this.location = aLocation;
this.positionType = aPositionType;
this.coreCompetency = someCoreCompetency;
}

// TODO: Add custom equals and hashCode methods. Consider two Job objects "equal" when their id fields
// match.

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Job job)) return false;
return id == job.id;
}

@Override
public int hashCode() {
return Objects.hash(id);
}

// TODO: Add getters for each field EXCEPT nextId. Add setters for each field EXCEPT nextID
// and id.

@Override
public String toString(){

String idValue = getId() == 0 ? "Data not available" : String.valueOf(getId());
String nameValue = getName().isEmpty() ? "Data not available" : getName();
String employerValue = getEmployer().getValue().isEmpty() ? "Data not available" : getEmployer().toString();
String locationValue = getLocation().getValue().isEmpty() ? "Data not available" : getLocation().toString();
String positionTypeValue = getPositionType().getValue().isEmpty() ? "Data not available" : getPositionType().toString();
String coreCompetencyValue = getCoreCompetency().getValue().isEmpty() ? "Data not available" : getCoreCompetency().toString();

return String.format("%sID: %s%sName: %s%sEmployer: %s%sLocation: %s%sPosition Type: %s%sCore Competency: %s%s",
System.lineSeparator(),
idValue, System.lineSeparator(),
nameValue, System.lineSeparator(),
employerValue, System.lineSeparator(),
locationValue, System.lineSeparator(),
positionTypeValue, System.lineSeparator(),
coreCompetencyValue, System.lineSeparator());
}

public int getId() {
return id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Employer getEmployer() {
return employer;
}

public void setEmployer(Employer employer) {
this.employer = employer;
}

public Location getLocation() {
return location;
}

public void setLocation(Location location) {
this.location = location;
}

public PositionType getPositionType() {
return positionType;
}

public void setPositionType(PositionType positionType) {
this.positionType = positionType;
}

public CoreCompetency getCoreCompetency() {
return coreCompetency;
}

public void setCoreCompetency(CoreCompetency coreCompetency) {
this.coreCompetency = coreCompetency;
}
}
52 changes: 52 additions & 0 deletions src/main/java/org/launchcode/techjobs/oo/JobField.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.launchcode.techjobs.oo;

import java.util.Objects;

public abstract class JobField {
private int id;
private static int nextId = 1;
private String value;

public JobField() {
id = nextId;
nextId++;
}

public JobField(String value) {
this();
this.value = value;
}
@Override
public String toString() {
return value;
}

@Override
public boolean equals(Object o) { // Two objects are equal if they have the same id.
if (this == o) return true;
if (!(o instanceof JobField)) return false;
JobField jobField = (JobField) o;
return getId() == jobField.getId();
}

@Override
public int hashCode() {
return Objects.hash(getId());
}

// Getters and Setters:

public int getId() {
return id;
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}


}
51 changes: 3 additions & 48 deletions src/main/java/org/launchcode/techjobs/oo/Location.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,8 @@

import java.util.Objects;

public class Location {

private int id;
private static int nextId = 1;
private String value;

public Location() {
id = nextId;
nextId++;
}

// TODO: Add a constructor that takes a string as a parameter and assigns it to the 'value' field. The
// constructor should also call the empty constructor in order to initialize the 'id' field.


// Custom toString, equals, and hashCode methods:

@Override
public String toString() {
return value;
public class Location extends JobField {
public Location(String value) {
super(value);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Location)) return false;
Location location = (Location) o;
return getId() == location.getId();
}

@Override
public int hashCode() {
return Objects.hash(getId());
}

// Getters and Setters:

public int getId() {
return id;
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}

}
34 changes: 3 additions & 31 deletions src/main/java/org/launchcode/techjobs/oo/PositionType.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,10 @@
package org.launchcode.techjobs.oo;

public class PositionType {
import java.util.Objects;

private int id;
private static int nextId = 1;
private String value;

public PositionType() {
id = nextId;
nextId++;
}
public class PositionType extends JobField {

public PositionType(String value) {
this();
this.value = value;
}

// TODO: Add a custom toString() method that returns the data stored in 'value'.

// TODO: Add custom equals and hashCode methods. Consider two PositionType objects "equal" when
// their id fields match.

// Getters and Setters:

public int getId() {
return id;
}

public String getValue() {
return value;
super(value);
}

public void setValue(String value) {
this.value = value;
}

}
Loading

0 comments on commit 0c590f3

Please sign in to comment.