Advertisement
Guest User

Shoes

a guest
Sep 20th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.47 KB | None | 0 0
  1. /*@John Robinson
  2. */
  3.  
  4. public class Shoes {
  5.  
  6. /* The error here is that the speak method was opened with an opening brace { but then it was not closed,
  7. because the needed closing brace is in comments. You still need the closing brace uncommented because
  8. now the compiler thinks that the rest of the code below this is part of the speak() method, throwing a
  9. bunch of errors, because you can't have public variables inside a method (those would be called 'local'
  10. variables). I will remove the closing brace from the comment to amend the error and I will add a classic
  11. TODO comment. Don't pay too much attention to my detailed explanation. The bottom line is that an
  12. ending brace was missing. */
  13.  
  14.     void speak (String msg) { // Shoes speak?
  15.     // TODO: implement the method
  16.     }
  17.    
  18.     //String reply to good shoes
  19.  
  20.     // I removed the comment slashes because you needed this method to be defined for your code to compile
  21.     // public String goodShoes() {
  22.         // TODO: Write the goodShoes method body here.
  23.      // } // I added this closing brace because you needed it for your code to compile when it would be uncommented.
  24.  
  25.     public String goodShoes() { // You define the method to be a String, so you need to return a String
  26.         return "I really like your shoes!";
  27.          
  28.         // I put the previous incorrect code in comments below so that you can see the difference.
  29.         // 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.
  30.         //Shoes =("I really like your shoes!");
  31.     }
  32.  
  33.   /*@return String reply to bad shoes
  34.   */
  35.   public String badShoes() {
  36.       return "What are THOSE?";
  37.  
  38.        /* You can't make an instance of a class inside the class itself.
  39.            In other words, this kind of code has to be in a main() method, outside of the Shoes class.
  40.            I'll just write above here what I think needs to be the right code. */
  41.      
  42.       // Shoes bs= new Shoes("What are THOSE?");
  43.       //TODO: Write the badShoes method body here.
  44.   }
  45.  
  46.   public static void main(String[] args) {
  47.       Shoes shoes = new Shoes();
  48.       String goodShoes = shoes.goodShoes();
  49.       String badShoes = shoes.badShoes();
  50.    
  51.     //TODO: Write the main method body here.
  52.       System.out.println(goodShoes);
  53.       System.out.println(badShoes); // There was a typo here
  54.   } //close the main method with an ending brace
  55.  
  56. } //close the class with an ending brace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement