Skip to content

Commit

Permalink
graded assignment LaunchCodeEducation#2 --> all tests pass, needs one…
Browse files Browse the repository at this point in the history
… more refactor
  • Loading branch information
byndas committed May 13, 2024
1 parent 73ea099 commit 830ee15
Show file tree
Hide file tree
Showing 9 changed files with 187 additions and 188 deletions.
25 changes: 21 additions & 4 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 34 additions & 48 deletions src/main/java/org/launchcode/techjobs/oo/CoreCompetency.java
Original file line number Diff line number Diff line change
@@ -1,53 +1,39 @@
package org.launchcode.techjobs.oo;

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 CoreCompetency(String value) {
this(); // initializes id by default
this.value = value;
}

public class CoreCompetency extends JobField {

// private int id;
// private static int nextId = 1;
// private String value;
// ////////////////////////////////////////////////////////////////////////////
// public CoreCompetency() {
// this.id = nextId;
// nextId++;
// }
public CoreCompetency(String value) { super(value); }

// public CoreCompetency(String value) {
// this(); // initializes id by default
// this.value = value;
// }
////////////////////////////////////////////////////////////////////////////
@Override
public String toString() {
return value;
}

@Override
public boolean equals(Object o) {
// objects are equal if share same id
if (this == o) return true;
if (!(o instanceof CoreCompetency)) return false;
CoreCompetency skill = (CoreCompetency) o;
return id == skill.id;
}

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

// @Override
// public boolean equals(Object o) {
// // objects are equal if share same id
// if (this == o) return true;
// if (!(o instanceof CoreCompetency)) return false;
// CoreCompetency skill = (CoreCompetency) o;
// return id == skill.id;
// }
////////////////////////////////////////////////////////////////////////////
public int getId() {
return id;
}

public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
// public int getId() {
// return id;
// }
//
// public String getValue() {
// return value;
// }
// public void setValue(String value) {
// this.value = value;
// }
}
69 changes: 31 additions & 38 deletions src/main/java/org/launchcode/techjobs/oo/Employer.java
Original file line number Diff line number Diff line change
@@ -1,49 +1,42 @@
package org.launchcode.techjobs.oo;

import java.util.Objects;

public class Employer {

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

// private int id;
// private static int nextId = 1;
// private String value;
////////////////////////////////////////////////////////////////////////////
public Employer() {
id = nextId;
nextId++;
}
// public Employer() {
// id = nextId;
// nextId++;
// }

public Employer(String value) {
this(); // initializes id by default
this.value = value;
super(value);
}

// public Employer(String value) {
// this(); // initializes id by default
// this.value = value;
// }
////////////////////////////////////////////////////////////////////////////
@Override
public String toString() {
return value;
}

@Override
public boolean equals(Object o) {
// objects sharing same id are equal
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());
}

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

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

public String getValue() { return value; }
public void setValue(String value) {
this.value = value;
}
// getters & setters:
// public int getId() { return id; }
//
// public String getValue() { return value; }
// public void setValue(String value) {
// this.value = value;
// }
}
7 changes: 1 addition & 6 deletions src/main/java/org/launchcode/techjobs/oo/Job.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,8 @@ public boolean equals(Object o) {
public String toString() {

String dna = "Data not available";
String noJobMsg = "OOPS! This job does not seem to exist.";

if (name == null) { return noJobMsg; }
if (employer == null) { return noJobMsg; }
if (location == null) { return noJobMsg; }
if (positionType == null) { return noJobMsg; }
if (coreCompetency == null) { return noJobMsg; }
if (name == null) { return "OOPS! This job does not seem to exist."; }

String strName = name;
String strEmployer = employer.toString();
Expand Down
38 changes: 38 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,38 @@
package org.launchcode.techjobs.oo;

import java.util.Objects;

public abstract class JobField {
// fields, constructors, getters/setters, custom methods ALL FOUR classes share
private int id;
private static int nextId = 1;
private String value;

public JobField(String value) {
this.value = value;
id = nextId;
nextId++;
}
////////////////////////////////////////////////////////////////////////////
@Override
public int hashCode() { return Objects.hash(getId()); }

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

@Override // job1.equals(job2)
public boolean equals(Object obj) {
// this refers to job1 & obj refers to job2
if (this == obj) { return true; }
if (!(obj instanceof JobField)) { return false; }
// casting Object obj to JobField type
JobField jobVar = (JobField) obj;
// equivalent objects have same id
return id == jobVar.id;
}
////////////////////////////////////////////////////////////////////////////
public int getId() { return id; }

public String getValue() { return value; }
public void setValue(String value) { this.value = value; }
}
69 changes: 28 additions & 41 deletions src/main/java/org/launchcode/techjobs/oo/Location.java
Original file line number Diff line number Diff line change
@@ -1,48 +1,35 @@
package org.launchcode.techjobs.oo;

import java.util.Objects;

public class Location {

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

// private int id;
// private static int nextId = 1;
// private String value;
////////////////////////////////////////////////////////////////////////////
public Location() {
id = nextId;
nextId++;
}

public Location(String value) {
this(); // initializes id by default
this.value = value;
}

// public Location() {
// id = nextId;
// nextId++;
// }
public Location(String value) { super(value); }

// public Location(String value) {
// this(); // initializes id by default
// this.value = value;
// }
////////////////////////////////////////////////////////////////////////////
@Override
public String toString() {
return 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());
}

// @Override
// public boolean equals(Object o) {
// // objects are equal if share same id
// if (this == o) return true;
// if (!(o instanceof Location)) return false;
// Location location = (Location) o;
// return getId() == location.getId();
// }
////////////////////////////////////////////////////////////////////////////
public int getId() { return id; }

public String getValue() { return value; }
public void setValue(String value) {
this.value = value;
}
// public int getId() { return id; }
//
// public String getValue() { return value; }
// public void setValue(String value) {
// this.value = value;
// }
}
1 change: 0 additions & 1 deletion src/main/java/org/launchcode/techjobs/oo/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public static void main(String[] args) {

/*
TODO INSTRUCTIONS:
////////////////////////////////////////////////////////////////////////////
use objects to encapsulate data & methods
use IntelliJ generator to automate routine tasks
Expand Down
Loading

0 comments on commit 830ee15

Please sign in to comment.