Java Help

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

DSdavidDS

Thread Starter
Joined
Feb 13, 2010
Messages
183
Joined
May 20, 2010
Messages
4,040
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;
}
 
Joined
May 20, 2010
Messages
4,040
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.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

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 807,865 other people just like you!

Latest posts

Staff online

Members online

Top