• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Object Oriented Programming confusion

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm struggling with understanding OOP in general. I thought I understood it, but according to my professor, I don't. This is his feedback from my last assignment, followed by my code. I wrote and ran the code in NetBeans 7.3.1 without any problems, so I'm not sure what he means when he says that it doesn't run. I have included the assignment requirements as a quote since I cannot attach a .doc file. I'm not looking for someone to do my assignment for me, I'm looking to legitimately learn and understand what isn't OO about my assignment and receive guidance that would help me learn what I did wrong so that I may fix it.

Jacob,

Your program does not run because it does not have a dedicated class. You cannot use PRJ3RennelsJ as the class for the instruments. You need to create a separate class. Please rework this assignment and resubmit. You have until Saturday evening to submit a new program that is consistent with OO. You will get a grade today with 0 for Project 3, but that will change when you turn in a program that is workable in OO.




Assignment requirements:

CMIS 141: Java Programming
Project 3
This project focuses on demonstrating your understanding of classes and objects. In addition you will demonstrate generating a text file. Before attempting this project, be sure you have completed all of the reading assignments listed in the syllabus to date, participated in the weekly conferences, and thoroughly understand the examples throughout the chapters.

There are several ways of executing this program. One way is to execute the program on a “command line” as referenced in the readings. This assignment is not being executed in that manner; it is being processed in the same way all the other assignments were completed in this class.

This program gives a user the opportunity to “play” a musical instrument. Since there are ten instances of a musical instrument, you can play several of the musical instruments (instances) before ending the program. It is expected that there will be at least two instances appearing in you output text file.

Project 3 (25 percent):

1. Create a Java Application Project named PRJ3[Last Name][First Initial]. As an example, if your name was Xavier Smith, then the project would be named PRJ3SmithX. Even though many examples show the class as a separate file from the main program, this assignment will consist of a single program file and no additional files for class.
2. Review the requirements for the program (3 a. – 3 d.) then generate a test plan in a document named PRJ3SmithXTestPlan using the Test Plan Explanation with Rubric document listed in Week 1 Activities.
3. Once you are in the IDE with the tabbed PRJ3SmithX.java in the Source window, begin developing the following program:

a. Identifiers for your instrument should include:

1) An array for a string instrument with at least ten instances. [The values in the various cells can be the names of various types of string instruments, e.g., violin, guitar, 12-string guitar, etc. However, it is expected that the array will either have an individual number or letter, or a combination number-letter if it is designated as an inventory item.]
2) An array for the strings of the string instrument, for example, a guitar normally uses E, A, D, G, B, and E for determining a chord. [Other string instruments have different string configurations, e.g. violin uses G, D, A, and E. This element can be researched for a different instrument. It is assumed that because of the complexity of this assignment, the program will probably use a single instrument with a single set of strings.]
3) A Boolean field to determine if the instrument is tuned.
4) A Boolean field to determine if the instrument is currently playing.
5) A volume that allows ten increments of sound (1-10) while the instrument is playing.
6) A register for an instance of the instrument that allows five levels (1-5).
7) A tone control for an instance of the instrument that allows five modes (1-5).
8) A pickup configuration that allows three choices (bridge, neck, or both).
9) A chord array based on the size determined by the array of strings mentioned (See 2) above). [For the purposes of this assignment, a chord is a set of two or more strings of an instrument sounded at the same time.]

b. A constructor method that initializes the variables in the class.

c. Methods include:

1) An interactive element that requests from the user the selection of one of the ten instances of the string instrument array to change. [This method is in main. There should probably be some list to choose from.]
2) An interactive process that goes through a set of sequential questions (no menu) based on all the attributes of an instrument instance, changes the values of some or all of the attributes for an instance of the string instrument, for example, from not playing to start playing an instance of guitarFour [the selected instance from the ten choices]:

Do you want to play guitarFour? (Y/N)

[The user would then enter a Y, y, N, n after this question and the program would assign that value to the appropriate identifier.]

3) Among the questions within c. 2., there is a method that selects a specific chord on the string instrument instance for playing. [Note: it is best to have individual requests for each of the strings that will be part of a specific chord, so an instrument with four strings would have four questions with a yes or no answer for including the string in the chord. The resulting display would show on a single line only the strings that were selected. So using a violin with G, D, A, and E, if only D and E had a yes response, then the output would be D E.]
4) Display in the Output window all processing as the program runs about an instance of the string instrument, e. g, all the questions and answers in the interactive section for the attributes of the string instrument instance.
5) Output to a text file the various attributes of the instance of the instrument – do not include any of the questions from c. 2. above – with two different sets:

a. the initial state of the string instrument instance [added at the beginning of the method]
b. the state after processing that instance [added after all the questions are answered]

The following is an example of coding that might be used with this requirement.

FileWriter instrumentFile;
instrumentFile = new FileWriter("instrumentConfig.txt", true);
PrintWriter Configuration = new PrintWriter(instrumentFile);

Configuration.print("Instrument status follows:\n");

6) If more than one instance is selected, then each instance appears in the text file with its own set of initial and final states.
7) The text file should default to the Project folder under CMIS141.

d. The program structure (see Skeleton at end of this document) should have

1) The main function:

a) Declare an array of ten instances for the instrument.
b) Declare the necessary elements for a text file.
c) Declare additional variables as necessary.
d) A looping structure that

• Selects an instance of the string instrument.
• Displays the initial state of that instance in the Output window and in the text file.
• Once a specific instance is select, allows the user to change some or all of the values of the attributes of that instance of the instrument displaying the whole process in the Output window.

e) At the end the looping structure, display the modified instance of the instrument in the Output window and in the text file.
f) Prompt the user to end the loop or continue to modifying another instance of the instrument.

2) The class section:

a) Declare all appropriate identifiers.
b) Declare an array for the strings of the instrument.
c) Initialize the variables in the constructor.
d) An interactive method to change values the attributes of an instance of the instrument.
e) An output method to display information in the Output window called at the loop.
f) An output method to display information to the text file called at the end of the loop.
g) Methods to change the values of various class identifiers, including making a chord.

When changing a value that is declared inside of the class, the method does not require passing the value to that method. There is also no need for a return line, so the method should be void. [Review the examples at the end of Homework 4.] For example, if you called the guitar.play() method, the method would look like:

public void play() {
isPlaying = true;
System.out.println("The guitar is now playing.");
} // end play ()

4. Write the output from your instrument class methods to a text file, e.g. PRJ3SmithXFile.txt.
5. When the assignment works correctly for all parts, capture images of the results from the Output window for each of the test plan sets of data – the program will have to run for each of the sets – and paste each of them after the test plan prepared in Item 2. above into a file PRJ3SmithXTestPlan.
6. Once you complete the Project 3 program attach the PRJ3SmithX.java file from the appropriate folder under the CMIS141 folder as well as the PRJ3SmithXTestPlan file to the appropriate Assignment element.
7. Based on the coding of the program, create a UML class diagram using a diagram tool using either MS PowerPoint or Visio. Prepare the diagrams and place them in a MS Word document along with a brief description of each of your classes. For help with UML:

http://www.smartdraw.com/resources/tutorials/uml-diagrams/

another reference that can be helpful is

http://www.lucidchart.com/

and a third reference [perhaps best place to start]

http://en.wikipedia.org/wiki/Unified_Modeling_Language

8. The UML diagram document is named PRJ3SmithXUML. Submit this document with the two identified in 6 above to the appropriate Assignment element.

Reference the concept of objects:

http://docs.oracle.com/javase/tutorial/java/concepts/object.html



Design Rubric for Project 3 (20 percent):

• Coding is properly ordered with declarations for the identifiers in main and class, inside a while loop select on instance off menu/list, write to text initial attributes, solicit responses from user, display summary results, write to text modified/final attributes, repeat until user ends loop, and a final message before ending the program
• Declare an array of ten instances for an instrument [String or integer data type]
• Declare the necessary elements for a text file
• Use of Boolean data type for binary responses
• Declare additional variables as necessary for the instrument attributes
• Calls to appropriate methods

In the class:

• Declare all appropriate identifiers
• Declare an array for the strings of the instrument [a chord array]
• Initialize the variables in the constructor
• Interactive method to change values the attributes of an instance of the instrument
• Output method to display information in the Output window called in the loop
• Output method to display information to the text file called at the beginning and the end of the loop
• Methods to change the values of various class identifiers, including making a chord

Within a loop:

• A menu or listing that allows user to select an instrument instance from the ten choices
• An interrogatory section with uses selecting various elements for the attributes of the instrument instance with user-friendly prompts
• Displays result of all the attribute results from the interrogatory section
• Displays result of user-selected chord on screen
• Prompt for continuation of loop to select and modify additional instrument instances

In the text file:

• The initial state for all the attributes of a selected instance written vertically
• The final state for all the attributes of a selected instance written vertically
• Additional sets of initial/final states for different selected instances

• There is no redundant coding
• The appropriate libraries are imported
• The Java class properly structured
• A properly developed UML diagram

Functionality Rubric for Project 3 (40 percent):

• Correctly declared all identifiers
• Appropriate loop continues until test is false
• All requested values are properly entered
• Correctly constructed a method using a call with parameters to display the appropriate information
• Interactive request for specific instance from the ten-element array
• Interactive section requesting user to select from a sequential list attributes of the instrument should be changed – all or some of the attributes
• Interactive request for a specific chord on the instrument
• Displaying results of all elements of the program including
• Prompt to continue modifying another instance or ending the program
• Output window displays menu/list
• Output window displays questions for modification of various elements of the attributes, including the chord
• Text file vertically written initial state of an instrument instance
• Text file vertically written modified/final state of an instrument instance
• Repeated sets of initial/final state for additional instrument instances
• Used the requested text
• Coded the requested blank lines
• Coding was implemented correctly
• All requested elements of the program were implemented

Documentation Rubric for Project 3 (20 percent):

• Refer to Documentation Explanation with Rubric in Week 1 Activities.

Test Plan Rubric for Project 3 (20 percent):

• Refer to Test Plan Explanation with Rubric in Week 1 Activities.


1. The skeleton:

package prj3programmerame;

/*
* @author Programmer Name
*/

import java.* ; section

public class PRJ3ProgrammerName {

public static void main(String[]args) {

- Declarations
- Loop to select instance and interactively change instances of the instrument and output initial state and final state of an instance

}// end main

}//end PRJ3ProgrammerName class

public class [InstrumentName] {

[Variable declarations]

//constructor for class
public [InstrumentName] () {

[Variables Initialized]

}//[InstrumentName] constructor

public void [A Method Name] () {

[Code for the method]

}//end [A Method Name]

}//end [InsturmentName} class

 
Jake Rennels
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I *think* I answered my own question. Does this code appear to be correct object oriented code?
 
Marshal
Posts: 80222
424
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

No. It doesn't. You got off to a good start by trying an InstrumentApp class. But your app only knows about guitars. What about violins, flutes, etc? You ought to have written an Instrument class, as you have been told. Do you know about inheritance, so you can subclass Instrument with Guitar, Violin etc? In which case, do all guitars have the same string tuning? Are they all EADGBE? I think all violins are GDAE and all cellos and violas are CGDA. Can you initialise that array in the Instrument class constructor? You need to add the other fields mentioned e.g. tuning to the Instrument class.
The Writer objects should not be fields. They should be local variables. You must close the writers after use, probably best done with try with resources.
Good luck with it. You are lucky to have a second chance.
 
Campbell Ritchie
Marshal
Posts: 80222
424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please review your code style. Your code is difficult to read because you have crammed it all together. You have too many //comments. Some of those comments ought to be documentation comments (even on private fields when they don't appear in the output). You have got lines too long. You have used that dreadful, error‑prone construct == true.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Please review your code style. Your code is difficult to read because you have crammed it all together.


And your lines are FAR TOO LONG.
The rule here is:
80 characters max.
(the SSCCE page actually recommends 62)
And that includes string literals AND comments AND long method calls.

Thanks.

Winston
 
Jake Rennels
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Campbell, thanks for the welcome. It's 3:30am and I'm a little foggy right now, so please bear with me as I try to clarify and gain some understanding. I will rename my instrumentApp class stringIntruments to provide some clarification there and instead of using 10 guitars, will rename them Instrument 1, Instrument 2, etc. This should still be in line with assignment parameters and possibly help me visualize what I am doing with the code.

You asked if I know about inheritance, I do not. After doing some reading it seems like a way to have one class call for variable from another class which contains code that tailors it to the needs of the requesting class. Let's see if I understand this correctly:
PRJ3RennelsJ will remain unchanged
instrumentApp will no longer list 10 guitars, it should instead query an array populated by a third class, instrumentStrings
instrument Strings would be it's own class with a three dimensional array, the first column being the instrument name and the additional columns being the names of the strings. This would present the problem of figuring out how to have the loop read only the number of columns necessary and not the maximum number, something I'll have to google.

If I understand this, I don't see the benefit of having the third class, versus having it as a method.

As far as tuning goes, I thought I addressed that in line 129, but maybe I'm misinterpreting the assignment requirement.

I'm completely lost understanding your sentence about the Writer objects.

This is my first programming course and was only seven weeks of learning, the first five of which I aced. Week six and this last week were OOP and I'm struggling to wrap my head around it. I've combed through the textbook a few times as well as docs.oracle, stackoverflow, javabeginner and this site, but for some reason it isn't "clicking" in my head. It probably doesn't help that I'm a tactile learner and I'm having a tough time following some of the examples I've been able to come across, including the example at the end of the assignment instructions included above. I'll go through and see if I can't shorten up my lines, add some blank spaces between blocks of code and find ways to consolidate // comments into /* */ comments once I gain some understanding of what I'm doing wrong as far as OOP is concerned.

Thanks again for your help as I struggle through this. I get my CPAP machine in the morning, with any luck I'll start getting more sleep soon and this will click in time for the new deadline.
 
Ranch Hand
Posts: 235
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote: You have used that dreadful, error‑prone construct == true.


If I might ask, could/would you elaborate on this, please? I'm unfamiliar with why, exactly, this is considered error prone, outside of not initializing construct before using it.

Note: I began writing (business application) software in the mid 80's through 2002ish. I understand the concepts well enough, I'm just a tad rusty.
 
Campbell Ritchie
Marshal
Posts: 80222
424
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Never if (b == true) ...
Use if (b) ...
Never if (b == false) ...
Use if (!b) ...

Imagine what will happen if you do what we see about once every three months on this forum. You write if (b = true) ... by mistake.
The same applies to while and similar.
 
Robert D. Smith
Ranch Hand
Posts: 235
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply and the insight. That was my thoughts on the matter; just wanted to make sure I wasn't missing something.
 
Jake Rennels
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm really racking my brain trying to figure this out. Maybe if I rephrase my question, someone can help clarify the issue for me? In my latest rewrite of the code, I'm trying a different approach, hoping that this latest semi-educated guess reflects OOP. As much as I've read online and in my text, it just doesn't seem to "click" with me. It's obviously not finished and I know I will need to change my data types for some areas, but would this approach be considered OO?

 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jake Rennels wrote:In my latest rewrite of the code, I'm trying a different approach, hoping that this latest semi-educated guess reflects OOP. As much as I've read online and in my text, it just doesn't seem to "click" with me.


Well, first off - Your new program looks MUCH better. It's nicely indented, and your lines aren't too long any more; so, well done there.

Second - The OO thing: don't sweat it. It took me 8 years for my 'Eureka' moment, but I started out with procedural languages. You have the advantage that you're starting out from scratch with Java, but don't expect it to all fall into place at once.
There are still a few simple things that you can remember to help you write good code:
  • Don't repeat code. If you find yourself doing so, think how you might put it in a method. It's called the DRY principle.
  • Code does NOT solve problems; you do. So, when you run into problems, StopCoding (←click).
  • When you first sit down to a problem, think about WHAT you need to do, not HOW you're going to do it. It's one of the hardest lessons for beginners to learn because you're just dying to code, but it's absolutely essential. The WhatNotHow (←click) page might help you out there; and in your case it probably means reading and re-reading those requirements until you know them upside-down and back-to-front.

  • And just a couple of specific things I see in your program:
    1. Why are all your fields ints? I suspect that some of them are indexes to arrays, but that's not a particularly "OO" way of doing things; and I suspect you may end up tying yourself in knots with all those "element" references.

    I'm no music expert, but I suspect that I'd be looking at an enum to store my notes (or tones; not sure of my terminology here). Perhaps something like:and then maybe another for the octave pitch, another for the volume...
    Basically, enums are great for anything that has a fixed set of valid "values" because:
    (a) You can't get them wrong.
    (b) You can give them meaningful names.
    (c) You can add "behaviour" (methods) to them. Enums can even implement interfaces.

    2. 'tuningState' - at least as far as I can see from the requirements - should be a boolean; and if it was me I think I'd call it 'tuned', because then I can use constructs like:
    if (instrument.isTuned())
    which are far more obvious when you're reading.

    Naming is VERY important, so you need to give it plenty of thought.

    HIH

    Winston
     
    Jake Rennels
    Greenhorn
    Posts: 9
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks for the help Winston. The only reason I had those set to int was for the sake of putting together a shell to illustrate a skeleton of what I'm guessing is an OOP design. This would allow someone to correct me or reassure me accordingly before I got too far into the actual coding of the methods. I'm still not sure if I have achieved an OOP design or not. Thanks for all of the suggestions as well, those seem like pretty sound advice and the links are helpful. In regard to enum, we haven't learned that this semester, so I'm going to stay away from it for now due to time constraints. As far as the arrays and tunings, the assignment technically allows for me to just define an array with ten instances of a single instance and an array for various tunings isn't even necessary. Given that I am down to about 24 hours, I'm seriously contemplating the KISS principle (Keep It Simple Stupid) for now and moving on to more advanced stuff after I meet this deadline. I'll post updated code later tonight and hopefully someone can give me a definite answer as to whether or not my code is OO.
     
    Jake Rennels
    Greenhorn
    Posts: 9
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I *think* I had my eureka moment. Aside from the fact that the getInstrumentAttributes method is not written yet, does this version of my code demonstrate OOP? I'm also aware that my code on lines 28 and 29 are not supported in versions prior to Java 7. What happens if a user with an earlier version of Java attempts to run this code?

     
    Winston Gutkowski
    Bartender
    Posts: 10780
    71
    Hibernate Eclipse IDE Ubuntu
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Jake Rennels wrote:I *think* I had my eureka moment. Aside from the fact that the getInstrumentAttributes method is not written yet, does this version of my code demonstrate OOP?


    I hate to say, but not really.

    I'm also aware that my code on lines 28 and 29 are not supported in versions prior to Java 7. What happens if a user with an earlier version of Java attempts to run this code?


    It won't work.

    Back to "OO" for a moment. Classes in Java should generally do ONE thing.
    If that "thing" is being a stringed instrument, then that's what it should do.

    The problem is that you've mixed in a whole pile of code that runs dialogues with your user.
    Would you expect to be communicating with your Stradcaster?
    Does a violin have a keyboard that you can enter data with?
    If you need to talk to your user, create an Input class for doing that, and then pass the results of those dialogues to your StringInstrument class so that it can concentrate on the business of "being a stringed instrument".

    And that's a good lesson right there: Just because you were told to write one class doesn't mean that you can't write a few others to help it work.
    In fact, it's what good OO programmers do.

    Also: Have you written down WHAT you need to do, in detail and in English, as the links I gave you suggest?

    Coding is the LAST step in writing a program, and when you get more practised it will also be the least important one, because you'll already know what your code should look like before you start.

    Winston
     
    Jake Rennels
    Greenhorn
    Posts: 9
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Winston,
    Thanks again for your help. I have in fact gone that route and tried to "map" out what links to what with boxes on a piece of paper as well. If I understand your feedback correctly, I should have a class containing main, a class for user inputs and variable storage, a class with a constructor that modifies the instrument object's states, a class for the output window output and a class for the text file output.
    The class containing main would call for the inputs, call for the class containing the object, pass the inputs to the object, call for the two output classes, then call for the method to enter additional inputs from the input class?
    Does that sound about right?

    Jake
     
    Winston Gutkowski
    Bartender
    Posts: 10780
    71
    Hibernate Eclipse IDE Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Jake Rennels wrote:Does that sound about right?


    Well, it certainly sounds better, because now you're rationalizing the process. And you're also thinking about it, rather than just writing code - and that's never a bad thing . IPO (Input-Process-Output) is an old concept in programming, and it still has merit, even in these days of OO.

    The only other thing I can suggest is: Take things one at a time. Write your Input class and make sure you can read the data you need and put it into variables correctly...every time. Then work on getting that data into your StringInstrument class and make sure you can change states as you want. Then work on the output.

    Trying to code everything at once is a recipe for disaster, which is just another reason why you should try to break problems up into discrete classes and tasks.

    HIH

    Winston

    PS: If you're interested, I've written a whole page about UserInput, because it can be quite fiddly. It's quite long, and I'm afraid it's only Part 1 (Part 2 should be ready later this week), but it might give you some things to think about.
     
    Jake Rennels
    Greenhorn
    Posts: 9
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Winston,
    I think I have it. How does this look? Any closer to OOP?



    Jake
     
    Winston Gutkowski
    Bartender
    Posts: 10780
    71
    Hibernate Eclipse IDE Ubuntu
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Jake Rennels wrote:I think I have it. How does this look? Any closer to OOP?


    I think it would be truer to say that it's closer to being a good modular program, because you're not really using many of the techniques that make OO what it is (inheritance, data hiding, encapsulation, polymorphism...). However, there's absolutely nothing wrong with that; and it's a world apart from what you had before.

    Do you see yourself how much better it is? You have small, tightly-focused, well-named methods, in classes designed for a specific task, rather than a great mish-mash of code crammed into main(). You actually have more code than you did before, but it's properly thought out; and anyone who goes through it can quickly get a good idea of what you're trying to do.

    And that's an important thing to remember: A good program should be understandable to other people. In the real world, if it isn't, it will be re-written, and your effort will end up in The Round File.

    Just a few things I see that will help you towards your goal of "OO nirvana":
  • Fields should always, always, always be private - at least until you're a lot further down the road. It's part of the business of "data hiding" I mentioned above. If you need to access them from outside your class, write "getter" methods (look it up) to do it. But DON'T just write getters willy-nilly, and don't make them public unless they need to be. And the same is doubly true for "setters".
  • Fields should only very rarely be static - and most of yours shouldn't be. And static fields should almost always be final as well.
  • (following on from above) You only appear to set up one instance of each class, and then rely on static variables to do your job.
    DON'T.
    If you have a StringIntrument class, then each instance of it should be a single stringed instrument. You can also use the same technique for your GatherInput class (although you might want to call it something like InstrumentInput):
    Make each instance of it the input for ONE instrument.
    Why? Because then you can pass it directly to a
    public StringIntrument(InstrumentInput input) { ...
    constructor, which is actually a variant of a very useful technique known as the Builder pattern. Do you see how that might be useful?
  • You don't need to set up a new Scanner for each input method. Make one for your whole GatherInput class; and in fact, IT could be static, since you'll want every new instance to be able to use it. Otherwise, create one in your constructor.
  • Don't use constructors to initialize static fields (follows on from the points above).
  • Don't use Strings as substitutes for other types (have a look at the StringsAreBad page for details). Your getPickup() method is a classic case in point: You get two booleans - which is, in fact, exactly what you want - and then translate them to a String. That String should be for display (ie, in your Output class), not how you store the data.

  • There is more stuff, but I think that's a fair bit to take in for now. Good luck.

    Winston
     
    Jake Rennels
    Greenhorn
    Posts: 9
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Winston,
    Thanks again for all your help. I ended up submitting that version about 1:30 this morning to meet a midnight deadline. With any luck the prof will accept that over the 8pm code I uploaded here. I'm facepalming over some of the feedback you provided me. Before OO, I always used private for variables, but with procedural it was very easy to do that. I kept getting IDE errors about using non-statics for the stuff I was trying to do, leading me to change how I did things. I understand what you mean about modular design, that sounds very familiar from a high school programming class I took back before Nirvana (the band) was popular. The class is finished one way or another, but I feel that one week to discover what OO and make that jump from procedural followed by one week to complete an OOP was certainly insufficient for me. I would like to take a step back and start learning OOP from the beginning. Digging around the site I saw a $200 course you guys offer, but that's not in my budget between now and the end of the year. I'm going to do some googling and see if I can find some other baby step online programs with a built-in editor, much like one site I started working on for javascript. (I'm trying not to name drop since I haven't familiarized myself with all of the forum rules yet.)

    At any rate, I wanted to say thank you. I'm grateful for the help you've provided. I'm also grateful that someone didn't just give me a solution; learning has taken place, which is the most important aspect to me, and the 0 I was previously being awarded would have given me a D for the course. Depending on the grade, I could have as much as a B, as it is worth 25% of my grade for the class.

    Jake
     
    Winston Gutkowski
    Bartender
    Posts: 10780
    71
    Hibernate Eclipse IDE Ubuntu
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Jake Rennels wrote:Winston, Thanks again for all your help.


    You're most welcome.

    The class is finished one way or another, but I feel that one week to discover what OO and make that jump from procedural followed by one week to complete an OOP was certainly insufficient for me.


    It's insufficient for ANYONE.

    Depending on the grade, I could have as much as a B, as it is worth 25% of my grade for the class.


    Best of luck.

    Winston
     
    There are no more "hours", it's centi-days. They say it's better, but this tiny ad says it's stupid:
    Smokeless wood heat with a rocket mass heater
    https://woodheat.net
    reply
      Bookmark Topic Watch Topic
    • New Topic