Last Project -- Need Help, Please

Okay, this is my last project, and I am struggling with it. The specification we were given was to write a program that reads in a file of dates and outputs the dates in descending order, using a priority queue. The PriorityQueue should implement the PriorityQueueInterface interface, and should implements a priority queue using a singly linked list. The list should be maintained in sorted order. This implementation should not use a heap.
I have the code built, but when I run it is not reading my dates fully, and I get an error message. The LinkList is already built for us, but here is the rest of my code. First I input from my dates.txt:
11/12/2000
04/04/2004
01/02/1998
import java.io.*;
public class DateDriver {
   public static void main(String[] args) throws IOException {
      PriorityQueue pq = new PriorityQueue();
      // ... read all Date objects from the file and enqueue them in the pq object
      BufferedReader in = new BufferedReader (new FileReader("C:/Users/April/Desktop/UMUC/CMIS241/Project4/Dates.txt"));
      Date date = new Date();
      date.input(in);
      while (!date.isNull()){
           pq.add(date);
           date = new Date();
           date.input(in);
           System.out.println(date);
      // ... dequeue the pq object and display the Date objects
      System.out.println("The dates in descending order are: ");
      while (!pq.isEmpty()){
           date = (Date) pq.dequeue();
           date.output(System.out);
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintStream;
public class Date implements InOutputable, Comparable {
   // ... define monthNames as a ?static final? array of String objects
   //  initialize the array with the first 3 characters of each month
     static final String[] monthNames = {null, "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",
          "Oct", "Nov", "Dec"};
   // ... define the instance variables of class Date, i.e. day, month, year
     private String monthAbr, date;
     private int month, day, year;
   // ... define the default constructor (initializes the instance variables to zero)
     public Date(){
          this.date = "";
          month = 00;
          day = 00;
          year = 0000;
   // ... define the method toString
   //     This method should return the corresponding Date string in the following format: Nov, 11, 2006
     public String toString() {
           return (monthAbr + ", " + day + ", " + year);
   // ... define the methods specified by the interface InOutputable
public boolean equals(InOutputable other) {
     Date otherDate = (Date) other;
     if (month == otherDate.month && day == otherDate.day && year == otherDate.year)
          return true;
     else
          return false;
public void input(BufferedReader in) throws IOException {
     date = in.readLine();
     if (date == null)
          return;
     month = Integer.parseInt(date.substring(0, 2));
     day = Integer.parseInt(date.substring(3, 5));
     year = Integer.parseInt(date.substring(6, 10));
public boolean isNull() {
     if (month == 0 && day == 0 && year == 0)
          return true;
     else
          return false;
public void output(PrintStream writer) {
     writer.println(toString());
   // ... define the method specified by the interface Comparable
public int compareTo(Object o) {
     Date otherDate = (Date) o;
     if(month == otherDate.month && day == otherDate.day && year == otherDate.year)
          return 0;
     else if (month >= otherDate.month && day >= otherDate.day && year >= otherDate.year)
          return 1;
     else
          return -1;
public class PriorityQueue implements PriorityQueueInterface {   
   private RefSortedList lst = new RefSortedList();
   // ... define the methods specified by the interface PriorityQueueInterface
public Comparable dequeue() throws EmptyQueue {
     return null;
public void enqueue(Comparable key) throws FullQueue {
public boolean isEmpty() {
     return false;
   // ... Use the lst object (by invoking list specific methods on it) when
   //     defining the PriorityQueueInterface methods.
   //     For example, method enqueue should be implemented by invoking list method add.
public void add(Date date){
     lst.add(date);
public void remove(Date date){
     lst.remove(date);
}My output:
Exception in thread "main" java.lang.NullPointerException
     at DateDriver.main(DateDriver.java:27)
null, 4, 2004
null, 2, 1998
null, 0, 0
The dates in descending order are:
Can anybody please point me in the right direction? I know I am missing something, but I am unable to pinpoint it. I don't understand why the date.output(System.out) is throwing a null pointer exception. I am still working, but I thought maybe a fresh pair of eyes would help me.

Dates implement Comparable... no need to sort them yourself
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
LinkedList<Date> dtes = new LinkedList<Date>();
BufferedReader in = new BufferedReader (new FileReader("C:/dates.txt"));
while (in.read()>0){
dtes.add(sdf.parse(in.readLine()));
}Edited by: wpp289 on Dec 11, 2008 1:27 PM

Similar Messages

  • My MacBook Pro has problem in iphoto,, I cant open it,, I need help please,,,,

    My MacBook Pro has problem in iphoto,, I cant open it,, I need help please,,,,

    Last login: Sun Apr 22 19:11:11 on ttys000
    Marlons-MacBook-Pro:~ ryanmnhs$ ls -la ~/Library/LaunchAgents
    total 40
    drwx------   7 ryanmnhs  staff   238  5 Nov 23:09 .
    drwx------@ 48 ryanmnhs  staff  1632 13 Jan 09:53 ..
    -rw-r--r--   1 ryanmnhs  staff   574 24 Oct 22:29 com.adobe.ARM.202f4087f2bbde52e3ac2df389f53a4f123223c9cc56a8fd83a6f7ae.plist
    -rw-r--r--   1 ryanmnhs  staff   618 22 Oct  2011 com.apple.AddressBook.ScheduledSync.PHXCardDAVSource.BAF380D0-E780-4E82-86BF-77 2440AB4936.plist
    -rw-r--r--   1 ryanmnhs  staff   895  4 Sep  2011 [email protected].plist
    -rw-r--r--   1 ryanmnhs  staff   802 21 Mar 12:56 com.facebook.videochat.ryanmnhs.plist
    -rw-r--r--@  1 ryanmnhs  staff   805  6 Sep  2011 com.google.keystone.agent.plist
    Marlons-MacBook-Pro:~ ryanmnhs$ 
    ,,,,,,,,THIS IS THE RESULT,, WHAT DOES THIS MEAN? HOW CAN I FIX MY PROBLEM? UP TO THIS DATE MY WORD, EXCEL AND POWERPOINT STILL DONT WORK!!!!PLEASE HELP ME, ANYONE? THANK YOU...

  • HT1212 My Ipad is disabled by wrong password and I have tried to reset and restore a few times with no success. Now I-tunes won't even recognize the I-pad in recovery mode. I need help please.

    My Ipad is disabled by wrong password and I have tried to reset and restore a few times with no success. Now I-tunes won't even recognize the I-pad in recovery mode. I need help please.

    If the iPad was running iOS 7,  iCloud: Find My iPhone Activation Lock in iOS 7
    http://support.apple.com/kb/HT5818
    How can I unlock my iPad if I forgot the passcode?
    http://www.everymac.com/systems/apple/ipad/ipad-troubleshooting-repair-faq/ipad- how-to-unlock-open-forgot-code-passcode-password-login.html
    iOS: Device disabled after entering wrong passcode
    http://support.apple.com/kb/ht1212
    How can I unlock my iPad if I forgot the passcode?
    http://tinyurl.com/7ndy8tb
    How to Reset a Forgotten Password for an iOS Device
    http://www.wikihow.com/Reset-a-Forgotten-Password-for-an-iOS-Device
    Using iPhone/iPad Recovery Mode
    http://ipod.about.com/od/iphonetroubleshooting/a/Iphone-Recovery-Mode.htm
    Saw this solution on another post about an iPad in a school environment. Might work on your iPad so you won't lose everything.
    ~~~~~~~~~~~~~
    ‘iPad is disabled’ fix without resetting using iTunes
    Today I met my match with an iPad that had a passcode entered too many times, resulting in it displaying the message ‘iPad is disabled – Connect to iTunes’. This was a student iPad and since they use Notability for most of their work there was a chance that her files were not all backed up to the cloud. I really wanted to just re-activate the iPad instead of totally resetting it back to our default image.
    I reached out to my PLN on Twitter and had some help from a few people through retweets and a couple of clarification tweets. I love that so many are willing to help out so quickly. Through this I also learned that I look like Lt. Riker from Star Trek (thanks @FillineMachine).
    Through some trial and error (and a little sheer luck), I was able to reactivate the iPad without loosing any data. Note, this will only work on the computer it last synced with. Here’s how:
    1. Configurator is useless in reactivating a locked iPad. You will only be able to completely reformat the iPad using Configurator. If that’s ok with you, go for it – otherwise don’t waste your time trying to figure it out.
    2. Open iTunes with the iPad disconnected.
    3. Connect the iPad to the computer and wait for it to show up in the devices section in iTunes.
    4. Click on the iPad name when it appears and you will be given the option to restore a backup or setup as a new iPad (since it is locked).
    5. Click ‘Setup as new iPad’ and then click restore.
    6. The iPad will start backing up before it does the full restore and sync. CANCEL THE BACKUP IMMEDIATELY. You do this by clicking the small x in the status window in iTunes.
    7. When the backup cancels, it immediately starts syncing – cancel this as well using the same small x in the iTunes status window.
    8. The first stage in the restore process unlocks the iPad, you are basically just cancelling out the restore process as soon as it reactivates the iPad.
    If done correctly, you will experience no data loss and the result will be a reactivated iPad. I have now tried this with about 5 iPads that were locked identically by students and each time it worked like a charm.
    ~~~~~~~~~~~~~
    Try it and good luck. You have nothing more to lose if it doesn't work for you.
     Cheers, Tom

  • How can I add a new Template to My Templates in Pages? I've read most of the discussions on the subject but it doesn't work for me. By the time I reach the Templates folder, I only see templates for Numbers and not for Pages. Need help, please.  Thanks

    How can I add a new Template to My Templates in Pages? I've read most of the discussions on the subject but it doesn't work for me. By the time I reach the Templates folder, I only see templates for Numbers and not for Pages. Need help, please.  Thanks

    Si vous avez utilisé la commande Save As Template depuis Pages, il y a forcément un dossier
    iWork > Pages
    contenant Templates > My Templates
    comme il y a un dossier
    iWork > Numbers
    contenant Templates > My Templates
    Depuis le Finder, tapez cmd + f
    puis configurez la recherche comme sur cette recopie d'écran.
    puis lancez la recherche.
    Ainsi, vous allez trouver vos modèles personnalisés dans leur dossier.
    Chez moi, il y en a une kyrielle en dehors des dossiers standards parce que je renomme wxcvb.template quasiment tous mes documents Pages et wxcvb.nmbtemplate à peu près tous mes documents Numbers.
    Ainsi, quand je travaille sur un document, je ne suis pas ralenti par Autosave.
    Désolé mais je ne répondrai plus avant demain.
    Pour moi il est temps de dormir.
    Yvan KOENIG (VALLAURIS, France)  mercredi 23 janvier 2011 22:39:28
    iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.2
    My iDisk is : <http://public.me.com/koenigyvan>
    Please : Search for questions similar to your own before submitting them to the community

  • HT1222 I am trying like **** to download itunes 10.6.3 (64 bit - Windows 7) and I keep getting "the installer was interrupted before the requested operations for iTunes could be completed.  Your systems has not been modified."  I NEED HELP, PLEASE!

    I am trying like **** to download itunes 10.6.3 (64 bit - Windows 7) and I keep getting "the installer was interrupted before the requested operations for iTunes could be completed.  Your systems has not been modified."  I NEED HELP, PLEASE!

    I got it figured out myself... yaaaaay for me!

  • After my iphone4S update to 7.0.6, it have a problem that keep searching network then no service show on display. Can't call. I have try check sim card, reset network settings, and restore my iphone. Still not working at all. Need help please.

    After my iphone4S update to 7.0.6, it have a problem that keep searching network then no service show on display. Can't call. I have try check sim card, reset network settings, and restore my iphone. Still not working at all. Need help please.Urgent.TQ

    Izit software or hardware? Confuse:(
    Only can use wifi now.
    Any way thanks guys for ur suggestion:) amishcake and simes

  • I have an ipod touch that continues to have a black screen with the white apple on it. It won't shut off and is completely frozen. This happened when we tried to restore it last night. Help please!!

    I have an ipod touch that continues to have a black screen with the white apple on it. It won't shut off and is completely frozen. This happened when we tried to restore it last night. Help please!!

    Try:
    - iOS: Not responding or does not turn on
    - Also try DFU mode after try recovery mode
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings
    - If not successful and you can't fully turn the iOS device fully off, let the battery fully drain. After charging for an least an hour try the above again.
    - If still not successful that indicates a hardware problem and an appointment at the Genius Bar of an Apple store is in order.
    Apple Retail Store - Genius Bar

  • Bought a new macbook and want to manually manage music onto my iphone 4s but when i click 'manually manage' and then 'apply' i get the message saying it will erase everything already on there. Need help please!

    Bought a new macbook and want to manually manage music onto my iphone 4s (as it is already full of music from old windows laptop) but when i click 'manually manage' and then 'apply' i get the message saying it will erase everything already on there. Need help please!

    Before you sync your iPhone make sure that all the music that was synced to your phonereviously has been copied to your iTunes on the new MacBook Pro. Then when you connect your phone you will be able to either sync all music or select only those playlists that you want on the phone.

  • HT4314 Hi i need help please i been playing clash of clans over 13 months. And today o realise what someone using my game Centra. Someone playing on my game Clash of Clans. I been change my Apple ID password, email, but doesn't work. Then I playing game I

    Hi i need help please i been playing clash of clans over 13 months. And today o realise what someone using my game Centra. Someone playing on my game Clash of Clans. I been change my Apple ID password, email, but doesn't work. Then I playing game I can see what someone else trying connecting to my game And I don't know what to do.So if you can help me please? I don't wanna lose my game.

    Contact iTunes
    Contact iTunes

  • Hi i need help please i been playing clash of clans over 13 months. And today o realise what someone using my game Centra. Someone playing on my game Clash of Clans. I been change my Apple ID password, email, but doesn't work. Then I playing game I can se

    Hi i need help please i been playing clash of clans over 13 months. And today o realise what someone using my game Centra. Someone playing on my game Clash of Clans. I been change my Apple ID password, email, but doesn't work. When I playing game I can see what someone else trying connecting to my game And I don't know what to do.So if you can help me please? I don't wanna lose my game. 

    Hello Vaidas Vaidas,
    It sounds like you are noticing someone else is accessing your Clash of Clans data by playing the game and you have tried to reset your Apple ID password. If you are following the steps outlined in this article:
    Apple ID: Changing your password
    http://support.apple.com/kb/ht5624
    What is preventing you from changing your password? Any error messages or prompts?
    Thank you for using Apple Support Communities.
    All the best,
    Sterling

  • I dont know how i got my photos to my ipod touch from my pc and now i wanna delete them but couldn't. so need help. please let me know.

    i dont know how i got my photos to my ipod touch from my pc and now i wanna delete them but couldn't. so need help. please let me know.

    To turn off auto sync - launch iTunes and go to Edit>Preferences>Devices - check the box at the bottom that says - Prevent iPod, iPhones and iPads from syncing automatically. Click OK and then quit iTunes.
    Connect your iDevice to your PC.
    Launch iTunes,
    Click on the device name on the left side of the iTunes Window.
    Click on the Photos Tab in the iTunes window on the right.
    Untick all of the photos or albums that you want to remove.
    Click on Apply in the lower right corner of iTunes
    If you untick or uncheck the Sync Photos heading and then click Apply it will remove all of the photos from the device when it syncs. In this screenshot - I have only certain albums and events selected to sync.

  • My iPhone 6 can't find my macbook pro on the airdrop list, although everything is in place, bluetooth, wi fi gets, need help please ?

    My iPhone 6 can't find my macbook pro on the airdrop list, although everything is in place, bluetooth, wi fi gets, need help please ?

    Dear Niel, thank you but my mac is (MacBook Pro (Retina, 15-inch, Early 2013).
    and i can send from it to my iPhone , but not vice versa

  • After many months of non-use, when I opened Photoshop CS4 Extended, I got an error message 148.3.  "Licensing for this product has stopped working."  I need help, please.

    After many months of non-use, when I tried to open Photoshop CS4 Extended, I got an error message 148.3.  "Licensing for this product has stopped working."  I need help, please.

    Error "Licensing has stopped working" | Windows
    Error "Licensing has stopped working" | Mac OS
    Mylenium

  • HT201413 I need help please!!!!! My iPhone 4 s won't charge!!!!! I get error message 21. How can I get around this.

    I need help please I keep getting error messega 21 when i try uploading my iPhone 4 s!!!!!!!!! omg some one please tell me if and how to fix this please. thank you!!!

    Hopefully this link will help you: http://support.apple.com/kb/HT2109

  • TS1702 Hello, I,m having problems with Polish spell check. It says in iPnstruction that this App (pages) should show my writing mistakes. Check spell button is on but but check spell is not working. Need help Please.

    Hello, I,m having problems with Polish spell check. It says in iPnstruction that this App (pages) should show my writing mistakes. Check spell button is on but but check spell is not working. Need help Please.

    Hello, I,m having problems with Polish spell check. It says in iPnstruction that this App (pages) should show my writing mistakes. Check spell button is on but but check spell is not working. Need help Please.

Maybe you are looking for

  • 2014 Mac Mini shows pink screen when waking

    I have a 2014 3Ghz i7 mac mini which I have attempted to connect two different Asus monitors via two different HDMI cables in multiple configurations. Regardless of the connection combination when the mac awakes from sleep or from the screensaver (to

  • Wrong aspect ratio when importing photos

    I have done different movies (16:9 format), never had any problems. Since yesterday, I am not able anymore to integrate photos in the right aspect ratio. In the preview they appear with the right ratio. When I integrate them and the rendering starts,

  • Ipad 2 personal hotspot access serious trouble

    I bought an Ipad 2 Wifi only. It can acess wifi network in my house but I can´t conect with my Iphone 4 personal hotspot. It´s very strange because I can have a goood conection with Iphone 4 personal hotspot using my Macbook Pro. Both two gadgets (Ip

  • Importing in flash problem

    This appears when I export from captivate to flash: "A swf animation slide has been imported. The following files must be made available at publish time: myfile_Slide_7_0.swf myfile_Slide_10_0.swf Please make sure you publish the project to "C:/Docum

  • Sender Verification Number e-mail issue.

    I have tried to e-mail photos through adobe e-mail and the system send me a notice that I need to use a "Sender Verification Number" that has been sent to my email address.  However, when I check my e-mail there is no e-mail message.  How do I get th