Question Details

[answered] Michael Lackey Date: 12/ 4 / 16 The Calendar Program The pu


Hello I need help with my Java code I'm not sure what it is I'm doing wrong. Any input would be appreciated I'm sure I'm missing something small. Please let me know what you think.?



COMP 274

 

Week 6 iLab assignment

 

By: Michael Lackey

 

Date: 12/ 4 / 16

 

The Calendar Program

 

The purpose of this lab is to give you a chance to use some of the data stream tools we have been

 

discussing in a simple application. The assignment is to write a calendar application which allows the

 

user to select a date, and either retrieve a previously stored calendar entry, or save a calendar entry. Your program should present a GUI interface which allows the user to specify the month, day, and year

 

of the calendar entry. The GUI should also have a text area for displaying and editing a particular entry. It

 

will also need two buttons, one for saving an entry, and the other for retrieving an entry. Required program elements:

 

1

 

2

 

3

 

4 5

 

6

 

7

 

8 Your user interface must allow the user to enter the month, day, and year. You can do this using

 

text fields for input, or you can use ComboBoxes if you feel adventurous.

 

The only GUI components which create events that your program needs to handle are the save

 

and retrieve buttons.

 

Don?t go overboard making your GUI beautiful! We are just looking for basic functionality here!

 

You must have a separate class which manages the calendar data. You will have a minimum of

 

three classes in your application, a user interface class, the calendar manager class, and a

 

calendar test class. The user interface class creates an instance of the calendar manager in its

 

constructor and stores it in a member variable.

 

The calendar manager must provide methods which support saving a specific calendar entry and

 

retrieving a specific calendar entry. The interfaces must be defined to only pass a single day?s

 

calendar entry across the interface.

 

The calendar manager must store calendar data into files according to month+year. That is, the

 

calendar entries for December 2011 must all be stored in the same file.

 

The calendar manager must use ObjectInput/OutputStreams to read/write data from/to files.

 

The calendar manager will use an array to store String objects. The position of a String in this

 

array corresponds to the calendar entry for a specific day.

 

The save method of the calendar manager will need to determine if a file exists for the

 

requested month and year. If so, the object from that file must be read into the calendar

 

manager. Otherwise, the calendar manager must create an empty String array. The new entry 9 must be saved to the appropriate day?s location in the array. The modified array must be saved

 

to the appropriate file.

 

The retrieve method of the calendar manager will need to determine if a file exists for the

 

requested month and year. If not, return an error string indicating that there is no such entry. If

 

the file exists, read the String array from the file and locate the requested day?s entry. If this

 

entry is null, return an error string indicating that there is no such entry, otherwise return the

 

entry. Take screen shots of the output of your program. Paste the screen shots and your source code for your

 

programs into a Word document. Submit your Word document. Outputs:

 

Source Code:

 

import java.awt.*;

 

import java.awt.event.ActionEvent;

 

import java.awt.event.ActionListener;

 

import javax.swing.*;

 

public class userInterface extends JFrame implements ActionListener

 

{

 

private static final long serialVersionUID = 1L;

 

public CalendarManager calendar;

 

public JTextField Month, day, year;

 

public JScrollPane Content;

 

public JTextArea text;

 

public JButton get, save;

 

public JLabel m, d, y;

 

public userInterface()

 

{

 

super("Calendar manager");

 

setLayout(new FlowLayout());

 

m = new JLabel("MONTH");

 

d = new JLabel("DAY");

 

y = new JLabel("YEAR");

 

Month = new JTextField(12);

 

day = new JTextField(12); year = new JTextField(12);

 

add(m);

 

add(Month);

 

add(d);

 

add(day);

 

add(y);

 

add(year);

 

text = new JTextArea(10, 30);

 

add(new JScrollPane(text));

 

get = new JButton("GET");

 

add(get);

 

get.addActionListener((ActionListener) this);

 

save = new JButton("SAVE");

 

add(save);

 

save.addActionListener(this);

 

}

 

public void actionPerformed(ActionEvent e)

 

{

 

CalendarManager c=new CalendarManager();

 

if(e.getSource() == get)

 

{

 

text.setText(c.getEntry(Month.getText(), day.getText(),

 

year.getText()));

 

}

 

if(e.getSource() == save)

 

{

 

text.setText(c.saveEntry(Month.getText(), day.getText(),

 

year.getText(), text.getText()));

 

}

 

}

 

}

 

import java.io.File;

 

import java.io.FileInputStream;

 

import java.io.FileOutputStream;

 

import java.io.IOException;

 

import java.io.ObjectInputStream;

 

import java.io.ObjectOutputStream; import javax.swing.JFileChooser;

 

public class CalendarManager

 

{

 

public String array;

 

public CalendarManager()

 

{

 

String fname="base.dir";

 

File dir = new File(fname);

 

if (!dir.exists())

 

dir.mkdir();

 

JFileChooser filechooser = new JFileChooser();

 

filechooser.setCurrentDirectory(dir);

 

filechooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

 

}

 

public String saveEntry(String month, String day, String year, String entry)

 

{

 

getFile(month, year);

 

try

 

{

 

array[Integer.parseInt(day) - 1] = entry;

 

FileOutputStream f;

 

ObjectOutputStream fop;

 

File file;

 

file = new File(month + " " + year + ".dat");

 

f = new FileOutputStream(file);

 

fop = new ObjectOutputStream(f);

 

fop.writeObject(array);

 

fop.close();

 

return "Success";

 

}

 

catch (Exception e)

 

{

 

return "Error";

 

}

 

}

 

private void getFile(String month, String year)

 

{

 

try {

 

File file = new File(month + " " + year + ".dat");

 

if (!file.exists())

 

{

 

file.createNewFile();

 

array = new String[31];

 

}

 

else

 

{

 

FileInputStream fw = new

 

FileInputStream(file.getAbsoluteFile());

 

ObjectInputStream bw = new

 

ObjectInputStream(fw);

 

array = (String) bw.readObject();

 

bw.close();

 

}

 

}

 

catch (IOException e)

 

{

 

array = new String[31];

 

e.printStackTrace();

 

}

 

catch (ClassNotFoundException e)

 

{

 

array = new String[31];

 

e.printStackTrace();

 

}

 

}

 

public String getEntry(String month, String day, String year)

 

{

 

getFile(month, year);

 

String data = array[Integer.parseInt(day) - 1];

 

if (data != null)

 

{

 

return data;

 

}

 

return "entry does not exist"; }

 

}

 

import javax.swing.JFrame;

 

public class CalendarTest

 

{

 

public static void main(String args)

 

{

 

userInterface uI = new userInterface();

 

uI.setSize(400, 400);

 

uI.setVisible(true);

 

uI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

 

}

 

}

 


Solution details:
STATUS
Answered
QUALITY
Approved
ANSWER RATING

This question was answered on: Sep 18, 2020

PRICE: $15

Solution~0001013823.zip (25.37 KB)

Buy this answer for only: $15

This attachment is locked

We have a ready expert answer for this paper which you can use for in-depth understanding, research editing or paraphrasing. You can buy it or order for a fresh, original and plagiarism-free copy from our tutoring website www.aceyourhomework.com (Deadline assured. Flexible pricing. TurnItIn Report provided)

Pay using PayPal (No PayPal account Required) or your credit card . All your purchases are securely protected by .
SiteLock

About this Question

STATUS

Answered

QUALITY

Approved

DATE ANSWERED

Sep 18, 2020

EXPERT

Tutor

ANSWER RATING

GET INSTANT HELP/h4>

We have top-notch tutors who can do your essay/homework for you at a reasonable cost and then you can simply use that essay as a template to build your own arguments.

You can also use these solutions:

  • As a reference for in-depth understanding of the subject.
  • As a source of ideas / reasoning for your own research (if properly referenced)
  • For editing and paraphrasing (check your institution's definition of plagiarism and recommended paraphrase).
This we believe is a better way of understanding a problem and makes use of the efficiency of time of the student.

NEW ASSIGNMENT HELP?

Order New Solution. Quick Turnaround

Click on the button below in order to Order for a New, Original and High-Quality Essay Solutions. New orders are original solutions and precise to your writing instruction requirements. Place a New Order using the button below.

WE GUARANTEE, THAT YOUR PAPER WILL BE WRITTEN FROM SCRATCH AND WITHIN YOUR SET DEADLINE.

Order Now