Question: Here is the following task: (as a side note, I am coding in JAVA using repl.it) Create Spinner.java to simulate a board game spinner. Each
Here is the following task: (as a side note, I am coding in JAVA using repl.it)
Create Spinner.java to simulate a board game spinner. Each Spinner has a color and a number of sections. The spinner has an equal likelihood of landing in any of the sections.
The object should contain the following:
~ Data fields:
*Color (String)
*Number of Sections (int)
~Constructors:
*A default constructor. Have it set the color to red and the number of sections to 4.
*A custom constructor. Have it take 2 arguments, a String for the color and an int for the number of sections
~Methods:
*Getters:
public String getColor()
public int getNum()
*Setters:
public void setColor(String s)
public void setNum(int n)
*Method that simulates spinning the spinner. It returns a random number of one of the sections
public int spin()
I have the following code:
public class Spinner{
//instance variable
private String color;
private int sections;
//default constructor
public Spinner(){
color = "red";
sections = 4;
}
//instatiation
Spinner = new Type ("red" , 4)
//custom constructor
public Spinner (String c, int s){
color = c;
sections = s;
}
//getter
public String getColor()
public int getNum(){
return color;
}
//setter
public void setColor (String c)
public void setNum (int n)
{
public void setSections (int s);
}
public int getSections(){
return sections;
}
public String toString(){
return color + "," + sections + "sections"
}
//start spinning
public void set();
public int spin();
}
and then I put this code in a separate file:
public class Spin{ public static void main(String[]){ Spinner c1 = new color(); System.out.println(c1); Spinner c2) = new color ("Green", 4); System.out.println(c2); s.1num(1); System.out.println(s1.getSections()); } }
However I recieved the following errors:
Main.java:11: error:
Can someone help my code? Thank you.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
