1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Java Help

Discussion in 'Software Development' started by DSdavidDS, Oct 30, 2011.

Thread Status:
Not open for further replies.
Advertisement
  1. DSdavidDS

    DSdavidDS Thread Starter

    Joined:
    Feb 13, 2010
    Messages:
    183
  2. sepala

    sepala

    Joined:
    May 20, 2010
    Messages:
    4,038
    Hi, please copy and paste the code in here
     
  3. DSdavidDS

    DSdavidDS Thread Starter

    Joined:
    Feb 13, 2010
    Messages:
    183
    I pasted the code in the link =o
     
  4. sepala

    sepala

    Joined:
    May 20, 2010
    Messages:
    4,038
    I know the lnk is there but I requested it to be here because that is easy for anyone trying to correct that. Anyway here I am pasting the code for you.

    Code:
    import java.util.Scanner;
    
    public class EP52Out
    {
        public static void main(String[] args)
        {
            Scanner in = new Scanner(System.in);        
            
            System.out.println("Enter the Card Notation: ");
            String notation = in.next();
            card newCard = new card(notation);
            System.out.println(newCard.getDescription);
        }
    }


    Code:
    public class EP52
    {
        public card(String notation)
        {
            symbol = notation;
        }
        public  String getDescription()
        {
            String i;
            if (symbol == "h") i = "Hearts";
            else if (symbol == "d") i = "Diamonds";        
            else if (symbol == "s") i = "Spades";
            else if (symbol == "c") i = "Clovers";
            else i = "Unknown";
            return i;
                                           
        }
        
        private String symbol;
        private String letter;
    }
     
  5. sepala

    sepala

    Joined:
    May 20, 2010
    Messages:
    4,038
    There are number of errors in your code.

    1. In the second code, you are creating a method called "card" without a "return type". That is wrong.
    2. In the first code, you are creating an object of class "card" which doesn't exist.
    what has happened here???

    You have messed up with the "constructor" and "method". Study what is a "Constructor" and what is a method "properly". Study how to work with constructors and how to work with methods.



    Here are some good programming practices you should follow when coding.

    1. Do not create new global variables at the end of the code, create them at the beginning, and initialize them in the constructor.
    2. Use ELSE IF statement properly with {}
    3. USE PROPER NAMES FOR CLASSES. The names you have given are not programmer friendly.
    4. Find out when to use "==" and ".equals()" method. you have to replace the "==" in the if else statement with that method.
    5.Get used to the error messages you get while compiling.
     
  6. DSdavidDS

    DSdavidDS Thread Starter

    Joined:
    Feb 13, 2010
    Messages:
    183
    Thank you very much for the advice. Ill take a look into it!
     
  7. sepala

    sepala

    Joined:
    May 20, 2010
    Messages:
    4,038
    You are welcome
     
  8. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Similar Threads - Java Help
  1. charlzguitarz
    Replies:
    4
    Views:
    971
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1024632

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice