Question

In: Computer Science

This code in java: A typical ball is circular in shape. Many games are played with...

This code in java:

A typical ball is circular in shape. Many games are played with ball e.g cricket ball football etc. Impingement a scenario in which you create cricket ball and football or any other game ball. All balls differ in color, size and material

Solutions

Expert Solution

I have created a ball class, that represents the ball in general. A ball can be represented by its properties, like size, color, material, game, etc. As these properties are defined, we get the purpose of the ball. Similarly we can define a ball class having above properties. These properties of a ball can be set when defining a new ball object, or after the object is defined. once we have a ball class, we can define different objects representing different types of balls.

I have attached relevant comments in the example code below. I hope you find it helpful.

As an example, I have created two sample ball objects, cricketBall and football representing actual game balls.


public class ball {

    public static void main(String[] args) {
        Ball cricketBall = new Ball("cricket", "leather", "white", 10);
        Ball football = new Ball("football", "synthetic", "white", 50);

        System.out.println(cricketBall.getColour());
        System.out.println(football.getColour());
    }
}

class Ball {
    //colour of the ball
    private String colour;
    //size of the ball in cm
    private int size;
    //material of the ball
    private String material;
    //game where the ball is used
    private String game;

    //initialise the ball(any kind) with the following properties
    Ball(String game, String material, String colour, int size) {
        this.colour = colour;
        this.game = game;
        this.size = size;
        this.material = material;
    }

    /**
     * @return returns colour of the ball
     */
    public String getColour() {
        return colour;
    }

    // sets the colour of the ball
    public void setColour(String colour) {
        this.colour = colour;
    }

    //returns the size of the ball
    public int getSize() {
        return size;
    }
    // sets size of the ball
    public void setSize(int size) {
        this.size = size;
    }
    
    //returns the material of the ball
    public String getMaterial() {
        return material;
    }
    
    //sets the material of the ball
    public void setMaterial(String material) {
        this.material = material;
    }

    //returns the game where the ball is used
    public String getGame() {
        return game;
    }

    //sets the game property of the ball
    public void setGame(String game) {
        this.game = game;
    }
}

Related Solutions

The code is needed in Java. There are many ways to design a solution to this...
The code is needed in Java. There are many ways to design a solution to this problem but you are evaluated on meeting the specific specifications as given in this quiz. Use proper statement indentation and meaningful variable names in the code. (3 points) Place a multi-line comment (not multiple single line comments) giving a description of what this application does before the class header. Include your name and the date with the description. (2 points) Output spacing, formatting, and...
The average score for games played in the NFL is 22.4 and the standard deviation is...
The average score for games played in the NFL is 22.4 and the standard deviation is 9.1 points. 43 games are randomly selected. Round all answers to 4 decimal places where possible and assume a normal distribution. A. What is the distribution of ¯xx¯? ¯xx¯ ~ N(,) B. What is the distribution of ∑x∑x? ∑x∑x ~ N(,) C. P(¯xx¯ > 22.3185) = D. Find the 60th percentile for the mean score for this sample size. E. P(21.0185 < ¯xx¯ <...
The average score for games played in the NFL is 21 and the standard deviation is...
The average score for games played in the NFL is 21 and the standard deviation is 9.3 points. 10 games are randomly selected. Round all answers to 4 decimal places where possible and assume a normal distribution. What is the distribution of ¯xx¯? ¯xx¯ ~ N(,) What is the distribution of ∑x∑x? ∑x∑x ~ N(,) P(¯xx¯ < 20.9887) = Find the 70th percentile for the mean score for this sample size. P(20.5887 < ¯xx¯ < 23.3705) = Q1 for the...
The average score for games played in the NFL is 22 and the standard deviation is...
The average score for games played in the NFL is 22 and the standard deviation is 9 points. 13 games are randomly selected. Round all answers to 4 decimal places where possible and assume a normal distribution. What is the distribution of ¯xx¯? ¯xx¯ ~ N(,) What is the distribution of ∑x∑x? ∑x∑x ~ N(,) P(¯xx¯ > 19.1557) = Find the 72th percentile for the mean score for this sample size. P(20.0557 < ¯xx¯ < 25.0481) = Q1 for the...
The average score for games played in the NFL is 20.7 and the standard deviation is...
The average score for games played in the NFL is 20.7 and the standard deviation is 9.3 points. 49 games are randomly selected. Round all answers to 4 decimal places where possible and assume a normal distribution. What is the distribution of ¯xx¯? ¯xx¯ ~ N(,) What is the distribution of ∑x∑x? ∑x∑x ~ N(,) P(¯xx¯ < 21.7071) = Find the 68th percentile for the mean score for this sample size. P(19.6071 < ¯xx¯ < 21.9643) = Q3 for the...
The average score for games played in the NFL is 22.2 and the standard deviation is...
The average score for games played in the NFL is 22.2 and the standard deviation is 8.9 points. 12 games are randomly selected. Round all answers to 4 decimal places where possible and assume a normal distribution. What is the distribution of ¯ x x¯ ? ¯ x x¯ ~ N(,) What is the distribution of ∑ x ∑x ? ∑ x ∑x ~ N(,) P( ¯ x x¯ > 19.7462) = Find the 65th percentile for the mean score...
Objective: Using Java coding language, complete each "TO-DO" section for the following classes. Shape code (for...
Objective: Using Java coding language, complete each "TO-DO" section for the following classes. Shape code (for reference, nothing to complete here): import java.awt.Color; import java.awt.Graphics; import java.awt.Rectangle; import java.io.RandomAccessFile; public abstract class Shape extends Rectangle {    public int id;    public Color color;    public int xSpeed, ySpeed;       public Shape(int id, int x, int y, int width, int height, Color color, int xSpeed, int ySpeed) {        super(x,y,width,height);        this.id = id;        this.color...
Evaluate Grade for Shipping Company - Code in Java There are many Shipping companies emerging in...
Evaluate Grade for Shipping Company - Code in Java There are many Shipping companies emerging in the market now. 'SaySo' online survey panel has come up with the strategy to choose the best Shipping Company for your shipping needs. The survey panel has taken into consideration two factors of the companies namely the number of countries a shipping Company offers its services (country coverage) and number of shipments done per month. The survey panel has graded the companies based on...
The following data represent the number of games played in each series of an annual tournament...
The following data represent the number of games played in each series of an annual tournament from 1923 to 2001. Complete parts​ (a) through​ (d) below. x​ (games played) 4 5 6 7 Copy to Clipboard + Open in Excel + Frequency 17 14 22 25 ​(a) Construct a discrete probability distribution for the random variable x. x​ (games played) ​P(x) 4 5 6 7 ​(Round to four decimal places as​ needed.) ​​(c) Compute and interpret the mean of the...
Roulette is one of the most common games played in gambling casinos in Las Vegas and...
Roulette is one of the most common games played in gambling casinos in Las Vegas and elsewhere. An American roulette wheel has slots marked with the numbers from 1 to 36 as well as 0 and 00 (the latter is called "double zero"). Half of the slots marked 1 to 36 are colored red and the other half are black. (The 0 and 00 are colored green.) With each spin of the wheel, the ball lands in one of these...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT