Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*@John Robinson
- */
- public class Shoes {
- /* The error here is that the speak method was opened with an opening brace { but then it was not closed,
- because the needed closing brace is in comments. You still need the closing brace uncommented because
- now the compiler thinks that the rest of the code below this is part of the speak() method, throwing a
- bunch of errors, because you can't have public variables inside a method (those would be called 'local'
- variables). I will remove the closing brace from the comment to amend the error and I will add a classic
- TODO comment. Don't pay too much attention to my detailed explanation. The bottom line is that an
- ending brace was missing. */
- void speak (String msg) { // Shoes speak?
- // TODO: implement the method
- }
- //String reply to good shoes
- // I removed the comment slashes because you needed this method to be defined for your code to compile
- // public String goodShoes() {
- // TODO: Write the goodShoes method body here.
- // } // I added this closing brace because you needed it for your code to compile when it would be uncommented.
- public String goodShoes() { // You define the method to be a String, so you need to return a String
- return "I really like your shoes!";
- // I put the previous incorrect code in comments below so that you can see the difference.
- // I will write correct example code above here. You can't just put something between brackets after the equals sign because it's not valid Java code.
- //Shoes =("I really like your shoes!");
- }
- /*@return String reply to bad shoes
- */
- public String badShoes() {
- return "What are THOSE?";
- /* You can't make an instance of a class inside the class itself.
- In other words, this kind of code has to be in a main() method, outside of the Shoes class.
- I'll just write above here what I think needs to be the right code. */
- // Shoes bs= new Shoes("What are THOSE?");
- //TODO: Write the badShoes method body here.
- }
- public static void main(String[] args) {
- Shoes shoes = new Shoes();
- String goodShoes = shoes.goodShoes();
- String badShoes = shoes.badShoes();
- //TODO: Write the main method body here.
- System.out.println(goodShoes);
- System.out.println(badShoes); // There was a typo here
- } //close the main method with an ending brace
- } //close the class with an ending brace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement