Results 1 to 7 of 7

Thread: I have no idea what I'm doing anymore(Java)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    GO! use leech seed! qwertysaur's Avatar
    Join Date
    Dec 2006
    Location
    Kanto
    Posts
    11,627
    Contributions
    • Former Site Staff

    Default I have no idea what I'm doing anymore(Java)

    This has been my life for two hours. I have to make a juggler class that creates three ball objects, and then can change their diameters. but I can't get the constructor to work, and I'm going crazy over it.

    Here is the code for the two classes. Please help!
    The error message says I am giving the wrong data type, but I'm just so confused about the project I can't find where it went wrong.


    Edit: I tried to change the data type in the constructor to ball, which worked but I can't make balls now. I'm being destroyed by this.
    Ball
    Code:
    /**
     * Ball
     * @author me
     * @version 1.0.2
     */
    
    /**
     * Public Class for the Ball
     */
    
    public class Ball{
        /**
         * Fields for the Ball Class
         */
        private String color;
        private int diameter;
        private String material;
        private String ballName;
        private String namePiece;
        private int bounces;
        /**
         * Constructors
         */
        public Ball(String anyColor, int anyDiameter, String anyMaterial, String anyName){
            color=anyColor;
            diameter=anyDiameter;
            material=anyMaterial;
            ballName=anyName;
            bounces = 0;
        }
        
        public Ball(int anyDiameter){
            diameter=anyDiameter;
            bounces = 0;
        }
        
        //--------------------------------------Accessor Methods-------------------------------------------//
        /**
         * Method to retrieve the color of the ball
         */
        public String getColor(){
            return color;
        }
        /**
         * Method to retrieve the Diameter of the ball
         */
        public int getDiameter(){
            return diameter;
        }
        /**
         * Method to retrieve the material of the ball
         */
        public String getMaterial(){
        return material;
        }
    
        /**
         * Method to display the number of bounces
         */
        public int getBounces(){
            return bounces;
        }    
        //--------------------------Mutator Methods----------------------------------//
        /**
         * Method to inflate/deflate the ball
         * Note that the max diameter is 256
         */
        public void setnewDiameter(int anyDiameterInflate){
        int diameterBackup;
        diameterBackup = diameter;
        diameter += anyDiameterInflate;
            if (diameter <= 0 || diameter > 256){
            System.out.println("BOOM!!!! YOU HAVE MADE THE BALL GO BYE BYE. \nGood thing that was a simulation. New ball created.");
            diameter = diameterBackup;
            }else if(diameter == 256){
            System.out.println("You should stop inflating the ball. It's kinda full.");
            }else if(diameter == 1){
            System.out.println("You should put some diameter in this ball. Or it will dissapear... :(");
            }else{
            System.out.println("Success! The new Diameter is now " + diameter);
            }
        }
        /**
         * Method to change the ball material
         */
        public void setMaterial(String anyMaterial){
        material = anyMaterial;
        }
         /**
         * Method to change the Diameter of the ball
         */
        public void setDiameter(int anyDiameter){
            diameter=anyDiameter;
        }
    
         /**
         * Method to change the Color of the ball
         */
        public void setColor(String anyColor){
            color=anyColor;
            ballName = color + namePiece;
        }
        /**
         * Method to print the ball info
         */
        public void printBallInfo(){
        System.out.println("The ball called " + ballName + " has the following properties!" + "\nDiameter: " + diameter + "\nMaterial: " + material);
        }
        /**
         * Method to change all the fields at once
         */
        public void setAll(String anyColor, int anyDiameter, String anyMaterial, String anyName){
            color= anyColor;
            diameter= anyDiameter;
            material= anyMaterial;
            ballName= color + anyName;
        }
         /**
         * Method to name the ball
         */
        public void setBallName(String anyName){
            namePiece = anyName;
            ballName = color + namePiece;
        }
        /**
         * Method to increase the the number of bounces by one
         */
        public void setBounceNumber(){
        bounces++;
        }
    }
    Juggler
    Code:
    /**
     * the juggler class is able to create 3 ball objects to use
     * It can set the diameter of each ball
     * 
     * @author me
     * @version 1.0.0
     */
    public class Juggler{
        private Ball ballOne;
        private Ball ballTwo;
        private Ball ballThree;
    
        /**
         * Constructor for objects of class Juggler
         * Creates three distinct ball objects
         */
        public Juggler(int ballOne, int ballTwo, int ballThree){
            ballOne = new Ball(1);
            ballTwo = new Ball(2);
            ballThree = new Ball(3);
            updateBallsDiameter();
    
        }
        
        /**
         * method that updates the three balls
         */
        
        public void updateBallsDiameter(int diameterOne, int diameterTwo, int diameterThree){
            ballOne.setnewDiameter(diameterOne);
            ballTwo.setnewDiameter(diameterTwo);
            ballThree.setnewDiameter(diameterThree);
        }
    }
    Last edited by qwertysaur; 04-02-2009 at 10:57 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •