Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 15 of 15

Thread: Problems with my HW

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problems with my HW

    Hi everybody I`ve got a Hw in my object oriented course I`ve done all the tasks needed except two those are the ones I need help with,
    Write a GUI application called “MyOrganizer”. Your application should have the following options:
    1. Add a new contact
    2. Read contacts from a “Contacts” file
    3. Save contacts to a “Contacts” file
    4. Display all contacts
    5. Add a new reminder
    6. Display reminders of today (or a given day)
    7. Read reminders from a “Reminders” file
    8. Save reminders to a “Reminders” file
    9. Add a new appointment
    10. Display appointments of the coming week ( or a given week )
    11. Read appointments from an “Appointments” file
    12. Save appointments to an “Appointments” file
    I have problems with step 6 and 10
    I`m using arrayList to add the items needed all I need is a way to display the data at a given day for reminders and at a given week for application.
    Last edited by hws; December 30th, 2011 at 02:28 AM.


  2. #2
    Forum VIP
    Join Date
    Oct 2010
    Posts
    275
    My Mood
    Cool
    Thanks
    32
    Thanked 54 Times in 47 Posts
    Blog Entries
    2

    Default Re: Problems with my HW

    Be more specific! We can't read your mind and know exactly where the errors are, however while there is nothing inherently wrong with using an array list, it may through some OutOfMemoryExceptions if they schedule a lot of appointments (Or have lots of contacts).

  3. #3
    Junior Member
    Join Date
    Dec 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problems with my HW

    I`m just telling u that I used an arrayList so that I can add items so I can achieve steps 1, 5, and 9, my question is how can i create a method to display the results which are the items I have in an array of reminders for example, depending on the year month and week that should be given by the user, and each entry in this array that I already created have a year, month, and day attributes or fields, if you read my question above you would`ve seen that I already clarified that I had a problems with enforcing steps 6 and 10, anyways thanks for tryin to help

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Problems with my HW

    how can i create a method to display the results which are the items I have in an array
    Sounds like you need a loop to go through the array and select the items and data to be displayed.

  5. #5
    Junior Member
    Join Date
    Dec 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problems with my HW

    Norm I already did that, but what I need is to display them at a date given by the user, since each entry have year, month, and day, I used scanner and get methods to compare em and it still didn`t work that`s where I need help I need help at finding a method that can compare the year, month, and day of an entry to the year, month, and day specified by the user, I hope it was clear enough.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Problems with my HW

    a method that can compare the year, month, and day of an entry to the year, month, and day specified by the user,
    Can you show the code that you are having the problems with?
    If you use the Calendar class and its subclass there are methods for working with dates.

  7. #7
    Junior Member
    Join Date
    Dec 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problems with my HW

    public String toString1() {
    String str = "";
    for (int i = 0; i < reminder.size(); i++) {
    str = str + reminder.get(i).toString();
    }
    return str;
    }
    this the code I used to display the data or the results what`s inside the array what I want is for it to work only for the entries in the array that have the same year, month, and day as the year, month and day that`s specified by the user I want a method that do that along with giving the user the chance to input the date he/she wants, to clarify more this reminder array that`s used above is of type Reminder which is a class I created that have String subject, int year, int month, and int day as its attributes it also have getters and setters methods and a toString, I just though it would be more obvious if I specified the array`s type.
    Last edited by hws; December 30th, 2011 at 09:09 AM.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Problems with my HW

    What does your posted code have to do with going through the elements in an array and choosing some of them based on a user's input?
    reminder must be a class object, not an array, because you are using a get() method instead of array notatoin:[i]
    What does the reminder object contain? Does it have class objects that you need to look inside of to determine if the user wants to select that object?

    In a loop you need to get the objects one at a time and somehow determine if that object is one the user wants. This can be done by having the object's class have methods that can be used to get at specific items in the object, like the year, month and day. There are many ways to do this.

  9. #9
    Junior Member
    Join Date
    Dec 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problems with my HW

    public class Reminder {
    String subject;
    int year;
    int month;

    int day;
    int time;
    String importance;


    public Reminder(){

    }
    public Reminder(String i, String s1, int y, int m, int d, int t) {
    subject = s1;
    year = y;
    month=m;

    day=d;
    time = t;
    importance = i;
    }

    @Override
    public String toString() {
    String str = "Reminder{ Subject: " + subject + ", year=" + year + ", month=" + month + ", day=" + day + ", time=" + time + ", importance=" + importance + '}' + "\n";
    return str ;
    }

    public int getDay() {
    return day;
    }

    public void setDay(int day) {
    this.day = day;
    }

    public String getImportance() {
    return importance;
    }

    public void setImportance(String importance) {
    this.importance = importance;
    }

    public int getMonth() {
    return month;
    }

    public void setMonth(int month) {
    this.month = month;
    }

    public int getTime() {
    return time;
    }

    public void setTime(int time) {
    this.time = time;
    }



    public int getYear() {
    return year;
    }

    public void setYear(int year) {
    this.year = year;
    }

    }
    That`s everything related to the class reminder, and if the method I posted ain`t got nothin to do with it can u tell me which method does?,
    and about the array I created that array from the class above like that private ArrayList<Reminder> reminder = new ArrayList<Reminder>();

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Problems with my HW

    If the class needs more methods to solve your problem, then you should add them.
    What data do you have that you want to use to select an object from the arraylist?
    year, month and day?
    The Reminder class has methods that return the value of each of them. Use those methods to get the object's contents and compare the values returned against the data that you have for selection.


    An ArrayList is not an array. You need to use the correct words when describing your problem.

  11. #11
    Junior Member
    Join Date
    Dec 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problems with my HW

    Ok man when I did get the year, month, and day using the getter method in the reminder class and compared them to the user`s input it didn`t work for me could you help me by giving me a code to compare the year, month, and day with the user`s year, month, and day inputs.

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Problems with my HW

    it didn`t work for me
    Post the code that didn't work and explain what problems you had with it.

  13. #13
    Junior Member
    Join Date
    Dec 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problems with my HW

    I used both scanner and JoptionPane to ask for the users input then I did that
    Reminder re = new Reminder();
    String str = ""
    if(re.getYear()==scan.nextInt()){
    for (int i = 0; i < reminder.size(); i++) {
    str = str + reminder.get(i).toString();
    }

    return str;
    }
    then at the main GUI
    the button that do the display I put that method inside it
    DataBase1(the class containing the method above ) db = new DataBase1();
    then to display at the text area I put
    displayTextArea1.setText(db.toString1());

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Problems with my HW

    You need to show these things:
    1) Where is the data from the user? What variables is the data it read into?
    2) Where do you get the next Reminder object from the ArrayList?
    3) Where do you compare the data in the variables (see step 1) from the user against the contents of the Reminder object (see step2)?

    Don't try to do it all in one step:
    re.getYear()==scan.nextInt()

  15. #15
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Problems with my HW

    Posted here too:
    http://www.javaprogrammingforums.com...html#post53760

    Please stick to this thread hws and read the forum rules.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  16. The Following 2 Users Say Thank You to newbie For This Useful Post:

    Norm (December 30th, 2011), Tjstretch (December 31st, 2011)

Similar Threads

  1. [SOLVED] NIO Problems
    By bgroenks96 in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: November 12th, 2011, 06:26 PM
  2. MP3 problems
    By relion65 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 15th, 2011, 12:09 PM
  3. [SOLVED] Have a few odd problems.
    By javapenguin in forum What's Wrong With My Code?
    Replies: 18
    Last Post: October 19th, 2010, 06:08 PM
  4. rmi problems
    By deepthought in forum Java SE APIs
    Replies: 7
    Last Post: September 7th, 2010, 07:25 PM
  5. How to compile and run java program?
    By ebalari56 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 27th, 2009, 09:33 PM