Jobs Simply

How do I use fileReader to find a string in a text file?

I am working on an appointment book program for my java class, I am not sure how I am going to go about this yet but here is my idea: Use a filewriter to put the appointments into one text file, each appointment prefixed by a string of numbers. I plan on using the filereader to find where the string of numbers is in the file and print out whatever is after it. I need to have it be able to find more than one instance though, because the user will be able to have multiple appointments on the same day. Any ideas? Here is the assignment if it helps: Implement an On-Line Appointment Book Based on the Following Specifications: A. Implement a superclass called Appointment and subclasses OneTime, Daily, Weekly, and Monthly. An Appointment has a description (for example, “Meet with interviewer about job”) and a date and time. Write a method occursOn(int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches. Then, in a TestAppointment class, fill an array of Appointment objects with a mixture of different kinds of appointments. Ask a user to enter a date and print out all appointments that occur on that date. B. Improve your Appointment program by giving the user the option to add new Appointments. The user must specify the type of the appointment, the description, and the date and time. C. Improve the program further by letting the user save the appointment data to a file and reload the data from a file. The saving part is straightforward: make a method saveApptData. In it, save the type, description, date, and time to a file. The loading part is not so easy. First determine the type of the appointment to be loaded, create an object of that type, and then call a loadApptData method to load the data. As always, the source code must be indented properly and contain comments that describe important parts of the algorithm.

Public Comments

  1. Since your program already has Objects, I would write methods in Appointment like so... public Appointment findDate( String date ) { if( this.date = date ) return this; return null; } public Appointment findDesc( String description ) { if( this.description = description ) return this; return null; } TestAppointment has a datastore, such as ArrayList<Appointment> alist = ArrayList<Appointment>(). You go through that alist Appointment detail = null; for( Appointment a : alist ) { if( a.description( "dentist" ) != null ) detail = a; break; Use Scanner with FileReader to re-make your Appointment Objects
Powered by Yahoo! Answers