Java Reference
In-Depth Information
4.5 Making use of class Results shown below, repeat the above program, this time
writing/reading objects of class Result . (When displaying the names and marks
that have been read, of course, you must make use of the methods of class
Result .) Once again, redirect initial input to come from your text fi le.
class Result implements java.io.Serializable
{
private String surname;
private int mark;
public Result(String name, int score)
{
surname = name;
mark = score;
}
public String getName()
{
return surname;
}
public void setName(String name)
{
surname = name;
}
public int getMark()
{
return mark;
}
public void setMark(int score)
{
if ((score>=0) && (score<=100))
mark = score;
}
}
4.6 Using class Personnel from Sect. 4.9 , create a simple GUI-based program
called ChooseSaveFile.java that has no components, but creates an instance of
itself within main and has the usual window-closing code (also within main ).
Within the constructor for the class, declare and initialise an array of three
Personnel objects (as in program ArrayListSerialise.java from Sect. 4.9 ) and
write the objects from the array to a fi le (using an ObjectOutputStream ). The
name and location of the fi le should be chosen by the user via a JFileChooser
object. Note that you will need to close down the (empty) application window
by clicking on the window close box.
Search WWH ::




Custom Search