start assignment 3
This commit is contained in:
8 files changed
+600
No files matched your search
@@ -0,0 +1,31 @@
|
||||
package ca.bcit.comp1510.assignment3.q1;
|
||||
|
||||
/**
|
||||
* Represents a street address.
|
||||
*
|
||||
* @author Lewis & Loftus 9e
|
||||
* @author BCIT
|
||||
* @version 2017
|
||||
* @param streetAddress Street address.
|
||||
* @param city city.
|
||||
* @param state state or province.
|
||||
* @param postalCode postal code, zip code.
|
||||
*/
|
||||
public record Address(String streetAddress, String city,
|
||||
String state, String postalCode) {
|
||||
|
||||
/**
|
||||
* Returns a description of this Address object.
|
||||
*
|
||||
* @return formatted value of streetAddress, city, state, zipCode
|
||||
*/
|
||||
public String toString() {
|
||||
String result;
|
||||
|
||||
result = streetAddress + "\n";
|
||||
result += city + ", " + state + " " + postalCode;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package ca.bcit.comp1510.assignment3.q1;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
/**
|
||||
* Course contains course related information
|
||||
* including Stutdent classes.
|
||||
* @author Braeden Sowinski
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class Course {
|
||||
|
||||
/** MAX number of students. */
|
||||
public static final int MAX = 5;
|
||||
|
||||
/** name of course. */
|
||||
private String name;
|
||||
|
||||
/** students array. */
|
||||
private List<Student> students;
|
||||
|
||||
/**
|
||||
* Course constructor.
|
||||
* @param name of course
|
||||
*/
|
||||
public Course(String name) {
|
||||
this.name = name;
|
||||
this.students = new ArrayList<Student>();
|
||||
}
|
||||
|
||||
/**
|
||||
* addStudent to students array.
|
||||
* @param s student to add
|
||||
*/
|
||||
public void addStudent(Student s) {
|
||||
if (this.students.size() < MAX) {
|
||||
students.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* average of all students averages.
|
||||
* @return average of all students.
|
||||
*/
|
||||
public double average() {
|
||||
double a = 0;
|
||||
for (int i = 0; i < this.students.size(); i++) {
|
||||
a += this.students.get(i).average();
|
||||
}
|
||||
DecimalFormat format = new DecimalFormat("#0.00");
|
||||
return Double.parseDouble(format.format(a / this.students.size()));
|
||||
}
|
||||
|
||||
/**
|
||||
* role prints all students.
|
||||
*/
|
||||
public void role() {
|
||||
System.out.println("Course: " + this.name);
|
||||
for (int i = 0; i < this.students.size(); i++) {
|
||||
System.out.println(this.students.get(i).toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
package ca.bcit.comp1510.assignment3.q1;
|
||||
|
||||
/**
|
||||
* Represents a BCIT student.
|
||||
*
|
||||
* @author Lewis & Loftus 9e
|
||||
* @author BCIT
|
||||
* @version 2017
|
||||
*/
|
||||
public class Student {
|
||||
/** First name of this student. */
|
||||
private String firstName;
|
||||
|
||||
/** Last name of this student. */
|
||||
private String lastName;
|
||||
|
||||
/** Home address of this student. */
|
||||
private Address homeAddress;
|
||||
|
||||
/** School address of this student. Can be shared by other students */
|
||||
private Address schoolAddress;
|
||||
|
||||
/** testScore1. */
|
||||
private double testScore1;
|
||||
|
||||
/** testScore2. */
|
||||
private double testScore2;
|
||||
|
||||
/** testScore3. */
|
||||
private double testScore3;
|
||||
|
||||
/**
|
||||
* Constructs a Student object that contains the specified values.
|
||||
* @param first a String representing the first name
|
||||
* @param last a String representing the last name
|
||||
* @param home an Address object containing the home address
|
||||
* @param school an Address object containing the school address
|
||||
*/
|
||||
public Student(
|
||||
String first,
|
||||
String last,
|
||||
Address home,
|
||||
Address school
|
||||
) {
|
||||
firstName = first;
|
||||
lastName = last;
|
||||
homeAddress = home;
|
||||
schoolAddress = school;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a Student object that contains the specified values.
|
||||
* @param first a String representing the first name
|
||||
* @param last a String representing the last name
|
||||
* @param home an Address object containing the home address
|
||||
* @param school an Address object containing the school address
|
||||
* @param testScore1 is a double of their first test score
|
||||
* @param testScore2 is a double of their seccond test score
|
||||
* @param testScore3 is a double of their third test score
|
||||
*/
|
||||
public Student(
|
||||
String first,
|
||||
String last,
|
||||
Address home,
|
||||
Address school,
|
||||
double testScore1,
|
||||
double testScore2,
|
||||
double testScore3
|
||||
) {
|
||||
firstName = first;
|
||||
lastName = last;
|
||||
homeAddress = home;
|
||||
schoolAddress = school;
|
||||
this.testScore1 = testScore1;
|
||||
this.testScore2 = testScore2;
|
||||
this.testScore3 = testScore3;
|
||||
}
|
||||
|
||||
/**
|
||||
* setTestScore updates a selected test to
|
||||
* a new score.
|
||||
* @param test to select
|
||||
* @param score to update test to
|
||||
*/
|
||||
public void setTestScore(int test, double score) {
|
||||
switch (test) {
|
||||
case 1 -> this.testScore1 = score;
|
||||
case 2 -> this.testScore2 = score;
|
||||
default -> this.testScore3 = score;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* getTestScore of a given test.
|
||||
* @param test to get score of
|
||||
* @return score of test
|
||||
*/
|
||||
public double getTestScore(int test) {
|
||||
double score;
|
||||
switch (test) {
|
||||
case 1 -> score = this.testScore1;
|
||||
case 2 -> score = this.testScore2;
|
||||
default -> score = this.testScore3;
|
||||
}
|
||||
return score;
|
||||
}
|
||||
|
||||
/**
|
||||
* average calculation of all 3 test scores.
|
||||
* @return average
|
||||
*/
|
||||
public double average() {
|
||||
final int tests = 3;
|
||||
return (this.testScore1 + this.testScore2 + this.testScore3) / tests;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a String description of this Student object.
|
||||
* @return description a String
|
||||
*/
|
||||
public String toString() {
|
||||
String result;
|
||||
|
||||
result = firstName + " " + lastName + "\n";
|
||||
result += "Home Address:\n" + homeAddress + "\n";
|
||||
result += "School Address:\n" + schoolAddress + "\n";
|
||||
result += "Test Score 1:\n" + testScore1 + "\n";
|
||||
result += "Test Score 2:\n" + testScore2 + "\n";
|
||||
result += "Test Score 3:\n" + testScore3 + "\n";
|
||||
result += "Average Score:\n" + average();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package ca.bcit.comp1510.assignment3.q1;
|
||||
|
||||
/**
|
||||
* TestCourse tests Course class.
|
||||
* @author Braeden Sowinski
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class TestCourse {
|
||||
|
||||
/**
|
||||
* main program entry.
|
||||
* @param args unused
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
Course comp1510 = new Course("Programming Methods");
|
||||
|
||||
final double perfect = 100.0;
|
||||
comp1510.addStudent(new Student(
|
||||
"Braeden",
|
||||
"Sowinski",
|
||||
new Address("123 ABC St.", "Surrey", "BC", "A1B 2C3"),
|
||||
new Address("3700 Willington Ave.", "Burnaby", "BC", "V5G 3H2"),
|
||||
perfect,
|
||||
perfect,
|
||||
perfect
|
||||
));
|
||||
|
||||
final double bad1 = 73.7;
|
||||
final double bad2 = 69.69;
|
||||
final double okay = 84.5;
|
||||
comp1510.addStudent(new Student(
|
||||
"Joker",
|
||||
"Student",
|
||||
new Address("321 ABC St.", "Vancouver", "BC", "X1Y 2Z3"),
|
||||
new Address("3700 Willington Ave.", "Burnaby", "BC", "V5G 3H2"),
|
||||
bad1,
|
||||
bad2,
|
||||
okay
|
||||
));
|
||||
|
||||
|
||||
final double mid1 = 83.21;
|
||||
final double mid2 = 79.97;
|
||||
comp1510.addStudent(new Student(
|
||||
"Joker",
|
||||
"Student",
|
||||
new Address("987 XYZ St.", "Toronto", "Quebec", "ABC 123"),
|
||||
new Address("3700 Willington Ave.", "Burnaby", "BC", "V5G 3H2"),
|
||||
mid1,
|
||||
mid2,
|
||||
okay
|
||||
));
|
||||
|
||||
comp1510.role();
|
||||
System.out.println("Programming Methods Average: "
|
||||
+ comp1510.average());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package ca.bcit.comp1510.assignment3.q2;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.DayOfWeek;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* TimeSheet data.
|
||||
* @author Braeden Sowinski
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class TimeSheet {
|
||||
|
||||
/** empNum is employee number. */
|
||||
private String empNum;
|
||||
|
||||
/** endDate of week, must be Friday. */
|
||||
private LocalDate endWeek;
|
||||
|
||||
/** details of TimeSheetRows. */
|
||||
private List<TimeSheetRow> details;
|
||||
|
||||
/**
|
||||
* TimeSheet no-argument constructor.
|
||||
*/
|
||||
public TimeSheet() {
|
||||
this.empNum = "";
|
||||
this.endWeek = null;
|
||||
this.details = new ArrayList<TimeSheetRow>();
|
||||
}
|
||||
|
||||
/**
|
||||
* TimeSheet constructor.
|
||||
* @param empNum string of employee number
|
||||
* @param endWeek date
|
||||
*/
|
||||
public TimeSheet(String empNum, LocalDate endWeek) {
|
||||
this.empNum = empNum;
|
||||
this.endWeek = endWeek;
|
||||
this.details = new ArrayList<TimeSheetRow>();
|
||||
}
|
||||
|
||||
/**
|
||||
* getEmpNum.
|
||||
* @return empNum String employee number
|
||||
*/
|
||||
public String getEmpNum() {
|
||||
return this.empNum;
|
||||
}
|
||||
|
||||
/**
|
||||
* getEndWeek.
|
||||
* @return endWeek LocalDate
|
||||
*/
|
||||
public LocalDate getEndWeek() {
|
||||
return this.endWeek;
|
||||
}
|
||||
|
||||
/**
|
||||
* getDetails.
|
||||
* @return details List of TimeSheetRow
|
||||
*/
|
||||
public List<TimeSheetRow> getDetails() {
|
||||
return this.details;
|
||||
}
|
||||
|
||||
/**
|
||||
* setEmpNum to update employee number.
|
||||
* @param empNum String to update
|
||||
*/
|
||||
public void setEmpNum(String empNum) {
|
||||
this.empNum = empNum;
|
||||
}
|
||||
|
||||
/**
|
||||
* setEndWeek to update endWeek.
|
||||
* @param endDate to update
|
||||
* @throws IllegalArgumentException if not Friday
|
||||
*/
|
||||
public void setEndWeek(LocalDate endDate) throws IllegalArgumentException {
|
||||
if (endDate.getDayOfWeek() != DayOfWeek.FRIDAY) {
|
||||
throw new IllegalArgumentException(
|
||||
"End date must be set to a Friday."
|
||||
);
|
||||
}
|
||||
this.endWeek = endDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* toString.
|
||||
* @return TimeSheet representation
|
||||
*/
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* addRow to details array.
|
||||
* @param row TimeSheetRow
|
||||
*/
|
||||
public void addRow(TimeSheetRow row) {
|
||||
this.details.add(row);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
package ca.bcit.comp1510.assignment3.q2;
|
||||
|
||||
/**
|
||||
* TimeSheetRow is a row of TimeSheet.
|
||||
* @author Braeden Sowinski
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class TimeSheetRow {
|
||||
|
||||
/** MASK of bits for days of week represented inside hours long. */
|
||||
private static final long[] MASK = {
|
||||
0xFFL, 0xFF00L, 0xFF0000L,
|
||||
0xFF000000L, 0xFF00000000L,
|
||||
0xFF0000000000L, 0xFF000000000000L
|
||||
};
|
||||
|
||||
/** UMASK to unmask stuff. */
|
||||
private static final long[] UMASK = {
|
||||
0xFFFFFFFFFFFFFF00L,
|
||||
0xFFFFFFFFFFFF00FFL,
|
||||
0xFFFFFFFFFF00FFFFL,
|
||||
0xFFFFFFFF00FFFFFFL,
|
||||
0xFFFFFF00FFFFFFFFL,
|
||||
0xFFFF00FFFFFFFFFFL,
|
||||
0xFF00FFFFFFFFFFFFL
|
||||
};
|
||||
|
||||
/** DECI to convert hours. */
|
||||
private static final float DECI = 10;
|
||||
|
||||
/** baseHex to convert hexidecimal */
|
||||
private static final int HEX_BASE = 16;
|
||||
|
||||
/** SHIFT by bits */
|
||||
private static final int SHIFT = 8;
|
||||
|
||||
/** project number as int. */
|
||||
private int project;
|
||||
|
||||
/** workPackage string. */
|
||||
private String workPackage;
|
||||
|
||||
/** hours worked long. */
|
||||
private long hours;
|
||||
|
||||
/**
|
||||
* TimeSheetRow no-argument constructor.
|
||||
*/
|
||||
public TimeSheetRow() {
|
||||
this.project = 0;
|
||||
this.workPackage = "";
|
||||
this.hours = 0;
|
||||
}
|
||||
|
||||
/**4
|
||||
* TimeSheetRow constructor.
|
||||
* @param projectNumber int
|
||||
* @param workPackage String
|
||||
* @param hours float...
|
||||
*/
|
||||
public TimeSheetRow(int projectNumber, String workPackage, float... hours) {
|
||||
this.project = projectNumber;
|
||||
this.workPackage = workPackage;
|
||||
|
||||
String encoded = "";
|
||||
for (int i = hours.length - 1; i >= 0; i--) {
|
||||
String hex = Integer.toHexString((int) (hours[i] * DECI));
|
||||
hex = hex.length() == 1 ? "0" + hex : hex;
|
||||
encoded += hex;
|
||||
}
|
||||
|
||||
this.hours = Long.parseLong(encoded, HEX_BASE);
|
||||
}
|
||||
|
||||
/**
|
||||
* getProject number.
|
||||
* @return project int
|
||||
*/
|
||||
public int getProject() {
|
||||
return this.project;
|
||||
}
|
||||
|
||||
/**
|
||||
* getWorkPackage name.
|
||||
* @return workPackage string
|
||||
*/
|
||||
public String getWorkPackage() {
|
||||
return this.workPackage;
|
||||
}
|
||||
|
||||
/**
|
||||
* getHours worked.
|
||||
* @return hours long.
|
||||
*/
|
||||
public long getHours() {
|
||||
return this.hours;
|
||||
}
|
||||
|
||||
/**
|
||||
* setProject number.
|
||||
* @param project int
|
||||
*/
|
||||
public void setProject(int project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
/**
|
||||
* setProject name.
|
||||
* @param newWorkPackage string
|
||||
*/
|
||||
public void setProject(String newWorkPackage) {
|
||||
this.workPackage = newWorkPackage;
|
||||
}
|
||||
|
||||
/**
|
||||
* setProject worked.
|
||||
* @param newHours long.
|
||||
*/
|
||||
public void setProject(long newHours) {
|
||||
this.hours = newHours;
|
||||
}
|
||||
|
||||
/**
|
||||
* toString string representation.
|
||||
* @return string
|
||||
*/
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* getHour of day.
|
||||
* @param day as int
|
||||
* @return hours float
|
||||
*/
|
||||
public float getHour(int day) {
|
||||
return ((this.hours >> (day * SHIFT)) & MASK[0]) / DECI;
|
||||
}
|
||||
|
||||
/**
|
||||
* setHour of a given day of week.
|
||||
* @param day as int
|
||||
* @param hour float
|
||||
*/
|
||||
public void setHour(int day, float hour) {
|
||||
// long encoded = ((long) (hour * DECI) | MASK[day + 1]) << day * SHIFT;
|
||||
// this.hours = (this.hours & UMASK[day]) | encoded;
|
||||
String hex = Integer.toHexString((int) (hour * DECI));
|
||||
long encoded = Long.parseLong(hex, HEX_BASE) << (day * SHIFT);
|
||||
this.hours = (this.hours & UMASK[day]) | encoded;
|
||||
}
|
||||
|
||||
/**
|
||||
* main test encode decode.
|
||||
* @param args unused
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
final Long n = 0X321420372d0b20L;
|
||||
|
||||
TimeSheetRow t = new TimeSheetRow(
|
||||
0,
|
||||
"Test",
|
||||
3.2f, 1.1f, 4.5f, 5.5f, 3.2f, 2.0f, 5.0f
|
||||
);
|
||||
|
||||
System.out.println(Long.toHexString(t.getHours()));
|
||||
// t.setHour(2, 3.2f);
|
||||
// t.setHour(4, 5.5f);
|
||||
for (int i = 0; i < 7; i++) {
|
||||
t.setHour(i, 3.0f);
|
||||
System.out.print(t.getHour(i) + " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package ca.bcit.comp1510.assignment3.q2;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class TimeSheetRowTest {
|
||||
|
||||
@Test
|
||||
void test() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package ca.bcit.comp1510.assignment3.q2;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class TimeSheetTest {
|
||||
|
||||
@Test
|
||||
void test() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user