Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dbenion9 committed Oct 1, 2024
1 parent 1480b6a commit d84d93b
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 218 deletions.
44 changes: 30 additions & 14 deletions .idea/workspace.xml

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

54 changes: 6 additions & 48 deletions src/main/java/org/launchcode/techjobs/oo/CoreCompetency.java
Original file line number Diff line number Diff line change
@@ -1,55 +1,13 @@
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++;
}
// CoreCompetency now extends JobField
public class CoreCompetency extends JobField {

// Constructor that accepts a value and passes it to the superclass
public CoreCompetency(String value) {
this();
this.value = value;
}

// Custom toString, equals, and hashCode methods:

@Override
public String toString() {
return 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;
super(value); // Call to the JobField constructor to initialize the 'value' field
}

@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.

public String getValue() {
return value;
}

public int getId() {
return id;
}

public void setValue(String value) {
this.value = value;
}
// No need to redefine equals, hashCode, toString, getId, or getValue methods,
// since these are inherited from JobField
}
55 changes: 6 additions & 49 deletions src/main/java/org/launchcode/techjobs/oo/Employer.java
Original file line number Diff line number Diff line change
@@ -1,55 +1,12 @@
package org.launchcode.techjobs.oo;

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 {

// Constructor that accepts a value and passes it to the JobField superclass
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());
}

// Getters and Setters:

public int getId() {
return id;
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
super(value); // Call the JobField constructor to initialize 'value'
}

}
// No need to redefine equals, hashCode, toString, getId, or getValue methods,
// since these are inherited from JobField
}
1 change: 1 addition & 0 deletions src/main/java/org/launchcode/techjobs/oo/Job.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Objects;


public class Job {
// Field declarations
private int id;
Expand Down
54 changes: 52 additions & 2 deletions src/main/java/org/launchcode/techjobs/oo/JobField.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,54 @@
package org.launchcode.techjobs.oo;

public class JobField {
}
import
java.util.Objects;

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

// Constructor initializing only id
public JobField() {
this.id = nextId;
nextId++;
}

// Constructor initializing id and value
public JobField(String value) {
this();
this.value = value;
}

// Getters and setters for 'id' and 'value'
public int getId() {
return id;
}

public String getValue() {
return value;
}

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

// Custom equals and hashCode methods, if needed
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
JobField jobField = (JobField) o;
return id == jobField.id;
}

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

@Override
public String toString() {
return value;
}
}
59 changes: 8 additions & 51 deletions src/main/java/org/launchcode/techjobs/oo/Location.java
Original file line number Diff line number Diff line change
@@ -1,59 +1,16 @@
package org.launchcode.techjobs.oo;

// Import Objects utility for equals and hashCode
import java.util.Objects;

public class Location {

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

public Location() {
id = nextId;
nextId++;
}
// Location now extends JobField
public class Location extends JobField {

// Constructor that accepts a value and passes it to the superclass
public Location(String value) {
this(); // This calls the default constructor to initialize 'id'
this.value = value; // Assign the passed 'value' to the 'value' field
}

// 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;
}

@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;
super(value); // Call to the JobField constructor to initialize the 'value' field
}

}
// No need to redefine equals, hashCode, toString, getId, or getValue methods,
// since these are inherited from JobField
}
Loading

0 comments on commit d84d93b

Please sign in to comment.