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 10 of 10

Thread: Help out a poor student!

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help out a poor student!

    edit* I have to produce code as per the Javadoc comments.

    Ok, managed to get straight into 3rd year at University studying Computing after very little Java, so i'm struggling! I'm working my way through 'Data Structures and the Java Collections' by William J Collins (recommended reading) but I'm not taking a lot of it in as of yet.

    Please help!! Question under the code I have attempted so far.


    Oh, sorry if this I have posted this in the wrong section.

    In this project you will get to be developer of a parameterized class, and become a user of
    that class. To start with, here are method specifications for the parameterized class,
    Sequence, with E the type parameter:

     
    public class Sequence<E> {
     
        protected E[] data;
        protected int size;
     
     
        /**
        * Initialises this Sequence object to be empty, with an initial
        * capacity of ten elements.
        */
        public Sequence() {
     
            E[] data = (E[]) new Object[10];
            int size = 0;
     
     
        }
        /**
        * Initialises this Sequence object to be empty, with a specified
        * initial capacity.
        *
        * @param capacity - the initial capacity of this Sequence object.
        *
        * @throws IllegalArgumentException - if capacity is non-positive
        */
        public Sequence (int capacity){
            capacity = 0;
            throw new IllegalArgumentException();
        }
        /**
        * Returns the number of elements in this Sequence object.
        *
        * @return the number of elements in this Sequence object.
        */
        public int size (){
            return  0;
        }
        /**
        * Appends a specified element to this Sequence object.
        *
        * @param element - the element to be inserted at the end of this
        * Sequence object.
        */
        public void append (E element) {
     
        }
        /**
        * Returns the element at a specified index in this Sequence object.
        * The worstTime(n) is constant, where n is the number of elements in
        * this Sequence object.
        *
        * @param k - the index of the element returned.
        * *
    * @return the element at index k in this Sequence object.
    *
    * @throws IndexOutOfBoundsException - if k is either negative or
    * greater than or equal to the number of elements in this
    * Sequence object.
    */
    public E get (int k){ //Week 3 Laboratory – COMP09044 Page 2
     
        return null; 
    }
    /**
    * Changes the element at a specified index in this Sequence object.
    * The worstTime(n) is constant, where n is the number of elements in
    * this Sequence object.
    *
    * @param k - the index of the element required.
    * @param newElement - the element to replace the element at index k
    * in this Sequence object.
    *
    * @throws IndexOutOfBoundsException - if k is either negative or
    * greater than or equal to the number of elements in this
    * Sequence object.
    */
    public void set (int k, E newElement){
     
    }
     
    }

    Part 1: Create unit tests based on the method specifications and stubs.
    Part 2: Define the methods in the Sequence class.
    Hint: use the following fields:
    protected E[] data;
    protected int size; // The number of elements in the Sequence, not
    // the capacity of the data array.
    Note 1: for the append method, if the data array is currently full, its capacity must be
    increased before the element can be appended. See Programming Exercise 2.10 to see how
    to accomplish the expansion.
    Note 2: for methods that may throw an exception, do not include catch blocks. Instead, the
    exception will be propagated, so the handling can be customised for the application.
    Part 3: Test the method definitions in your Sequence class.
    Last edited by Hoor-paar-kraat; October 4th, 2012 at 04:00 PM.


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Help out a poor student!

    Quote Originally Posted by Hoor-paar-kraat View Post
    Please help!! Question under the code I have attempted so far.
    I don't see your question.

    Also please see the forum rules including the section on the use of code tags, if you have any questions please ask.

  3. #3
    Junior Member
    Join Date
    Oct 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help out a poor student!

    Sorry, I was too stressed and didn't read the rules. Also I realise there is no set question. I have to first complete the code that will accompany the javadoc comments and then follow the steps outlined below the code.

    I would really appreciate any help with the code and I am sure I could work out the rest, or at least give it a bash.

  4. #4
    Junior Member
    Join Date
    Oct 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help out a poor student!

    I would also appreciate any recommendations for reading material on java.

  5. #5
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Help out a poor student!

    Quote Originally Posted by Hoor-paar-kraat View Post
    Sorry, I was too stressed and didn't read the rules. Also I realise there is no set question. I have to first complete the code that will accompany the javadoc comments and then follow the steps outlined below the code.

    I would really appreciate any help with the code and I am sure I could work out the rest, or at least give it a bash.
    To promote learning we try not to spoon-feed code that is a solution to the problem. Rather we encourage you to attempt a solution to the problem and post questions when you get stuck. Try to pick the first basic problem to solve, isolate it from the rest, and try to get a program working that does just the first part.

  6. #6
    Junior Member
    Join Date
    Oct 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help out a poor student!

    Indeed! I don't expect someone else to do the work for me, otherwise I'll just end up failing when it comes to exam time. There was no code what-so-ever on the original question, Everything you see there is my work so far (although you can probably tell that!:p).

    I will give it another go over the weekend after I have read another decent chunk of this text book. I only ask you point me in the right direction if i'm totally off with anything.

    Oh, am I looking at Array Lists for this section?

     /**
        * Initialises this Sequence object to be empty, with a specified
        * initial capacity.
        *
        * @param capacity - the initial capacity of this Sequence object.
        *
        * @throws IllegalArgumentException - if capacity is non-positive
        */
        public Sequence (int capacity){
            capacity = 0;
            throw new IllegalArgumentException();
        }
        /**
        * Returns the number of elements in this Sequence object.
        *
        * @return the number of elements in this Sequence object.
        */
        public int size (){
            return  0;
        }

  7. #7
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Help out a poor student!

    After a quick once-over it looks to me like you are instructed to use E[] to store the elements of the object, and an int size to keep record of how many elements are currently stored in E[].

    It looks to me like you are to do the assignment without ArrayList.
    Note 1: for the append method, if the data array is currently full, its capacity must be
    increased before the element can be appended. See Programming Exercise 2.10 to see how
    to accomplish the expansion.

    Browse 2.10 ...

  8. #8
    Junior Member
    Join Date
    Oct 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help out a poor student!

    Programming Exercise 2.10 is slightly out of my working ability as of yet. I am getting there, however, said exercise is very difficult to understand (I am assuming because my knowledge of java is fairly poor). I was hoping for a better explanation or links to a recommended site. I am only 1 week into the course and this piece of work hasn't to be handed in for another month, I just thought I would try get a head start so I can catch up with everyone else.

    Cheers.

  9. #9
    Member
    Join Date
    Jun 2012
    Posts
    105
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default Re: Help out a poor student!

    I am also trying to learn Java by myself to poor to afford to go to college. Is there a link that I can look at it that actually has the assignment.

    THanks.

  10. #10
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Help out a poor student!

    Quote Originally Posted by Hoor-paar-kraat View Post
    Programming Exercise 2.10 is slightly out of my working ability as of yet. I am getting there, however, said exercise is very difficult to understand (I am assuming because my knowledge of java is fairly poor). I was hoping for a better explanation or links to a recommended site. I am only 1 week into the course and this piece of work hasn't to be handed in for another month, I just thought I would try get a head start so I can catch up with everyone else.

    Cheers.
    I don't even know what is in 2.10. I am just quoting your post where the instructions tell you to look there.

    Going by what you posted here it looks like you should be reading about arrays. When you create an array, the array has a fixed size equal to the specified size, say 12 for this example. Now you have space for 12 ints. You actually add 3 ints to the array.
    Now you have an array 12 elements long, holding 3 elements. So your size method would return 3, not 12.
    Picture it like an egg carton. The carton holds 12 eggs maximum. But it can have just 3 eggs left... or 8... the size variable is meant to keep track of how many eggs you have in your carton.

    Now suppose your egg carton has 12 eggs and you find another egg. There is no room in the carton for the 13th egg. So you have to create a new carton larger than before, transfer the first 12 eggs from the old carton, and finally add that 13th egg to the new carton.

    I suggest you pick one method at a time and try to make it work. When you get stuck ask a question. Don't try to visualize every detail of the whole assignment at once.

Similar Threads

  1. Where are all the symbols!? Poor Java can't find them... :(
    By coffecupcake in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 17th, 2012, 03:08 PM
  2. Student Grading
    By happychild in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 14th, 2011, 12:09 PM
  3. student CGPA
    By adamu adamu in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 8th, 2011, 06:52 AM
  4. Hello to all!/Java Student.
    By Benjamin Cainan in forum Member Introductions
    Replies: 1
    Last Post: May 3rd, 2011, 09:48 AM
  5. Student Programs
    By Suzanne42 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 26th, 2011, 09:20 AM