Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By Junky

Thread: Need Ideas to Figure Out Wording on Assignment!

  1. #1
    GFE
    GFE is offline Member
    Join Date
    Nov 2011
    Posts
    3
    Rep Power
    0

    Question Need Ideas to Figure Out Wording on Assignment!

    Hi all. First post and such, but I am just so baffled by my intro to java class that I had to seek help somewhere

    As much as I understand bits and pieces of my class and the assignments, my prof's wording makes things a bit harder to understand (at least for me).

    I'm trying to figure out the meaning of his third assignment. I don't need the code, I just need your input (please!!) on what exactly he means so I can try and figure it out myself. Any tips with code would help too obviously!


    "Write a JAVA class definition for an object called NumberSorter that has three (3) integer attributes
    to store three (3) numbers. Define and write the code for set() and get() methods to set and get
    the values of the three (3) integers. Also, define and write the code for methods to perform the
    following operations.

    return the Largest integer
    return the smallest integer
    print the integers in ascending order (smallest to largest)
    print the integers in descending order (largest to smallest).

    Write the main method as part of the class to test the functionality of each of the methods of the class.
    You should prompt an operator to enter the three integers."

    The part in bold is what I'm having the most trouble with. What is my main method, and why must it be (apparently) a test of some sort for the other methods? It seems like the answers I come up with are either ridiculously obvious or just.. wrong.

    I figure the process could be:
    - Write method that allows user to input 3 numbers that are stored as integer variables (set?)
    - Refer to variables (get?) and write methods for each operation, the answers being other variables previously mentioned (set again?)
    - Conclude with a string that presents the user with the final results (ie. "'The largest integer is' + x" sort of thing)

    Bonus questions!
    - should I worry about private vs public classes yet? Part of me wonders if I could write all these methods as private and then create a public class referring to them to make the end product (code) look neater... if that makes sense?

    - am I using get/set correctly? I feel like I could do this assignment without get and set and that may be part of what's confusing me... hard to find detailed resources on get/set with simple examples.

    Thanks in advance, I've been browsing this forum for a while but never really created an account except for now.. You guys are great!

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Need Ideas to Figure Out Wording on Assignment!

    What is my main method, and why must it be (apparently) a test of some sort for the other methods? It seems like the answers I come up with are either ridiculously obvious or just.. wrong.
    The main() method is just a method of the class declared as

    Java Code:
    public static void main(String args[]) {
        // code here
    }
    It will be what gets invoked when the user runs "java NumberSorter" at the command line. It has to be a test of the class because the teacher says it has to be - ie there is no reason why it *must* be. In fact it might be considered a better plan to make it a main() method of *another* class (see below) but that is not what your teacher is saying you must do.

    I figure the process could be:
    - Write method that allows user to input 3 numbers that are stored as integer variables (set?)
    - Refer to variables (get?) and write methods for each operation, the answers being other variables previously mentioned (set again?)
    - Conclude with a string that presents the user with the final results (ie. "'The largest integer is' + x" sort of thing)
    That sounds good to me. One thing you have forgotten is that the main() method should also create an instance of the NumberSorter class so that it can call the methods.

    should I worry about private vs public classes yet?
    Yes. And a rule of thumb is make everything as restrictive as possible: in this case the integer variables should be private and the setter/getter and other methods methods public.

    It is the public stuff (the methods) that your main() is testing. That is why I mentioned above that such a test main() would often be placed in a different class (you are testing not only the what the methods do, but also that they are accessible to the outside world).

    am I using get/set correctly? I feel like I could do this assignment without get and set
    Yes, it sounds like you are using get/set correctly. And yes, you could do the assignment (all the other bits) without them. But doing things that way would lose the Goodness of having the variables private and the behaviour of getting and setting their values public. That goodness lies in the fact that your NumberSorter class has complete control about what happens when the "outside world" sets or gets a value. If you didn't make the variables private other classes could just alter their values at will. And once you make them private you are more or less committed to having public setters and getters (otherwise you couldn't do anything useful with the variables). In more complex cases this control is very handy and I suppose it is a programming pattern that the assignment is intended to illustrate.

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,789
    Rep Power
    7

    Default Re: Need Ideas to Figure Out Wording on Assignment!

    Quote Originally Posted by pbrockway2 View Post
    Yes. And a rule of thumb is make everything as restrictive as possible: in this case the integer variables should be private and the setter/getter and other methods public.
    Adding my 2cents. Definately make the methods the assignment calls for public but you might find yourself needing one or more helper methods. If you do then make these extra methods private.
    pbrockway2 likes this.

  4. #4
    GFE
    GFE is offline Member
    Join Date
    Nov 2011
    Posts
    3
    Rep Power
    0

    Default Re: Need Ideas to Figure Out Wording on Assignment!

    Thanks! It's reassuring to have some clarification since for some reason a lot of my actual classes derail from the simple questions..this one time an analogy for cookie dough on a literal, real-life cookie tray turned into an user interface cookie that changes colours depending on user preference... it was a long night.

    Quote Originally Posted by pbrockway2 View Post
    It will be what gets invoked when the user runs "java NumberSorter" at the command line. It has to be a test of the class because the teacher says it has to be - ie there is no reason why it *must* be. In fact it might be considered a better plan to make it a main() method of *another* class (see below) but that is not what your teacher is saying you must do.
    So from what I understand, "testing" the other methods basically means that in the main method you will be referring to them. Not something you need to do in particular, but something you will inevitably do in order to do the assignment properly.. like if the result from the main method is incorrect, or has an error, then I've "tested" it?

    Sorry, I get hung up on wording and it can throw me off my work completely if I'm not careful

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,789
    Rep Power
    7

    Default Re: Need Ideas to Figure Out Wording on Assignment!

    The purpose of the main method and testing would be to create a NumberSorter object and call all of the methods to ensure that the correct behaviour is obeserved. For example one of the methods is to print the numbers out in ascending order. But when you call that method you find that it actually prints the largest number 3 times. So it does not do what it should be doing.

  6. #6
    GFE
    GFE is offline Member
    Join Date
    Nov 2011
    Posts
    3
    Rep Power
    0

    Default Re: Need Ideas to Figure Out Wording on Assignment!

    Ok, perfect. That's pretty much what I was hoping it was.

Similar Threads

  1. Ideas anyone?
    By SwEeTAcTioN in forum New To Java
    Replies: 6
    Last Post: 12-03-2009, 08:17 AM
  2. Need ideas here
    By Manfizy in forum New To Java
    Replies: 0
    Last Post: 07-30-2009, 08:07 AM
  3. out of ideas
    By v1nsai in forum New To Java
    Replies: 2
    Last Post: 03-27-2009, 01:35 AM
  4. Merging Ideas
    By CompleteBeginner in forum New To Java
    Replies: 1
    Last Post: 05-19-2008, 02:15 PM
  5. Java assignment - couple methods don't know how to figure out
    By Snowboardmylife in forum New To Java
    Replies: 1
    Last Post: 04-16-2008, 10:52 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •