• 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
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Difficult combining two codes into one

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My requirement and overall goal is to make the two codes  into one and I kept getting errors whenever they're meshed together. Below, I have listed out the code and the error that I'm getting. Are my brackets in the wrong place or is it not possible to combine two codes? The help is greatly appreciated.



//ERROR(s)

C:\Users\Robb>javac Guitar1.java
Guitar1.java:130: error: reached end of file while parsing
}
^
1 error
 
Sheriff
Posts: 7123
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are definitely missing braces (curly brackets) about at line 39.  Also, since Guitar1 is public, that has to be the name of the file.  
 
Saloon Keeper
Posts: 9727
80
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are you trying to achieve, a single file containing multiple classes, or a single file containing nested classes, or a single file containing one class?
 
Marshal
Posts: 4006
549
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code below seems like it is misplaced.  I would take this (repeated) code and put it in a play() method the Guitar class.



Also - a nitpick comment - what you referred to note should be chords.
 
Robert Daniels
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was able to fix the issue; however, there were more found after trying to compile the code. I would like to have a single file containing multiple classes. Additionally, I changed all my notes to chords and I was sightly confused on where you wanted me to replace the (repeated) code should be placed. Provided below are the new errors that I'm getting.
Capture.PNG
[Thumbnail for Capture.PNG]
Errors
 
Marshal
Posts: 76854
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please don't post screenshots.
Why are you trying to put those two classes together as one in the first place? You have managed to do it in such a way that the whole of one class is inside the {} of the other class.
 
Robert Daniels
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Apologies, I was unable to copy + paste the error code into the reply due to the abbreviate of "are" to "r" so I uploaded the screen shot.

I'm fairly new to java and made the assumption of having one file with multiple classes would be the simplest; however, it doesn't seem like it is. In your opinion, what would be the easiest route?
 
Campbell Ritchie
Marshal
Posts: 76854
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Apology accepted; I hadn't noticed the “r”.
See the old Sun style guide. Write one class per source file if at all possible. You will have to repeat the package and import declarations however.
 
Morning came much too soon and it brought along a friend named Margarita Hangover, and a tiny ad.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic