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

Thread: Coding in BlueJ/JDK 8, In need of assistance.

  1. #1
    Junior Member
    Join Date
    Aug 2014
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Coding in BlueJ/JDK 8, In need of assistance.

    Hi, I just recently started a coding class using BlueJ/JDK 8, I know exactly what i want my code to do, and i already have a basic set up, but I'm stuck. The goal is to have the user input a Tank (The ones that drive around and shoot?) name, and what returns to them are the stats, such as Hitpoints, Tier, Type of tank, etc. Any advice or help would be greatly appreciated! Here's my code:
    public class TankCalculator {
    private int tier = 1;
    private int whatType;
    private int whatNation;
    private int whatHitpoints;
    private int whatPlaystyle;
    private int whichTank;
    private int MS1;
    private int T1;
    private int Medium1;
    private int LTr;
    private int FT;
    private int NC31;
    private int ROtsu;
    private String stats;
    public TankCalculator(int Tank) {
    whichTank = Tank;
    if (whichTank == MS1)stats = 1;
    if (whichTank == T1)stats = 2;
    if (whichTank == Medium1) stats = 3;
    if (whichTank == LTr)stats = 4;
    if (whichTank == FT) stats = 5;
    if (whichTank == NC31) stats = 6;
    if (whichTank == ROtsu) stats = 7;
    }
    private void setHitpoints(int hitpoints) {
    whatHitpoints = hitpoints;
    if (whichTank == MS1)return "90 - 100";
    if (whichTank == T1)return "105 - 115";
    if (whichTank == Medium1) return "130 - 140";
    if (whichTank == LTr)return "110 - 130";
    if (whichTank == FT) return "105 - 115";
    if (whichTank == NC31)return "100 - 110";
    if (whichTank == ROtsu)return "100 - 110";

    }
    private void setType(int type) {
    whatType = type;
    if (whichTank == MS1)return "Light";
    if (whichTank == T1)return "Light";
    if (whichTank == Medium1) return "Medium";
    if (whichTank == LTr)return "Light";
    if (whichTank == FT) return "Light";
    if (whichTank == NC31)return "Light";
    if (whichTank == ROtsu)return "Light";
    }

    private void setNation(int nation) {
    whatNation = nation;
    if (whichTank == MS1)return "USSR";
    if (whichTank == T1)return "USA";
    if (whichTank == Medium1) return "UK";
    if (whichTank == LTr)return "Germany";
    if (whichTank == FT) return "France";
    if (whichTank == NC31)return "China";
    if (whichTank == ROtsu)return "Japan";
    }

    private void setPlaystyle(int playstyle){
    whatPlaystyle = playstyle;
    if (whichTank == MS1)return "Brawler";
    if (whichTank == T1)return "Mixed";
    if (whichTank == Medium1)return "Brawler";
    if (whichTank == LTr)return "Sniper";
    if (whichTank == FT)return "Sniper";
    if (whichTank == NC31)return "Mixed";
    if (whichTank == ROtsu)return "Support";
    }
    public String getStats() {
    return stats;
    }

    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,718
    My Mood
    Mellow
    Thanks
    231
    Thanked 706 Times in 692 Posts

    Default Re: Coding in BlueJ/JDK 8, In need of assistance.

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Please post your code correctly per the above link.

    Describe what your code is not doing that it should be doing. Post a sample run and an example of what the run should be but isn't. I don't see a main() method. Is BlueJ the IDE that doesn't require one? Or have you written a driver program that makes the above go?

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

    Morrow (August 30th, 2014)

  4. #3
    Junior Member
    Join Date
    Aug 2014
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Coding in BlueJ/JDK 8, In need of assistance.

    Okay, Okay. Im really new to this so most of what you're saying i'm not following. I already explained what i want it to do, I want it so the USER, The person at the computer, types a name in: For example, "T1", and the code recognizes it and returns a set of statistics (return stats) to the user. BlueJ Might be the IDE That doesnt require one. I dont know for sure. New to the class.

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

    Default Re: Coding in BlueJ/JDK 8, In need of assistance.

    I can assure you BlueJ does use main methods - I used the IDE once as a beta
    version. It's setup is very basic compared to Eclipse as it is aimed at students
    learning Java - it does have a very pretty interface

    In regards to the problem, are you getting compile errors? Is the program running but
    outputting wrong results? Greg was suggesting we need a better view on exactly what
    is not working.

    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)

  6. #5
    Junior Member
    Join Date
    Aug 2014
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Coding in BlueJ/JDK 8, In need of assistance.

    .....jpg
    Compile picture. Cant even get it to have an input box. aka Object i guess?

  7. #6
    Junior Member
    Join Date
    Aug 2014
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Coding in BlueJ/JDK 8, In need of assistance.

    int cannot be converted to java.lang.string, line highlighted being if (whichTank == MS1)stats = 1;

  8. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,973
    Thanks
    51
    Thanked 2,269 Times in 2,241 Posts

    Default Re: Coding in BlueJ/JDK 8, In need of assistance.

    int cannot be converted to java.lang.String
    The compiler can't convert the int: 1 to a String to assign to the variable: stats.
    Change the int: 1 to a String by putting it in "s
    "1" is a String.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #8
    Junior Member
    Join Date
    Aug 2014
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Coding in BlueJ/JDK 8, In need of assistance.

    if (whichTank == MS1)stats = MS;"1";
    Like this? it's now saying it isnt a statement.

  10. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,973
    Thanks
    51
    Thanked 2,269 Times in 2,241 Posts

    Default Re: Coding in BlueJ/JDK 8, In need of assistance.

    stats = MS;"1";
    Where did the MS come from? It wasn't part of the error message you reported here:
    line highlighted being if (whichTank == MS1)stats = 1;
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. [SOLVED] Java Coding: Assistance with a loop that calculates maximum, minimum, and average of 10 inputted numbers.
    By Knowledge_Feeds_The_Mind in forum What's Wrong With My Code?
    Replies: 20
    Last Post: February 27th, 2014, 10:11 PM
  2. [SOLVED] Run JDK from USB for BlueJ
    By Abstract3000 in forum Java IDEs
    Replies: 2
    Last Post: January 9th, 2014, 04:45 AM
  3. Run JDK from USB for BlueJ
    By Abstract3000 in forum The Cafe
    Replies: 1
    Last Post: January 9th, 2014, 01:36 AM
  4. Bluej help
    By kiara4 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 13th, 2012, 04:29 PM
  5. Replies: 2
    Last Post: February 19th, 2012, 06:36 AM