Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T4Practical1 #6

Open
wants to merge 2 commits into
base: demo
Choose a base branch
from
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
23 changes: 23 additions & 0 deletions src/main/java/com/stir/cscu9t4practical1/CycleEntry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.stir.cscu9t4practical1;

public class CycleEntry extends Entry{

private String terrain;
private String tempo;

public CycleEntry (String n, int d, int m, int y, int h, int min, int s, float dist, String terr, String tempo){
super(n,d, m, y, h, min, s, dist);
this.terrain = terr;
this.tempo = tempo;

}

public String getTerrain() { return terrain; }

public String getTempo() { return tempo; }

@Override
public String getEntry() {
return (getName() + " cycled " + getDistance() + " km in " + getHour() + ":" + getMin() + ":" + getSec() + " on " + getDay() + "/" + getMonth() + "/" + getYear() + " on " + getTerrain() + " at " + getTempo() + " tempo\n");
}
}
17 changes: 8 additions & 9 deletions src/main/java/com/stir/cscu9t4practical1/Entry.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
// This class holds information about a single training session
package com.stir.cscu9t4practical1;

import java.util.Calendar;
// Just testing
import java.util.Calendar;
public class Entry {
private String name;
private Calendar dateAndTime;
private float distance;
protected String name;
protected Calendar dateAndTime;
protected float distance;

public Entry (String n, int d, int m, int y, int h, int min, int s, float dist) {
name = n;
this.name = n;
Calendar inst = Calendar.getInstance();
inst.set(y,m-1,d,h,min,s);
dateAndTime = inst;
distance = dist;
this.dateAndTime = inst;
this.distance = dist;
} //constructor

public String getName () {
Expand Down Expand Up @@ -50,7 +49,7 @@ public float getDistance () {
} //getYear

public String getEntry () {
String result = getName()+" ran " + getDistance() + " km in "
String result = getName()+" went " + getDistance() + " km in "
+getHour()+":"+getMin()+":"+ getSec() + " on "
+getDay()+"/"+getMonth()+"/"+getYear()+"\n";
return result;
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/com/stir/cscu9t4practical1/SprintEntry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.stir.cscu9t4practical1;
import java.util.Calendar;

public class SprintEntry extends Entry{

private int repetitions;
private float recovery;

public SprintEntry(String n, int d, int m, int y, int h, int min, int s, float dist, int reps, float recov) {

super(n,d, m, y, h, min, s, dist);
this.repetitions = reps;
this.recovery = recov;

}

public int getRepetitions() { return repetitions; }

public float getRecovery() { return recovery; }

@Override
public String getEntry() {
return (getName() + " sprinted " + getRepetitions() + "x" + getDistance() + "m in " + getHour() + ":" + getMin() + ":" + getSec() + " with " + getRecovery() + " minutes recovery on " + getDay() + "/" + getMonth() + "/" + getYear() +"\n");
}
}
25 changes: 25 additions & 0 deletions src/main/java/com/stir/cscu9t4practical1/SwimEntry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.stir.cscu9t4practical1;
import java.util.Calendar;

public class SwimEntry extends Entry{
private String where;

public SwimEntry(String n, int d, int m, int y, int h, int min, int s, float dist, String where) {
super(n,d, m, y, h, min, s, dist);
this.where = where;
}

public String getWhere() {
if (where.equals("pool")) {
return "in a " + where;
}
else {
return where;
}
}

@Override
public String getEntry() {
return (getName() + " swam " + getDistance() + " km " + getWhere() + " in " + getHour() + ":" + getMin() + ":" + getSec() + " on " + getDay() + "/" + getMonth() + "/" + getYear() +"\n");
}
}
49 changes: 47 additions & 2 deletions src/main/java/com/stir/cscu9t4practical1/TrainingRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,35 @@ public String lookupEntry (int d, int m, int y) {
}
return result;
} // lookupEntry


// look up the entry of a given day and month
public void RemoveEntry (int d, int m, int y, String n) {
ListIterator<Entry> iter = tr.listIterator();
String result = "No entries found";
while (iter.hasNext()) {
Entry current = iter.next();
if (current.getDay()==d && current.getMonth()==m && current.getYear()==y && current.getName().equals(n))
tr.remove(current.getEntry());
}
} // lookupEntry

// look up the entry of a given day and month
public LinkedList<String> lookUpEntries (int d, int m, int y) {
ListIterator<Entry> iter = tr.listIterator();
LinkedList<String> result = new LinkedList();
// result.set(i, "No entries found");
int i = 0;
while (iter.hasNext()) {
Entry current = iter.next();
if (current.getDay()==d && current.getMonth()==m && current.getYear()==y)
result.set(i, current.getEntry());
else
result.set(i, "No entries found.");
i++;
}
return result;
} // lookupEntry

// Count the number of entries
public int getNumberOfEntries(){
return tr.size();
Expand All @@ -39,5 +67,22 @@ public int getNumberOfEntries(){
public void clearAllEntries(){
tr.clear();
}


//public void RemoveEntry(Entry e) {tr.remove(e); }
//public int RemoveEntry(String name, int d, int m, int y) {
// ListIterator<Entry> iter = tr.listIterator();
// LinkedList<String> result = new LinkedList();
// result.set(i, "No entries found");
// int i = 0;
// while (iter.hasNext()) {
// Entry current = iter.next();
// if (current.getDay()==d && current.getMonth()==m && current.getYear()==y)
// result.set(i, current.getEntry());
// else
// result.set(i, "No entries found.");
// i++;
// }
// return result;
//}

} // TrainingRecord
Loading