Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with Problem 2 IO Streams Problem 1: Writ e a program to store multiple memos in a file. Allow a user to

I need help with Problem 2

IO Streams

Problem 1:

Writ

e a program to store multiple memos in a file. Allow a user to enter a topic and the text of a

memo (the text of the memo is stored as a single line and thus cannot contain a

return character).

Store the topic, the date stamp of the memo, and the memo message.

Creating a

java.util.Date

object with no arguments will initialize the

Date

object to the

current time and date. A date stamp is obtained by calling the

Date.toString()

method.

Use a text editor to view the contents of the output and to check that the information is stored

correctly.

Part of the program code has been provided for you:

import . . .

public class MemoPadCreator

{

public static void main(String[] args)

throws FileNotFoundException

{

Date now;

Scanner console = new Scanner(System.in);

System.out.print("Output file: ");

String filename = console.nextLine();

PrintWriter out = . . .;

boolean done = false;

while

(!done)

{

System.out.println("Memo topic (enter

-

1 to end):");

String topic = console.nextLine();

if (topic.equals("

-

1"))

{

done = true;

}

else

{

System.out.println("Memo text:");

String message = console.nextLine();

// Create the new date object and obtain a dateStamp

out.println(topic + "

\

n" + dateStamp + "

\

n" + message);

}

}

// Close the ou

tput file

}

}

Problem 2:

Modify your memo writing program to read multiple memos stored in a text file. Memos are

stored in three lines. The first line is the memo topic, the second line is the date stamp, and the

third line is the memo message. Display the memos

one at a time, and allow the user to choose to

view the next memo (if there is one).

Part of the program code has been provided for you:

. . .

public class MemoPadReader

{

public static void main(String[] args) throws IOException

{

Scanner

console = new Scanner(System.in);

System.out.print("Input file: ");

String inputFileName = console.nextLine();

File inFile = . . .;

Scanner in = new Scanner(inFile);

boolean done = false;

while (in.hasNextLine()

&& !done)

{

String topic = . . .;

String dateStamp = . . .;

String message = . . .;

System.out.println(topic + "

\

n" + dateStamp + "

\

n" + message);

if (. . .) // You should only ask to display

the next memo if

// there are more memos in the file

{

System.out.println("Do you want to read the next memo (y/n)?");

String ans = console.nextLine();

if (ans.equalsIgnoreCase("n"))

{

done = true;

}

}

}

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Online Market Research Cost Effective Searching Of The Internet And Online Databases

Authors: John F. Lescher

1st Edition

0201489295, 978-0201489293

More Books

Students also viewed these Databases questions