Question

Write a class named DartSector. The constructor should accept a sector number and position {Single, Double,...

Write a class named DartSector. The constructor should accept a sector number and position {Single, Double, Treble, Outer & Inner} represented with the integers 1 – 5 respectively. The class should have 3 methods: • getSectorColor – method should return the pocket’s color (as a String) • singleThrow – method should generate 2 random numbers; one in the range (1..20) and another (1..5); and return the score for the throw. • throwThree – method should generate 3 sets of random numbers, as above; and return the sum of the scores for these three throws. Demonstrate the class in a program that asks the user to select the number of throw desired (1 or 3, validating user input is one of these), then calls the appropriate method to generate those throws; if a single spin, gives the resulting sector and color on the monitor; if 3 spins, uses a loop to display all the sectors and colors, each throw on a separate line.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;

public class DartSector {

    private int sector, position;


    public DartSector(int sector, int position) {
        this.sector = sector;
        this.position = position;
    }

    public String getSectorColor() {
        // derive the color from sector number
        return "";
    }

    public String getPosition() {
        String pos[] = {"", "Single", "Double", "Treble", "Outer", "Inner"};
        return pos[position];
    }

    public int singleThrow() {
        int r1 = (int) (Math.random() * 20 + 1);
        int r2 = (int) (Math.random() * 5 + 1);
        System.out.println("(" + r1 + "," + r2 + ")");
        return r1 + r2;
    }
    public int throwThree() {
        int score = singleThrow();
        score += singleThrow();
        score += singleThrow();
        return score;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        System.out.println("Enter number of throws: ");
        int t = in.nextInt();

        while(t != 1 && t != 3) {
            System.out.println("Invalid moves.");
            System.out.println("Enter number of throws: ");
            t = in.nextInt();
        }

        DartSector sector = new DartSector(1, 2);
        if(t == 1) {
            sector.singleThrow();
        } else {
            sector.throwThree();
        }

        in.close();
    }

}

I do not understand what is a sector and how to find colors, but the above code should help you.. Still in case of issue, ask in comments.

Add a comment
Know the answer?
Add Answer to:
Write a class named DartSector. The constructor should accept a sector number and position {Single, Double,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a class named MonthDays. The class’s constructor should accept two arguments: l An integer for...

    Write a class named MonthDays. The class’s constructor should accept two arguments: l An integer for the month (1 = January, 2 February, etc). l An integer for the year The class should have a method named getNumberOfDays that returns the number of days in the specified month. The method should use the following criteria to identify leap years: 1. Determine whether the year is divisible by 100. If it is, then it is a leap year if and if...

  • Write a Lottery class that simulates a 6-number lottery (e.g. "Lotto"). The class should have an...

    Write a Lottery class that simulates a 6-number lottery (e.g. "Lotto"). The class should have an array of six integers named lotteryNumbers, and another array of six integers named userLotteryPicks. The class' constructor should use the Random class to generate a unique random number in the range of 1 to 60 for each of the 6 elements in the lotteryNumbers array. Thus, there should be a loop that keeps generating random numbers until all 6 numbers are unique.  The Lottery class...

  • Write a class called Primes. This class should contain a constructor and a method called next_prime....

    Write a class called Primes. This class should contain a constructor and a method called next_prime. The next_prime method returns the next prime number. For example: >>> n = int(input('How many prime numbers?\n')) >>> p = primes() >>> prime_numbers = [ ] >>> for i in range(n): >>> prime = p.next_prime() >>> primes_numbers.append(prime) >>> print(prime_numbers) If the user types 5 in response to the prompt, then the output should be [2, 3, 5, 7, 11]. python 2.7.13

  • Java Please - Design and implement a class Triangle. A constructor should accept the lengths of...

    Java Please - Design and implement a class Triangle. A constructor should accept the lengths of a triangle’s 3 sides (as integers) and verify that the sum of any 2 sides is greater than the 3rd(i.e., that the 3 sides satisfy the triangle inequality). The constructor should mark the triangle as valid or invalid; do not throw an exception. Provide get and set methods for the 3 sides, and recheck for validity in the set methods. Provide a toString method...

  • C++ 1. Start with a UML diagram of the class definition for the following problem defining a utility class named Month. 2. Write a class named Month. The class should have an integer field named month...

    C++ 1. Start with a UML diagram of the class definition for the following problem defining a utility class named Month. 2. Write a class named Month. The class should have an integer field named monthNumber that holds the number of the month (January is 1, February is 2, etc.). Also provide the following functions: • A default constructor that sets the monthNumber field to 1. • A constructor that accepts the number of month as an argument and sets...

  • You will write a class called Shoe.java Shoe.java should have Three instance variables String brand (cannot...

    You will write a class called Shoe.java Shoe.java should have Three instance variables String brand (cannot be blank) double size (from 5 to 12) int color (a number from 1 to 5 representing one of 5 colors) This code is to control the amount of colors. the colors represented are as follows 1. red 2. green 3. blue 4. black 5. grey One constructor, one get method per instance variable, one set method per instance variable. You will need a...

  • Write a class named Month. The class should have an int field named monthNumber that holds...

    Write a class named Month. The class should have an int field named monthNumber that holds the number of the month. For example. January would be 1. February would be 2. and so forth. In addition, provide the following methods A no-arg constructor that sets the monthNumber field to 1 A constructor that accepts the number of the month as an argument. It should set the monthNumber field to the value passed as the argument. If a value less than...

  • LW: Class Constructors Objectives Write a default constructor for a class. Note that this const...

    LW: Class Constructors Objectives Write a default constructor for a class. Note that this constructor is used to build the object anytime an argument is not provided when it is defined. Write a parameterized constructor that takes arguments that are used to initialize the class’s member variables Labwork Download the code associated with this lab: ColorConstructor.zip Main.cpp Color.h Color.cpp Compile and run the code. The first line of output of the program should display nonsensical integers for the values of...

  • Please use C++. Write a class named Circle that has a double data member named radius...

    Please use C++. Write a class named Circle that has a double data member named radius and a static double data member named maxRadius. It should have a default constructor that initializes the radius to 1.0. It should have a constructor that takes a double and uses it to initialize the radius. It should have a method called calcArea that returns the area of the Circle (use 3.14159 for pi). It should have a static set method for the maxRadius....

  • Room Class....... in JAVA!!!!! Write a class named Room that has the following fields: Length: Double...

    Room Class....... in JAVA!!!!! Write a class named Room that has the following fields: Length: Double variable that holds the rooms length(in feet). Breadth: The double variable that holds the rooms breadth(in feet). Height: Double variable that holds rooms height in feet. Color: String object that holds the color you want the room to be painted with. The class should have a constructor to initialize the fields for a particular instance (or object) of the class as given: All double...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT