Q5:
(a) Explain using examples the difference between Data Sink Streams and
Processing Streams.
5 MARKS
(b) Write a Java class called RAFO that uses a RandomAccessFile to store
diary entries of the format [date][diary entry]. For example, "2022-02-
17 Today is windy!", where the quotes illustrate an individual UTF string. Your
program should include the following two methods for writing a diary entry to
and reading a diary entry from the file, respectively:
public void writeDiaryEntry(LocalDate timestamp, String diaryEntry)
public String getDiaryEntry(LocalDate timestamp)
An example of how the class is intended to be used is as follows. This
example would print "Today is dry" to the console:
RAFO raf = new RAFO("mydiary.txt");
LocalDate timestamp = LocalDate.now();
raf.writeDiaryEntry(timestamp, "Today is sunny");
LocalDate anothertimestamp = LocalDate.parse("2022-01-03");
raf.writeDiaryEntry(anothertimestamp, "Today is dry");
LocalDate andanothertimestamp = LocalDate.parse("2022-04-12");
raf.writeDiaryEntry(andanothertimestamp, "Today is windy!");
System.out.println(raf.getDiaryEntry(anothertimestamp));
20 MARKS