fork download
  1.  
  2. import java.awt.Color;
  3.  
  4. import java.lang.reflect.Field;
  5.  
  6. import java.util.Random;
  7.  
  8. public class Main {
  9. public static void main (String[] args) throws java.lang.Exception;
  10.  
  11. private int numStrings;
  12.  
  13. private double guitarLength;
  14.  
  15. private String guitarManufacturer;
  16.  
  17. private Color guitarColor;
  18.  
  19. public Main() {
  20.  
  21. //default constructor
  22.  
  23. numStrings = 6;
  24.  
  25. guitarLength = 28.2;
  26.  
  27. guitarManufacturer = "Gibson";
  28.  
  29. guitarColor = Color.RED;
  30.  
  31. }
  32. //these two fields are used to generate random note and duration
  33.  
  34. static char[] validNotes = { 'A', 'B', 'C', 'D', 'E', 'F', 'G' };
  35.  
  36. static double[] validDuration = { 0.25, 0.5, 1, 2, 4 };
  37.  
  38.  
  39. public Main(int numStrings, double guitarLength,
  40.  
  41. String guitarManufacturer, Color guitarColor) {
  42.  
  43. // parameterized constructor
  44.  
  45. this.numStrings = numStrings;
  46.  
  47. this.guitarLength = guitarLength;
  48.  
  49. this.guitarManufacturer = guitarManufacturer;
  50.  
  51. this.guitarColor = guitarColor;
  52.  
  53. }
  54.  
  55. // required getters and setters
  56.  
  57. public static char[] getValidNotes() {
  58.  
  59. return validNotes;
  60.  
  61. }
  62.  
  63. public static void setValidNotes(char[] validNotes) {
  64.  
  65. Guitar.validNotes = validNotes;
  66.  
  67. }
  68.  
  69. public static double[] getValidDuration() {
  70.  
  71. return validDuration;
  72.  
  73. }
  74.  
  75. public static void setValidDuration(double[] validDuration) {
  76.  
  77. Guitar.validDuration = validDuration;
  78.  
  79. }
  80.  
  81. public int getNumStrings() {
  82.  
  83. return numStrings;
  84.  
  85. }
  86.  
  87. public void setNumStrings(int numStrings) {
  88.  
  89. this.numStrings = numStrings;
  90.  
  91. }
  92.  
  93. public double getGuitarLength() {
  94.  
  95. return guitarLength;
  96.  
  97. }
  98.  
  99. public void setGuitarLength(double guitarLength) {
  100.  
  101. this.guitarLength = guitarLength;
  102.  
  103. }
  104.  
  105. public String getGuitarManufacturer() {
  106.  
  107. return guitarManufacturer;
  108.  
  109. }
  110.  
  111. public void setGuitarManufacturer(String guitarManufacturer) {
  112.  
  113. this.guitarManufacturer = guitarManufacturer;
  114.  
  115. }
  116.  
  117. public Color getGuitarColor() {
  118.  
  119. return guitarColor;
  120.  
  121. }
  122.  
  123. public void setGuitarColor(Color guitarColor) {
  124.  
  125. this.guitarColor = guitarColor;
  126.  
  127. }
  128.  
  129. //return a string containing 16 random notes and duration
  130.  
  131. public String playGuitar() {
  132.  
  133. int MAX = 16;
  134.  
  135. String notes = "[";
  136.  
  137. Random random = new Random();
  138.  
  139. for (int i = 0; i < MAX; i++) {
  140.  
  141.  
  142. notes += validNotes[random.nextInt(validNotes.length)] + "("
  143.  
  144. + validDuration[random.nextInt(validDuration.length)] + ")";
  145.  
  146. if (i == MAX - 1) {
  147.  
  148. notes += "]";
  149.  
  150. } else {
  151.  
  152. notes += ", ";
  153.  
  154. }
  155.  
  156. }
  157.  
  158. return notes;
  159.  
  160. }
  161.  
  162. // returns a string containing guitar info
  163.  
  164. public String toString() {
  165.  
  166. return "(numStrings: " + numStrings + ", length: " + guitarLength
  167.  
  168. + ", Manufacturer: " + guitarManufacturer + ", Color: "
  169.  
  170. + convertColorToString(guitarColor);
  171.  
  172. }
  173.  
  174.  
  175. public static String convertColorToString(Color c) {
  176.  
  177. for (Field f : Color.class.getFields()) {
  178.  
  179. try {
  180.  
  181. if (f.getType() == Color.class && f.get(null).equals(c)) {
  182.  
  183. return f.getName();
  184.  
  185. }
  186.  
  187. } catch (java.lang.IllegalAccessException e) {
  188.  
  189.  
  190.  
  191. }
  192.  
  193. }
  194.  
  195. return c.toString();
  196.  
  197. }
  198.  
  199. }
  200.  
  201.  
  202.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
numStrings=7
guitarLength=30.2
Manufacturer=Fender
Color=Black
compilation info
Main.java:9: error: missing method body, or declare abstract
	public static void main (String[] args) throws java.lang.Exception;
	                   ^
Main.java:65: error: cannot find symbol
            Guitar.validNotes = validNotes;
            ^
  symbol:   variable Guitar
  location: class Main
Main.java:77: error: cannot find symbol
            Guitar.validDuration = validDuration;
            ^
  symbol:   variable Guitar
  location: class Main
3 errors
stdout
Standard output is empty