Results 1 to 8 of 8
  1. #1
    jo15765 is offline Member
    Join Date
    May 2012
    Posts
    42
    Rep Power
    0

    Default Creating a Secondary Class Based off of Primary Class

    I have been using Notepad++ to create .java & .class files. I am now attempting to teach myself Eclipse as it has many features which would have saved me TONS of time had I done this in the beginning. My question is, I have a class called DateTest, which will accept user input (numeric ex. 200) and pass that value to a class called Date which will calculate and display the date (mm/dd/yyyy) of what day 200 is. My problem is, I can't figure out in eclipse how to let DateTest "see" the functions in Date class?

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: Creating a Secondary Class Based off of Primary Class

    Post your code, please. There are many way to screw it up.

    Great that you've started with Notepad++! You've learned the basics, that an IDE will hide from you.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    jo15765 is offline Member
    Join Date
    May 2012
    Posts
    42
    Rep Power
    0

    Default Re: Creating a Secondary Class Based off of Primary Class

    That makes me feel better :)

    This is the DateTest class, that should prompt for userinput put it is not giving me a prompt when I try to run this in Eclipse, but if I run it through the command line it works fine.
    And it may just be that I am setting it up incorrect in Eclipse for this type of coding.
    Java Code:
    public class Date Test {
    public static Date getInput()
    {
    int month = 0;
    int year = 0;
    int day = 0;
    for(int i = 1; i <= 365; i++)
    {
    Scanner s = new Scanner(System.in);
    Date b;
    System.out.println("Input your choice of a month, a day and a year.");
    month = input.nextInt();
    day= input.nextInt();
    year = input.nextInt();
    b = new Date(month, day, year);
    System.out.println("Output " = b.nextDay());
    input.close();
    }
    return new Date(month, day, year);
    }
    Then for my Date class
    Java Code:
    public class Date
    {
    int month;
    int day;
    int year;
    public Date(int month, int day, int year)
    {
    this.month = month;
    this.day = day;
    this.year = year;
    System.out.println("Date object constructor for date "+month+"/"+day+"/"+year);
    }
    public String nextDay()
    {
    //TONS of code to check what the next day would be....
    }

  4. #4
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: Creating a Secondary Class Based off of Primary Class

    In eclipse you've got the Console view, that's where you see the output and where you enter your input, there is just no blinking cursor.
    Last edited by PhHein; 06-04-2013 at 03:37 PM.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  5. #5
    jo15765 is offline Member
    Join Date
    May 2012
    Posts
    42
    Rep Power
    0

    Default Re: Creating a Secondary Class Based off of Primary Class

    When I run it, there is no output in the console within Eclipse.
    However, if I copy/paste the code into a scrapbook page, I get output into the console there.

  6. #6
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: Creating a Secondary Class Based off of Primary Class

    DateTest doesn't have a main method. What do you start? Start it in debug mode and have a look what's happening.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  7. #7
    jo15765 is offline Member
    Join Date
    May 2012
    Posts
    42
    Rep Power
    0

    Default Re: Creating a Secondary Class Based off of Primary Class

    When I ran it in Notepad++ I didn't have to have a Main method in order for the code to execute.
    I added a breakpoint on the Scanner input line, but it is never hitting the breakpoint. So is it a safe assumption that my getInput method is never being reached?

  8. #8
    jo15765 is offline Member
    Join Date
    May 2012
    Posts
    42
    Rep Power
    0

    Default Re: Creating a Secondary Class Based off of Primary Class

    So I added a main method, and in that method I called my getInput() so my code reads like this.
    Java Code:
    public static void main(String[] args)
    {
    getInput();
    }
    And that gives the desired output. Now I am curious as to why it worked in notepad++ but Eclipse didn't like it?

Similar Threads

  1. Closing secondary window from button in primary window
    By KoncentriK in forum New To Java
    Replies: 4
    Last Post: 02-26-2012, 01:24 AM
  2. Replies: 9
    Last Post: 07-29-2011, 02:18 PM
  3. creating class
    By J7571 in forum New To Java
    Replies: 4
    Last Post: 11-18-2010, 02:55 PM
  4. Help with creating a class
    By cdawg_2010 in forum New To Java
    Replies: 22
    Last Post: 11-03-2010, 05:34 AM
  5. Replies: 7
    Last Post: 12-16-2009, 11:51 AM

Posting Permissions

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