Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 12 of 12

Thread: okay, i'm getting REALLY upset

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    6
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation okay, i'm getting REALLY upset

    okay, i have this final project to do and although i did well on the other hwk assignments, i feel like this assignment is suuuuupperrr hard, unless i am overthinking something. this is the description:

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

    a. Data fields for your instrument should include number of strings, an array of string names representing 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).

    2. Create a UML class diagram using a diagram tool (e.g. PPT, Visio) of your choice. Prepare the diagrams and place them in a word document along with a brief description of each of your classes.

    3. Create Java classes for your instruments. Be sure that your code matches your design specifications and some minimal functionality is included. For example, if you called the violin.play() method, you should at least print that the violin is playing. Similar functionality should be supplied when you stop playing, tune or call any of your methods. For example:

    public void playviolin() {
    System.out.println("The violin is now playing.");
    }

    4. Write the output from your Instrument class methods to a text file that a user entered from the command line arguments (e.g. java Mynamep3tst myfilename.txt). This allows your program to accept filenames from the user via a command line argument.

    5. Finally, create a Java test class that simulates using your instrument class. In your test class be you should at a minimum: a) Construct 10 instances of your instrument, b) tune your instruments, c) Start playing your instrument, d) Call your unique method, and e) Stop playing your instruments. (Hint: Arrays and Loops will make your job easier and result in more efficient code!)

    6. Your programs should compile and run without errors.

    here's what i have so far, it's probably super wrong. i'm having trouble with pretty much everything. like, i'm trying to figure out how to change the boolean from false to true while the instrument is playing, and i'm not really sure what to do with the arrays. from my understanding, the program is supposed to run w/out user input. also, there is nothing being written in the text file. it's just blank

    public class smp3 {
        public static void main(String[] args) throws Exception {
            //declare guitar object
            Guitar myGuitar = new Guitar();
     
            java.io.File file = new java.io.File("testresults.txt");
            //check to see if file already exists
            if (file.exists()){
                System.out.println("File already exists");
                System.exit(0);
            }
     
            //create a file
            java.io.PrintWriter output = new java.io.PrintWriter(file);
     
            //write test results to file
            output.println(myGuitar.doPlay());
            output.println(myGuitar.stopPlay());
            output.println(myGuitar.doTune());
     
     
     
            //declare array for guitar strings
            char [] guitarStrings = {'E','A','D','G','B','e'};
     
     
     
    }
     
        static class Guitar {
            boolean isTuned;
            boolean isPlaying;
     
            Guitar() {
                isTuned = false;
                isPlaying = false;
            }
     
            String doPlay (){
                return "The guitar is playing.";
            }
            String doTune(){
                return "The guitar is tuned.";
            }
     
            String stopPlay(){
                return "You have stopped playing.";
            }
     
        }
     
    }
    Last edited by msdiddyj; October 15th, 2011 at 04:53 AM. Reason: added code


  2. #2
    Member
    Join Date
    Aug 2011
    Posts
    55
    Thanks
    5
    Thanked 3 Times in 3 Posts

    Default Re: okay, i'm getting REALLY upset

    First, Your title for the post is not a good one. People have probably been inclined not to help because of the title. It should be a simple direct summary of
    the problem. Second, I would take the time to write out on paper a skeleton of the program using pseudo code. This will also help with your UML class
    diagram. Make a section for each method. define any input needed, any executable expressions, and the output expected. Break this big problem down
    into smaller ones, then tackle one at a time. In this case I would stub in the whole program first, naming each method accordingly. Then add any variables that are global, named constants, and then the variables that are local to each ,method. Then make your constructor. Sometimes its hard to conceptualize because the flow of writing the app is different then the flow of it executing. The good thing about addressing the smaller problems first is that then you can come back on the forums and ask for help in regards to a specific issue, which then more people will respond quicker to than just throwing your arms up
    and dumping your code in front of them.

  3. The Following User Says Thank You to mwr76 For This Useful Post:

    msdiddyj (October 15th, 2011)

  4. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    6
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: okay, i'm getting REALLY upset

    yeah, you're probably right. i'm just sooooo frustrated with this. i guess i can't change the title then, huh? i'm going to try again with a different approach and see what happens.

  5. #4
    Junior Member
    Join Date
    Oct 2011
    Posts
    6
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: okay, i'm getting REALLY upset

    okay, i started over. this is what i have so far for my guitar class and methods:

     
    class Guitar {
        boolean isTuned = false;    //by default guitar is not tuned
        boolean isPlaying = false;  //by default guitar is not playing
     
        //declare array for guitar strings
        char [] guitarStrings = {'E','A','D','G','B','e'};
     
        public Guitar() {   //construct default Guitar object
        }
     
        public void playGuitar() { 
            isPlaying = true;
        }
     
        public void stopPlaying() {
            isPlaying  = false;
        }
     
        public void tuneGuitar() {
            isTuned = true;
        }
     
    }

    i can't quite figure out what to do to individually tune each string. like in my test file, how would i do something to output "String E is tuned" ?

  6. #5
    Junior Member
    Join Date
    Oct 2011
    Posts
    6
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: okay, i'm getting REALLY upset

    bump. i realllyyy need help!

  7. #6
    Member
    Join Date
    Oct 2011
    Posts
    42
    My Mood
    Sneaky
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: okay, i'm getting REALLY upset

    Quickly reading over the requirements, it sounds like each string will be an object.

    A string has a name, isTunes, isPlaying, could be cool make tuned a number value, e.g 0. anything over and the string is sharp and lower and the string is flat, each time the string is accessed, it randomly gets a value 1, 0 or -1 added to the current tuned value).
    class GuitarString
    {
      private boolean isPlaying;
      private int tunedValue;
      private String name;
      /*
        declear the note sound variables here
      */
     
      public void GuitarString(){
        this.isPlaying = false;
        this.tunedValue = 0;
        this.name = "";
        /*
          initalize the note here
        */
      }
     public void GuitarString(String name){
        this.isPlaying = false;
        this.tunedValue = 0;
        this.name = name;
          /*
          initalize the note here
        */
      }
     public void GuitarString(String name, int tunedValue){
        this.isPlaying = false;
        this.tunedValue = tunedValue;
        this.name = name;
        /*
          initalize the note here
        */
      }
     
    //Could make another for a custom note
     
      public boolean getisPlaying(){
        return this.isPlaying;
      }
     public void setisPlaying(boo isPlaying){
        this.isPlaying = isPlaying;
      }
     
      public int getTunedValue(){
        return this.tunedValue;
      }
     public void setTunedValue(int tunedValue){
        this.tunedValue = tunedValue;
      }
     
     public int getname(){
        return this.name;
      }
     public void setName(String name){
        this.name= name;
      }
     
     // Then add in methods to make the string functional.
     
     public void playNote(){
        setIsPlaying(true);
        /*
           do playing sound stuff and set tuned value here
        */
        setIsPlaying(true);
      }
     
    }

    That is one way you could get started strings, you can then build your Guitar out of the GuitarStrings. Hopefully it will help inspire you

    (Before you ask, I deliberatly left the juicy bits for you, I don't want to take ALL your fun!)

  8. #7
    Junior Member
    Join Date
    Oct 2011
    Posts
    6
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: okay, i'm getting REALLY upset

    thanks, i'm going to try this and see how it works out. can i use my array with this, or no?

    eta: don't know what i'm doing wrong, but i tried to put an array where you said to declare the note sound variables and it is telling me that it is not a statement and ; expected.
    Last edited by msdiddyj; October 17th, 2011 at 01:31 AM.

  9. #8
    Member
    Join Date
    Oct 2011
    Posts
    42
    My Mood
    Sneaky
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: okay, i'm getting REALLY upset

    If you're going to use an array, rather than a collection, you will need to construct the string then add it to the array, e.g

     
    GuitarString GuitarStrings[] = new GuitarString[6];
     
    GuitarStrings[0] = new GuitarString("E"); // Depending on which constructor you are using
    GuitarStrings[1] = new GuitarString("A");
    GuitarStrings[2] = new GuitarString("D");
    GuitarStrings[3] = new GuitarString("G");
    GuitarStrings[4] = new GuitarString("B");
    GuitarStrings[5] = new GuitarString("E");


    The array of GuitarStrings should go in your Guitar class.

  10. #9
    Member
    Join Date
    Oct 2011
    Posts
    42
    My Mood
    Sneaky
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: okay, i'm getting REALLY upset

    The error expecting ; just means you're missing a ";" at the end of one of your lines, a good first palce to check is at the end of line before where the error occured.

    If you're still getting the not a statement error, post the code where its happening

  11. #10
    Member
    Join Date
    Oct 2011
    Posts
    42
    My Mood
    Sneaky
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: okay, i'm getting REALLY upset

    I'm not too sure how much experience you have with workign with objects, I made the assumption that since this is your final project you have make several programmes to learn how they interact?

    A Guitar has many GuitarStrings.

    So you will need to have Guitar class which contains instinces of the GuitarString.

  12. #11
    Junior Member
    Join Date
    Oct 2011
    Posts
    6
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: okay, i'm getting REALLY upset

    yes, this was my final project, but this was also an 8 week introductory java class. so i don't really have that much experience with objects, though i wish we could have done a more thorough lesson on it. honestly, this crap was SOOOOO confusing, but i did use bits of your code (thanks, you're a life-saver!). i'm not sure how well i did, but i tried my best lol. and noowww my java class is over, thank God. when i was a comp sci major in high school (went to a vo-tech school), i hated java, and i tried to give it another chance, but meh. i can't deal lol.

  13. #12
    Member
    Join Date
    Oct 2011
    Posts
    42
    My Mood
    Sneaky
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: okay, i'm getting REALLY upset

    I'm glad to hear that you finished it It sounds like apretty tough assignment after only an 8 week introduction. Hopefully you learned something, because in the end, thats what it's really all about.

Tags for this Thread