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

Thread: does this need a class

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default does this need a class

    does the following code require a class;
    // Create a Non-Playable-Character(s) / NPC in World
    NPC npc1 = new NPC("Wolf", 25, 8, 4);

    I am assuming
    Wolf is a string=name
    25 is an int=hp
    8 is an int=atk
    4 is an int=def

    I am having problems with constructors and how to write this. I blieve NPC needs a class with the variables. I am a beginner so my terminaolgy may be incorrect.

    Thanks for any assistance

    John


  2. #2
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    414
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: does this need a class

    Yes it would need a class. All Java programs use classes.

    NPC would be the class and npc1 would be the instance of the class.
    Is this a game you are making or a college assignment?

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

  3. The Following User Says Thank You to Ada Lovelace For This Useful Post:

    GregBrannon (July 27th, 2014)

  4. #3
    Junior Member
    Join Date
    Jul 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: does this need a class

    It is for school, I took a quiz and was unable to compile the main. I tried several times to write a NPC class that would instance or define the varibles to no avail. Now I am trying to understand what I was missing or how I should have written the NPC class file defining Wolf as a string and the rest as int.

    Thanks

    John

  5. #4
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    414
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: does this need a class

    It might be a good idea to read up on how class instances
    work within the main method (how an instance invokes a method,
    why the constructor is called) and basic Java terminologies such as
    Strings, fields and basic OOP.

    But your on the right track - keep working and good luck

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

Similar Threads

  1. Replies: 10
    Last Post: October 20th, 2013, 06:35 AM
  2. Replies: 2
    Last Post: November 18th, 2012, 02:09 PM
  3. need to make basic class and implementation class (base class without void main)
    By javanewbie101 in forum Object Oriented Programming
    Replies: 1
    Last Post: September 19th, 2012, 08:03 PM
  4. create a test class (main method) to start(run) the class in Java
    By curious725 in forum Java Theory & Questions
    Replies: 5
    Last Post: August 1st, 2012, 03:21 AM
  5. Replies: 3
    Last Post: June 17th, 2012, 06:22 PM

Tags for this Thread