+ 2

hello, i attempted to create this program but it keeps coming up with errors. can someone please make the corrections for me so

public class Humans{ String name; int heightInInches; int weight; String eyeColor; String gender; int age; String race; } public void speak(){ System.out.println("Hello my name is" + name); System.out.println("i am a" + gender "who is" + age); System.out.println("my eye color is" + eyeColor + "i am" + race); System.out.println("i am"+ heightInInches + "inches"+ "weighing" + weight + "pounds"); } public void eat(){ System.out.println("eating..."); } public void sleep(){ System.out.println("sleeping..."); } public void think(){ System.out.println("thinking..."); } public class Earth(){ public static void main(String []args){ Humans tom; tom = new Humans(); tom.age = 25; tom.eyeColor = "white"; tom.heightInInches = 66; tom.name = "david"; tom.race = "haitian"; tom.weight= 160; tom.gender = "Male"; tom.speak(); } }

5th Feb 2020, 10:46 PM
Pierre
3 ответов
+ 3
Remove the semicolon u inserted after datafields and write to close the humans class that is after the last method think and remove parentheses on the class name Earth , lastly add a "+" in speak method after gender ..it will work
5th Feb 2020, 11:12 PM
Jahnics
Jahnics - avatar
+ 2
Following up on what others had found and fixed; Please tag a relevant programming language name (assumed Java). This helps to improve context clarity, and allows the thread to be searched by relevant search term in the future. Also, considering the code size (more than 10-15 lines); next time please consider to share a saved code link instead. It's easier to check, and people can tell you the problematic line number, which is not possible in raw text format like this. Follow this steps for sharing links 👍 https://www.sololearn.com/post/74857/?ref=app
5th Feb 2020, 11:37 PM
Ipang
+ 1
The first error in the code is because you are closing the class Humans right after the fields (in this case right after 'String race;') This leaves your methods outside of the class. To fix this, delete the closing bracket after 'String race;', and add it after the last method (think). The second error is in the declaration of the Earth class. Classes are written as "public class Class {...}". In your case, you have entered "Earth()" which is a syntax used for methods. Remove the parentheses in the Earth class. The last error is inside the speak method. You have written <..."i am a" + gender "who is"...>. You need to add a + after the gender variable. Fix these errors and the code should run.
5th Feb 2020, 11:19 PM
Nikolay Ganev
Nikolay Ganev - avatar