Design and implement a stringed musical instrument class using the following guidelines:

a. Data fields for your instrument should include number of strings, variables for string names (e.g. E, A, D, G), and boolean fields to determine if the instrument is tuned, and if the instrument is currently playing. You are welcome to add additional data fields if you like.

b. A constructor method that set the tuned and currently playing fields to false.

c. Other methods 1) to tune the instrument, 2) to start the instrument playing, and 3) to stop the instrument from playing.

d. Other methods as you see fit (Add at least one unique method).

I have the following code. I think my problem is that i have a class within a class and I have not declared it correctly. Please Help! Thanks in advance!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{


class Guitar
{


bool isTuned; //Guitar starts off not tuned
bool isPlaying; //Guitar is not playing at start


//array for Guitar strings
char [] GuitarStrings = {'E','A','D','G'};


//default Guitar object
public Guitar()
{
isTuned = false;
isPlaying = false;
Console.Write("The Guitar is not playing, and it is not tuned.");
}


public Guitar(bool T, bool P)
{
isTuned = T;
isPlaying = P;
}


public bool playGuitar()
{
Console.Write("The Guitar is playing!");
return isPlaying = true;
}


public bool stopPlaying()
{
Console.Write("The Guitar has stopped playing.");
return isPlaying = false;
}


public bool tuneGuitar()
{
Console.Write("The Guitar is being tuned!");
return isTuned = true;


System.Console.WriteLine("Hit Enter to continue");


System.Console.ReadLine();


}


}


}
}

First, don't attempt to define classes inside Main.
Second, you have some unreachable code. VS should underline these for you.

[Technique]
Remove all printing statements from your class. It might not always be used with a Console app.
Determine the need to print and the output mechanism outside the class.

I would suggest to use a instrument interface that defines the common priperties for each and every intrument like the NumberOfNotes, the AvailableNotesToPlay, the TunedStatus and the PlayingStatus.

Then you can create as many instruments you need by defining they use this interface. VS will provide you the help to implement it.

As said by thines01, better you define your interface and classes in a new class module.

Hope this help

Did you fix it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.