+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 20 of 28

Thread: Java Help.     submit to reddit submit to twitter

  1. #1

    Java Help.

    Ok im kind of stumped on my java homework need some help trying to figure this part of the program out.

    He wants us to write a class named month. The class should have an int field named monthNumber that holds the number of the month.

    The part I am stuck on is he wants a constructor that accepts the name of the month as an argument. It should set the monthNumber field to the correct corresponding value.

    And this is intro to java so nothing to advanced.

  2. #2
    Title: "HUBBLE GOTCHU!" (without the quotes, of course [and without "(without the quotes, of course)", of course], etc)
    Join Date
    Jul 2006
    Posts
    3,141
    BG Level
    7

    Holy crap I was just about to make a "Java help" topic. I don't mean to hijack your topic, but I may as well post my question here too.

    How do I put an Ellipse.2D.Double object onto my panel? I need to draw a bunch of balls from an array of Ellipse.2D.Double objects.

    The only way I really know how to draw is to create a graphics2D object and use the methods drawOval or whatever. But for this assignment I'm supposed to use this array.

    My array is called balls. So is there some sort of draw.balls or draw(balls) or draw(balls[i]) (and loop i from 0 to 39)?

    Edit: Nevermind, I figured it out. It was g2.draw(balls[i]). I had tried this earlier but it didn't work. I must have did something wrong earlier, because it's working this time.

  3. #3

    if(stringVariable.equals("January"))
    spacingintVariable = 1;
    else if(stringVariable.equals("February"))
    spacingintVariable = 2;

    etc etc...

  4. #4

    Woozie, what compiler are you using for Java?

    And what Darkslitter said for the constructor. You can also use a switch statement as well which might make things more aesthetic and shorter to type.

  5. #5
    Title: "HUBBLE GOTCHU!" (without the quotes, of course [and without "(without the quotes, of course)", of course], etc)
    Join Date
    Jul 2006
    Posts
    3,141
    BG Level
    7

    eclipse

  6. #6

    Ah, I was going to suggest using that if you weren't already lol. The compiler I use at work is IntelliJ, as of right now they only have a version that you have to pay for. When version 9 comes out soonish, they are going open source so they'll have a free version. It's honestly the best environment I've ever used, I'll let you know when the free version comes out. There might be hacked torrent floating around for the current version, but Eclipse should be good enough until then.

  7. #7

    Can i use an enumerator for this for the months also. Since you wont actually do any inputing from the program. or is it easier just to do if/else for all 12 months?

  8. #8
    blax n gunz
    Join Date
    May 2005
    Posts
    11,161
    BG Level
    9

    Quote Originally Posted by Zilla View Post
    Can i use an enumerator for this for the months also. Since you wont actually do any inputing from the program. or is it easier just to do if/else for all 12 months?
    You can also create a static hashtable and just have your constructor reference it to get the internal value based on the string entered.

  9. #9
    Title: "HUBBLE GOTCHU!" (without the quotes, of course [and without "(without the quotes, of course)", of course], etc)
    Join Date
    Jul 2006
    Posts
    3,141
    BG Level
    7

    Okay, my circles are all outlined red. But I want them to be filled with red. How do I fill the circles with color for Ellipse.2D.Double objects?

    Edit: Is this even possible? Based on this

    http://java.sun.com/j2se/1.4.2/docs/...2D.Double.html

    There doesn't seem to be a way to do this. But my professor wants my end result to look like this:

    http://www.cs.uakron.edu/~zduan/clas...m5/progra5.jpg

    by using an array of Ellipse2D.Double objects.

  10. #10
    blax n gunz
    Join Date
    May 2005
    Posts
    11,161
    BG Level
    9

    I could swear all awt objects had a .fill() function to make it a solid color.

    Oops nvm been too long. You need the Java object that actually draws shapes and call fill on it passing your shape as the parameter. Somewhere in your program you should have a Graphics or Graphics2D object that you set things like viewport and origin on, then pass your object to the fill(Shape) method.

  11. #11

    Woozie, you should try and help Zilla. You're asking for more advanced help, I'm sure you can answer all of Zilla's questions.

    To Zilla: Enumerator, switch, if/else... They all work. Whichever you feel most comfortable using or most interested in pushing your limits with would be the best answer.

  12. #12
    Banned.

    Join Date
    Jul 2005
    Posts
    17,472
    BG Level
    9
    FFXI Server
    Ifrit
    WoW Realm
    Area 52

    Quote Originally Posted by Zilla View Post
    Ok im kind of stumped on my java homework need some help trying to figure this part of the program out.

    He wants us to write a class named month. The class should have an int field named monthNumber that holds the number of the month.

    The part I am stuck on is he wants a constructor that accepts the name of the month as an argument. It should set the monthNumber field to the correct corresponding value.

    And this is intro to java so nothing to advanced.
    A simple solution would be to build an array with every months listed in order. Then search through the array and compare it to your string input. The iterator is going to be the # of the months you're looking for, when both string matches.


    Quote Originally Posted by Woozie View Post
    Okay, my circles are all outlined red. But I want them to be filled with red. How do I fill the circles with color for Ellipse.2D.Double objects?

    Edit: Is this even possible? Based on this

    Ellipse2D.Double (Java 2 Platform SE v1.4.2)

    There doesn't seem to be a way to do this. But my professor wants my end result to look like this:

    http://www.cs.uakron.edu/~zduan/clas...m5/progra5.jpg

    by using an array of Ellipse2D.Double objects.
    Why are they making you write interactive interface in your first java class? It should be console output until you have no problem writting basic program that can solve most mathematics problem.

  13. #13

    We have not started arrays yet so i can't use those. I'll just do a big if/else way. Thinks thats easier for me to understand.

  14. #14
    Banned.

    Join Date
    Jul 2005
    Posts
    17,472
    BG Level
    9
    FFXI Server
    Ifrit
    WoW Realm
    Area 52

    Quote Originally Posted by Zilla View Post
    We have not started arrays yet so i can't use those. I'll just do a big if/else way. Thinks thats easier for me to understand.
    Code:
    //Constructor
    month("m")
    
        int i =0
     
        while i<12) 
              if month[i]== m      //month[i] is a 2-d table with 12 string
                     month#= i
              end if
        end while
    end month
    I don't remember much about java itself, but that's what I was saying. Not really hard to understand

    12 "if else" works too, but it's basically the same you're doing.

  15. #15
    Title: "HUBBLE GOTCHU!" (without the quotes, of course [and without "(without the quotes, of course)", of course], etc)
    Join Date
    Jul 2006
    Posts
    3,141
    BG Level
    7

    Quote Originally Posted by Correction View Post
    I could swear all awt objects had a .fill() function to make it a solid color.

    Oops nvm been too long. You need the Java object that actually draws shapes and call fill on it passing your shape as the parameter. Somewhere in your program you should have a Graphics or Graphics2D object that you set things like viewport and origin on, then pass your object to the fill(Shape) method.
    Thanks, it worked.

    Quote Originally Posted by StopTheLight View Post
    Woozie, you should try and help Zilla. You're asking for more advanced help, I'm sure you can answer all of Zilla's questions.

    To Zilla: Enumerator, switch, if/else... They all work. Whichever you feel most comfortable using or most interested in pushing your limits with would be the best answer.
    I was about to answer his first question but someone else posted the answer while I was typing. To be honest, I hardly understand what I'm doing in this class so I may not be the best person to help someone else, even if they're doing stuff I've already done.

    Quote Originally Posted by Kaylia View Post
    Why are they making you write interactive interface in your first java class? It should be console output until you have no problem writting basic program that can solve most mathematics problem.
    Almost every program we've had to write this semester were like this. Our last program was a slot machine. We had to have a GUI with spinning reels and a slider thingy to adjust the spinning speed.

  16. #16
    Banned.

    Join Date
    Jul 2005
    Posts
    17,472
    BG Level
    9
    FFXI Server
    Ifrit
    WoW Realm
    Area 52

    Quote Originally Posted by Woozie View Post
    Almost every program we've had to write this semester were like this. Our last program was a slot machine. We had to have a GUI with spinning reels and a slider thingy to adjust the spinning speed.
    No wonder you get confused with this crap. They skipped the most basic things and went for completely useless stuff. I'm not a CS teacher, but I completely disagree with this approach, unless your whole classes already have some programming experience.

    The first class should always deal with basic concept such as search method, storage method (array, stack..etc), recursivity and various object programming stuff.

  17. #17

    Yea the way this guy teaches is like we go over a chapter he does some random examples from the book and then gives us a problem to do. Some times its easy then its times where im lost.

  18. #18
    netz
    Guest

    Quote Originally Posted by Kaylia View Post
    No wonder you get confused with this crap. They skipped the most basic things and went for completely useless stuff. I'm not a CS teacher, but I completely disagree with this approach, unless your whole classes already have some programming experience.

    The first class should always deal with basic concept such as search method, storage method (array, stack..etc), recursivity and the different of object programming concept.
    Two schools I've been at try to get your feet wet before introducing you to data structures and algorithms formally. I'm guessing they want to give people an idea of how to use the language before teaching them how to use the language to solve more complex problems.

    The first class usually assumes absolutely no programming experience whatsoever. Can you think of a way to teach all of the things you listed within the first week to someone who has never used a language before? I think it'd be tough, honestly, but most schools don't want to design a computer science program that assumes you already know what you're doing. I think it would be a decent assumption, though, and it would have been nice to skip intro to java and data structures.

  19. #19
    blax n gunz
    Join Date
    May 2005
    Posts
    11,161
    BG Level
    9

    Mingling a 'wet feet' exposure to the AWT into a lesson unrelated to how to manage the graphics layer in java without abstracting it to a barebones idiotproof class library (which awt is anything but) would do more harm than good. Learning Java is extremely different than learning graphics programming.

  20. #20
    Banned.

    Join Date
    Jul 2005
    Posts
    17,472
    BG Level
    9
    FFXI Server
    Ifrit
    WoW Realm
    Area 52

    Quote Originally Posted by netz View Post
    Two schools I've been at try to get your feet wet before introducing you to data structures and algorithms formally. I'm guessing they want to give people an idea of how to use the language before teaching them how to use the language to solve more complex problems.

    The first class usually assumes absolutely no programming experience whatsoever. Can you think of a way to teach all of the things you listed within the first week to someone who has never used a language before? I think it'd be tough, honestly, but most schools don't want to design a computer science program that assumes you already know what you're doing. I think it would be a decent assumption, though, and it would have been nice to skip intro to java and data structures.
    None of the thing I mentioned require more than "if/else", while loop and basic variable type. I'm not asking to understand every search algorithm by the time you end your first class, but you should at least be able to program a basic one on your own.

    Confusing new students with useless graphic outputs is more harmful than anything, when they should learn how to handle strings of text, boolean conditions, and produce a logically sound program. When the students is confident with the "inside" of a program, adding a graphic layer on top of it is really easy, but it's not something you should do right away.


    It can get confusing really fast when you mix both interface and inner layer at the same time, because a programmer handle both differently. It won't generate the same kind of error when you debug them. Also one make you works on your logic, while the other force you to search around the net for the library/function you need. Both aspect are very important on their own, but you should understand your own code before using someone else's code (library).

Similar Threads

  1. Need help fixing Java Code
    By Minardi in forum General Discussion
    Replies: 18
    Last Post: 2010-03-15, 23:56
  2. Java Help
    By jinkazama in forum General Discussion
    Replies: 28
    Last Post: 2010-01-30, 22:07
  3. Java Programming Help
    By bori in forum General Discussion
    Replies: 9
    Last Post: 2008-09-19, 09:00
  4. Help with Java Programming Project. Get GF off my back plz
    By Azkarin in forum General Discussion
    Replies: 18
    Last Post: 2007-10-10, 10:59
  5. Java HELP :(
    By Maguspk in forum General Discussion
    Replies: 47
    Last Post: 2006-10-24, 10:36
  6. Need java help...
    By Sekkite in forum General Discussion
    Replies: 15
    Last Post: 2005-10-16, 15:58