Question
I can't figure out the following error I keep getting when I run the TestGuitar. Any help would be helpful. error: public String playGuitar() {
I can't figure out the following error I keep getting when I run the TestGuitar. Any help would be helpful.
error: public String playGuitar() {
import java.util.Random; import java.lang.StringBuilder;
// TestGuitar class public class TestGuitar { public static void main(String[] args) { //Construct three Guitars Guitar guitarOne = new Guitar(); Guitar guitarTwo = new Guitar(6,24.75,"Les Paul","Aquamarine"); Guitar guitarThree = new Guitar(6,25.5,"Fender","Blue Burst");
// Creates a random generator of musical notes public String playGuitar() { Random randomGenerator = new Random(System.currentTimeMillis()); String[] validNotes = {"A", "B", "C", "D", "E", "F", "G"}; String[] durationValues = {"0.25", "0.5", "1", "2", "4"}; //Creates an empty string builder StringBuilder musicalNote = new StringBuilder("["); for (int i=0; i<16; i++) { musicalNote.append(validNotes[randomGenerator.nextInt(7)] + "(" + durationValues[randomGenerator.nextInt(5)] + "),"); } // Call getter methods // Print results System.out.println(" toString(): " + guitar.toString()); System.out.println("getNumStrings(): " + guitar.getNumStrings()); System.out.println("getNumGuitarLength(): " + guitar.getGuitarLength()); System.out.println("getGuitarManufacturer(): " + guitar.getGuitarManufactrer()); System.out.println("getGuitarColor(): " + guitar.getGuitarColor()); System.out.println("playGuitar(): " + guitar.playGuitar() + " "); } }
--
import java.util.Random; import java.lang.StringBuilder;
public class Guitar { private int numStrings; private double guitarLength; private String guitarManufacturer; private String guitarColor;
// Guitar constructor public Guitar(int numS, double guitarL, String guitarM, String guitarC) { numStrings = numS; guitarLength = guitarL; guitarManufacturer = guitarM; guitarColor = guitarC; }
// Default Guitar constructor public Guitar() { numStrings = 6; guitarLength = 28.2; guitarManufacturer = "Gibson"; guitarColor = "Red"; }
// Setter methods // setNumS public void setNumStrings(int numS) { numStrings = numS; }
// setGuitarLength public void setGuitarLength(double guitarL) { guitarLength = guitarL; }
// setGuitarManufacture public void setGuitarManufacturer(String guitarM) { guitarManufacturer = guitarM; }
// setGuitarColor public void setGuitarColor(String guitarC) { guitarColor = guitarC; }
// Getter methods // getNumStrings public int getNumStrings() { return numStrings; }
// getGuitarLength public double getGuitarLength() { return guitarLength; }
// getGuitarManufacturer public String getGuitarManufacturer() { return guitarManufacturer; }
// getGuitarColor public String getGuitarColor() { return guitarColor; }
// Random musical note generator public String playGuitar() { Random randomGenerator = new Random(System.currentTimeMillis()); String[] validNotes = { "A", "B", "C", "D", "E", "F", "G" }; String[] durationValues = { "0.25", "0.5", "1", "2", "4" };
// String builder for musical notes StringBuilder musicalNote = new StringBuilder("["); for (int i = 0; i < 16; i++) { musicalNote.append( validNotes[randomGenerator.nextInt(7)] + "(" + durationValues[randomGenerator.nextInt(5)] + "),"); } String finalStr = musicalNote.toString(); finalStr = finalStr.substring(0,finalStr.length() - 1) + "]"; return finalStr; } public static void main(String[] args) { Guitar gt = new Guitar(); System.out.println(gt.playGuitar()); System.out.println(gt.playGuitar()); System.out.println(gt.playGuitar()); System.out.println(gt.playGuitar()); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started