ca_dyl
asked on
abstract, interfaces, maps & sets, taking reading and saving to file
Hi. Basically i have a task that involves me having student. This student can have 4 units, of which each unit can have assessments. An assessment is either a test or assignment. An Assignment can be completed in group of individually. What needs to happen is that the student manager class runs the program. I have to be able to add delete & alter units, list assessments, & details of student & their units / assessments basically. This needs to be the saved to file, & altered or viewed at any time. Assessments must be able to be viewed by due date & by unit.
i have included some of the classes i have started on. Where im stuck really is where to use TreeSet, HashMap, ArrayList (bc they r the three we have to use) & how the classes relate to each other. So really just a hand with the base classes. Any help or pointers would be so very much appreciated. I have the classes at the moment so that TheStudentManager controls the program. Unit Class. Contact Class (abstract) of which Student & Staff extend. Assessment (abstract) of which Test and Assignment extend.
thanks
matt
Assessment class:
import java.util.*;
import java.io.*;
public abstract class Assessment
{
// instance variables - replace the example below with your own
protected String time;
protected String date;
public Assessment()
{
time = "unknown";
date = "unknown";
}
public Assessment(String date, String time)
{
this.date = date;
this.time = time;
}
public String getDate()
{
return date;
}
public void setDate(String newDate)
{
date = newDate;
}
public String getTime()
{
return time;
}
public void setTime(String newTime)
{
time = newTime;
}
public abstract void print();
}
Test
import java.util.*;
import java.io.*;
public class Test extends Assessment
{
private String duration;
private String topics;
public Test()
{
// initialise instance variables
super("unknown", "unknown");
duration = ("3 hours");
topics = ("why we hate java");
}
Test(String date, String time, String newDuration, String newTopics)
{
super (date, time);
duration = newDuration;
topics = newTopics;
}
public void setDuration(String newDuration)
{
duration = newDuration;
}
public void setTopics(String newTopics)
{
topics = newTopics;
}
public void print()
{
System.out.println("" + "\n" +
"time : " + time + "\n" +
"duration" + duration + "\n");
}
}
Assignment
import java.util.*;
import java.io.*;
public class Assignment extends Assessment
{
private String dateDue;
private String subject;
public Assignment()
{
// initialise instance variables
super("unknown", "unknown");
subject = ("Java");
dateDue = ("30th Oct");
}
Assignment(String date, String time, String newDateDue, String newSubject)
{
super (date, time);
dateDue = newDateDue;
subject = newSubject;
}
public void setSubject(String newSubject)
{
subject = newSubject;
}
public void setDateDue(String newDateDue)
{
dateDue = newDateDue;
}
public void print()
{
System.out.println("" + "\n" +
"time : " + time + "\n" +
"subject" + subject + "\n");
}
}
Contact
import java.util.*;
import java.io.*;
public abstract class Contact
{
// instance variables - replace the example below with your own
protected String id;
protected String name;
protected String emailAddress;
protected String address;
protected String phoneNumber;
public Contact()
{
id = "unknown";
name = "unknown";
emailAddress = "unknown@monash.edu.au";
address = "unknown";
phoneNumber = "00000000";
}
public Contact(String newId, String newName, String newEmailAddress, String newAddress,
String newPhoneNumber)
{
// initialise instance variables
if(!setId(newId))
id = "unknown";
if(!setName(newName))
name = "unknown";
if(!setEmailAddress(newEma ilAddress) );
emailAddress = "unknown";
if(!setAddress(newAddress) )
address = "unknown";
if(!setPhoneNumber(newPhon eNumber))
phoneNumber = "00000000";
}
/**
* InvalidBlank method: checks that no fields have been left
* blank or empty
*/
public boolean invalidBlank(String aString)
{
if (aString.trim().length()!= 0)
return true;
return false;
}
/**
* This method retrieves the id of the Contact
*
* @return a String representing the Contact's id
*/
public String getId()
{
return id;
}
/**
* This method sets the id of the contact
*
* @param newId the string holding the id of the contact
* @return a boolean signifying that the id has been set
*/
public boolean setId(String newId)
{
if(invalidBlank(newId))
{
id = newId;
return true;
}
return false;
}
/**
* This method retrieves the name of the Contact
*
* @return a String representing the Contact's name
*/
public String getName()
{
return name;
}
/**
* This method sets the name of the Contact
*
* @param newName the string holding the name of the Contact
* @return a boolean signifying that the name has been set
*/
public boolean setName(String newName)
{
if(invalidBlank(newName))
{
name = newName;
return true;
}
return false;
}
/**
* This method retrieves the emailAddress of the Contact
*
* @return a String representing the Contact's emailAddress
*/
public String getEmailAddress()
{
return emailAddress;
}
/**
* This method sets the name of the Contact
*
* @param newDescription the string holding the Description of the booker
* @return a boolean signifying that the Description has been set
*/
public boolean setEmailAddress(String newEmailAddress)
{
if(invalidBlank(newEmailAd dress))
{
emailAddress = newEmailAddress;
return true;
}
return false;
}
/**
* This method retrieves the street address of the Booker
*
* @return a String representing the Booker's street address
*/
public String getAddress()
{
return address;
}
/**
* This method sets the address of the booker
*
* @param newAddress the string holding the address of the booker
* @return a boolean signifying that the address has been set
*/
public boolean setAddress(String newAddress)
{
if(invalidBlank(newAddress ))
{
address = newAddress;
return true;
}
return false;
}
public String getPhoneNumber()
{
return phoneNumber;
}
public boolean setPhoneNumber(String newPhoneNumber)
{
if(validPhoneNumber(newPho neNumber))
{
phoneNumber = newPhoneNumber;
return true;
}
return false;
}
/**
* this method validates the name so as it is not empty or balnk
*/
public boolean validPhoneNumber(String newPhoneNumber)
{
if(newPhoneNumber.trim().l ength() <= 8 && newPhoneNumber.trim().leng th() >= 10)
{
System.out.println("Phone Number must contain 8-10 digits");
return false;
}
return true;
}
public abstract void print();
}
Student
import java.util.*;
import java.io.*;
public class Student extends Contact
{
public Student()
{
// initialise instance variables
super("unknown", "unknown", "unknown@monash.edu.au", "unknown", "00000000" );
}
Student(String id, String name, String emailAddress, String address,
String phoneNumber)
{
super (id, name, emailAddress, address, phoneNumber);
}
public void print()
{
System.out.println();
}
}
Unit
import java.io.*;
import java.util.*;
public class Unit
{
// instance variables - replace the example below with your own
private String unitCode;
private String unitName;
private Map unitAssessments;
private String unitLecturer;
private String unitDescription;
public Unit()
{
// initialise instance variables
unitCode = "cse0000";
unitName = "unknown";
unitLecturer = "unknown";
unitDescription = "unknown";
unitAssessments = new TreeMap();
}
public Unit(String unitCode, String unitName, String unitLecturer, String unitDescription)
{
this.unitCode = unitCode;
this.unitName = unitName;
this.unitLecturer = unitLecturer;
this.unitDescription = unitDescription;
unitAssessments = new TreeMap();
}
public void addUnitAssessments(String unitCode, int unitAssessments)
{
Integer nF = new Integer(unitAssessments);
this.unitAssessments.put(u nitCode,nF );
}
private void printUnitAssessments()
{
Set keys = unitAssessments.keySet();
Iterator kI = keys.iterator();
while(kI.hasNext())
{
String type = (String)kI.next();
Integer numP = (Integer)unitAssessments.g et(type);
System.out.println(numP + " :" + type);
}
}
public void setUnitCode(String newUnitCode)
{
unitCode = newUnitCode;
}
public String getUnitCode()
{
return unitCode;
}
public void setUnitName(String newUnitName)
{
unitName = newUnitName;
}
public String getUnitName()
{
return unitName;
}
public void setUnitDescription(String newUnitDescription)
{
unitDescription = newUnitDescription;
}
public String getUnitDescription()
{
return unitDescription;
}
public void printUnit()
{
System.out.println("Unit Code: " + unitCode + "\n" + "Unit Name: " + unitName + "\n" + "Number Of Assessments: ");
printUnitAssessments();
}
}
i have included some of the classes i have started on. Where im stuck really is where to use TreeSet, HashMap, ArrayList (bc they r the three we have to use) & how the classes relate to each other. So really just a hand with the base classes. Any help or pointers would be so very much appreciated. I have the classes at the moment so that TheStudentManager controls the program. Unit Class. Contact Class (abstract) of which Student & Staff extend. Assessment (abstract) of which Test and Assignment extend.
thanks
matt
Assessment class:
import java.util.*;
import java.io.*;
public abstract class Assessment
{
// instance variables - replace the example below with your own
protected String time;
protected String date;
public Assessment()
{
time = "unknown";
date = "unknown";
}
public Assessment(String date, String time)
{
this.date = date;
this.time = time;
}
public String getDate()
{
return date;
}
public void setDate(String newDate)
{
date = newDate;
}
public String getTime()
{
return time;
}
public void setTime(String newTime)
{
time = newTime;
}
public abstract void print();
}
Test
import java.util.*;
import java.io.*;
public class Test extends Assessment
{
private String duration;
private String topics;
public Test()
{
// initialise instance variables
super("unknown", "unknown");
duration = ("3 hours");
topics = ("why we hate java");
}
Test(String date, String time, String newDuration, String newTopics)
{
super (date, time);
duration = newDuration;
topics = newTopics;
}
public void setDuration(String newDuration)
{
duration = newDuration;
}
public void setTopics(String newTopics)
{
topics = newTopics;
}
public void print()
{
System.out.println("" + "\n" +
"time : " + time + "\n" +
"duration" + duration + "\n");
}
}
Assignment
import java.util.*;
import java.io.*;
public class Assignment extends Assessment
{
private String dateDue;
private String subject;
public Assignment()
{
// initialise instance variables
super("unknown", "unknown");
subject = ("Java");
dateDue = ("30th Oct");
}
Assignment(String date, String time, String newDateDue, String newSubject)
{
super (date, time);
dateDue = newDateDue;
subject = newSubject;
}
public void setSubject(String newSubject)
{
subject = newSubject;
}
public void setDateDue(String newDateDue)
{
dateDue = newDateDue;
}
public void print()
{
System.out.println("" + "\n" +
"time : " + time + "\n" +
"subject" + subject + "\n");
}
}
Contact
import java.util.*;
import java.io.*;
public abstract class Contact
{
// instance variables - replace the example below with your own
protected String id;
protected String name;
protected String emailAddress;
protected String address;
protected String phoneNumber;
public Contact()
{
id = "unknown";
name = "unknown";
emailAddress = "unknown@monash.edu.au";
address = "unknown";
phoneNumber = "00000000";
}
public Contact(String newId, String newName, String newEmailAddress, String newAddress,
String newPhoneNumber)
{
// initialise instance variables
if(!setId(newId))
id = "unknown";
if(!setName(newName))
name = "unknown";
if(!setEmailAddress(newEma
emailAddress = "unknown";
if(!setAddress(newAddress)
address = "unknown";
if(!setPhoneNumber(newPhon
phoneNumber = "00000000";
}
/**
* InvalidBlank method: checks that no fields have been left
* blank or empty
*/
public boolean invalidBlank(String aString)
{
if (aString.trim().length()!=
return true;
return false;
}
/**
* This method retrieves the id of the Contact
*
* @return a String representing the Contact's id
*/
public String getId()
{
return id;
}
/**
* This method sets the id of the contact
*
* @param newId the string holding the id of the contact
* @return a boolean signifying that the id has been set
*/
public boolean setId(String newId)
{
if(invalidBlank(newId))
{
id = newId;
return true;
}
return false;
}
/**
* This method retrieves the name of the Contact
*
* @return a String representing the Contact's name
*/
public String getName()
{
return name;
}
/**
* This method sets the name of the Contact
*
* @param newName the string holding the name of the Contact
* @return a boolean signifying that the name has been set
*/
public boolean setName(String newName)
{
if(invalidBlank(newName))
{
name = newName;
return true;
}
return false;
}
/**
* This method retrieves the emailAddress of the Contact
*
* @return a String representing the Contact's emailAddress
*/
public String getEmailAddress()
{
return emailAddress;
}
/**
* This method sets the name of the Contact
*
* @param newDescription the string holding the Description of the booker
* @return a boolean signifying that the Description has been set
*/
public boolean setEmailAddress(String newEmailAddress)
{
if(invalidBlank(newEmailAd
{
emailAddress = newEmailAddress;
return true;
}
return false;
}
/**
* This method retrieves the street address of the Booker
*
* @return a String representing the Booker's street address
*/
public String getAddress()
{
return address;
}
/**
* This method sets the address of the booker
*
* @param newAddress the string holding the address of the booker
* @return a boolean signifying that the address has been set
*/
public boolean setAddress(String newAddress)
{
if(invalidBlank(newAddress
{
address = newAddress;
return true;
}
return false;
}
public String getPhoneNumber()
{
return phoneNumber;
}
public boolean setPhoneNumber(String newPhoneNumber)
{
if(validPhoneNumber(newPho
{
phoneNumber = newPhoneNumber;
return true;
}
return false;
}
/**
* this method validates the name so as it is not empty or balnk
*/
public boolean validPhoneNumber(String newPhoneNumber)
{
if(newPhoneNumber.trim().l
{
System.out.println("Phone Number must contain 8-10 digits");
return false;
}
return true;
}
public abstract void print();
}
Student
import java.util.*;
import java.io.*;
public class Student extends Contact
{
public Student()
{
// initialise instance variables
super("unknown", "unknown", "unknown@monash.edu.au", "unknown", "00000000" );
}
Student(String id, String name, String emailAddress, String address,
String phoneNumber)
{
super (id, name, emailAddress, address, phoneNumber);
}
public void print()
{
System.out.println();
}
}
Unit
import java.io.*;
import java.util.*;
public class Unit
{
// instance variables - replace the example below with your own
private String unitCode;
private String unitName;
private Map unitAssessments;
private String unitLecturer;
private String unitDescription;
public Unit()
{
// initialise instance variables
unitCode = "cse0000";
unitName = "unknown";
unitLecturer = "unknown";
unitDescription = "unknown";
unitAssessments = new TreeMap();
}
public Unit(String unitCode, String unitName, String unitLecturer, String unitDescription)
{
this.unitCode = unitCode;
this.unitName = unitName;
this.unitLecturer = unitLecturer;
this.unitDescription = unitDescription;
unitAssessments = new TreeMap();
}
public void addUnitAssessments(String unitCode, int unitAssessments)
{
Integer nF = new Integer(unitAssessments);
this.unitAssessments.put(u
}
private void printUnitAssessments()
{
Set keys = unitAssessments.keySet();
Iterator kI = keys.iterator();
while(kI.hasNext())
{
String type = (String)kI.next();
Integer numP = (Integer)unitAssessments.g
System.out.println(numP + " :" + type);
}
}
public void setUnitCode(String newUnitCode)
{
unitCode = newUnitCode;
}
public String getUnitCode()
{
return unitCode;
}
public void setUnitName(String newUnitName)
{
unitName = newUnitName;
}
public String getUnitName()
{
return unitName;
}
public void setUnitDescription(String newUnitDescription)
{
unitDescription = newUnitDescription;
}
public String getUnitDescription()
{
return unitDescription;
}
public void printUnit()
{
System.out.println("Unit Code: " + unitCode + "\n" + "Unit Name: " + unitName + "\n" + "Number Of Assessments: ");
printUnitAssessments();
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
public Assignment()
{
// initialise instance variables
super("unknown", "unknown");
subject = ("Java");
dateDue = ("30th Oct");
}
>>
That's not right. You wouldn't hard-code a subject and dateDue like that. Let the other ctor set these