Results 1 to 5 of 5
  1. #1
    MW130 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    317
    Rep Power
    4

    Default What is wrong with this?

    When I run this code I get 7 errors. What am I doing wrong?


    Java Code:
    public class Country{
    String name;
    String continent;
    public Country(String n, String c){
    name = n;
    continent = c;
    }
    public void PrintInfo(){
    Country Argentina = new Country("Argentina", "South America");
    Country China = new Country("China", "Asia");
    Country UnitedStates = new Country("United States","North America");
    System.out.println(name.Argentina+continent.Argentina);
    System.out.println(name.China+continent.China);
    System.out.println(name.UnitedStates+continent.UnitedStates);
    }
    public static void main(String[] args){
    Country callit = new Country();
    callit.PrintInfo("---","----");
    }
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,316
    Blog Entries
    7
    Rep Power
    25

    Default Re: What is wrong with this?

    Are you going to tell us the details of those errors or do you want us to guess?

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  3. #3
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    393
    Rep Power
    6

    Default Re: What is wrong with this?

    Hi,

    Your code on lines 9-14 should read Country.name and Country.continent.
    PrintInfo on line 18 passes two arguments when the method signature on line 8 doesn't accept any.

    Regards.

  4. #4
    tamilarasi is offline Member
    Join Date
    Nov 2012
    Location
    India
    Posts
    70
    Rep Power
    0

    Default Re: What is wrong with this?

    Quote Originally Posted by MW130 View Post
    When I run this code I get 7 errors. What am I doing wrong?
    your code have a problem with this line

    Java Code:
    System.out.println(name.Argentina+continent.Argentina);
    System.out.println(name.China+continent.China);
    System.out.println(name.UnitedStates+continent.UnitedStates);
    you don't call like this.. you call like this..
    Java Code:
    System.out.println(Argentina.name+Argentina.continent);
    System.out.println(China.name+China.continent);
    System.out.println(UnitedStates.name+UnitedStates.continent);
    And also your main method have problem with parameters. So you call like this...

    Java Code:
    public static void main(String[] args){
    Country callit = new Country("","");
    callit.PrintInfo();
    }
    Regards
    Android developer at Trinay Technology Solutions,http://www.trinaytech.com,5705750475

  5. #5
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    9

    Default Re: What is wrong with this?

    And variable names and methods are aways lower case!
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

Similar Threads

  1. Replies: 4
    Last Post: 06-11-2013, 01:37 AM
  2. I can't find anything wrong with this but somehow it's wrong.
    By Biscuit Tickler in forum New To Java
    Replies: 2
    Last Post: 09-12-2012, 09:28 PM
  3. What am I doing wrong?
    By DuncanHollows in forum New To Java
    Replies: 2
    Last Post: 04-08-2012, 05:33 PM
  4. What did I do wrong?
    By Astralogic in forum New To Java
    Replies: 6
    Last Post: 04-05-2012, 12:16 PM
  5. What am I doing wrong?
    By yankeefan9874 in forum New To Java
    Replies: 1
    Last Post: 04-16-2010, 08:54 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
  •