Jump to content

something wrong with code plz help

- - - - -

  • Please log in to reply
2 replies to this topic

#1
weasel

weasel

    Newbie

  • Members
  • Pip
  • 7 posts
Code:
package pizza;


/**

 *this is a class template for a pizza

 * @author Brandon Wegner

 */

public class Pizza {

    //declare instance variables always private or protected

    private String topping ;

    private double size;

    private boolean crust;

    private double price;

    private double gratuity = .015;

    

    /**

     * a setter for size

     * @param size

     */

     public void setSize(double size){             

        this.size=size;

     /**

      * a getter for size

      * @return

      */

        public double getSize(){

            return this.size;

     }

}

     /**

     * a setter for topping

     * @param topping

     */

     public void setTopping(String topping){

         this.topping=topping;

            /**

             * a getter for topping

             * @return

             */

        public double getTopping(){

             return this.topping

         }

     }

     /**

      * a setter for crust

      * @param crust

      */

     public void setCrust(boolean crust){

         this.crust=crust;

     /**

      * a getter for crust

      * @return

      */

         public boolean getCrust(){

             return this.crust


         }

     }

          /**

      * a setter for price

      * @param price

      */

     public void setPricet(boolean pricet){

         this.price=price;

     /**

      * a getter for price

      * @return

      */

        public boolean getPrice(){

             return this.price

        }   

    }

}

Edited by ZekeDragon, 11 February 2011 - 06:08 PM.
Please use [CODE] tags (the # button) when posting code.


#2
mr mike

mr mike

    Learning Programmer

  • Members
  • PipPipPip
  • 96 posts
Your problem is you created a method then inside the method, you created another method:

public void setSize(double size){ 

this.size=size;

// put closing brace here

public double getSize(){

return this.size;

}// end of getSize();

}// end of setSize(); remove this brace and put the one above


You did this throughout the class. A good practice is to create a method put open and closing braces right away.

#3
weasel

weasel

    Newbie

  • Members
  • Pip
  • 7 posts
thank you that was incredibly helpful




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users