Lenise Edwards

Greenhorn
+ Follow
since Nov 18, 2015
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
4
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Lenise Edwards

Just wanted to say thank you to everyone and update. I figured out how to use the split method and redid the program. It runs perfectly now
8 years ago

Campbell Ritchie wrote: .

Have you suffered an Exception in your program?

Yes the program I am inquiring about in this post is suffering from an exception. Here's the stack trace:



the full print is:



The textbook we are using in the class is Java Programming, 7th Edition, Joyce Farrell. I have read about methods, objects, and classes. In the book most of the programs are displayed in the main method, it's probably for easier display since I'm learning from you all that this isn't the best way. I have made it to Chapter 8 on arrays so far. I do like that the books tries to help guide you to the Java API and guides you through finding classes, but I still struggle at digesting and applying the information. I really want to become a great programmer though. This is difficult but I am determined to master this. I have a deep interest in programming and would like to eventually work my up to becoming a software developer/engineer. Baby steps
8 years ago

Paweł Baczyński wrote:

Lenise Edwards wrote:For my Java class we are using JGrasp IDE and it didn't pinpoint the exact line that is causing the exception. Also, what is a stack trace and how do I perform one?


When there is an uncaught exception, a stack trace is printed to the console. A stack trace shows you what method were called at which lines and wchich line caused the exception.

For example, running this code:
printsHere, a static method main() called a constructor (listed as <init>) at line 17, the constructor called foo() at line 5, foo() called baz() at line 8, baz() called bar() at line 11 and finally bar() threw an exception at line 14.



Ah, thanks I didn't know that lol. Here's the stack trace:

at java.lang.String.charAt(String.java:646)
at ConstructID.main(ConstructID.java:108)
8 years ago
Thank you all for the constructive criticisms, I will try to incorporate these tips in my future assignments. A little background info I probably should have included. My undergrad was accounting and I am now pursuing my masters in computer science. I am only one class into my major right now (currently Java Programming Level 1), so I am unfamiliar with some of the terminologies used.

Campbell Ritchie Wrote:

Also too much code for the main method. All that code should be in other methods. Use the split method of the String class to separate the input.



When you say its too much code in the main method are you suggesting to create a class and create all the methods within that class so that all I have to do is call the methods in the main method? I was following the format the textbook used. So far, the textbook has been placing majority of the code in the main method, but if this isn't efficient I can change that. Also I haven't covered anything on the split method yet but I can try and see if I can figure out how to use it from java API. I do find the API a bit difficult to learn from as I have tried to use it before to learn more about other classes.

Paweł Baczyński wrote:

Please tell us which line throws this exception.
Can you post a stack trace?



For my Java class we are using JGrasp IDE and it didn't pinpoint the exact line that is causing the exception. Also, what is a stack trace and how do I perform one?

Liutauras Vilda: Thank you for your input the unused variables were left there just in case I wanted to use them. I had planned on deleting them once I finished the program. Your other tips I will definitely keep, I didn't realize I was using poor commenting and I will use this information to help improve my programs.

Thank you all for taking the time to help
8 years ago
Hi Everyone

I am new to Code Ranch and I am having trouble with a program I am coding. The program is suppose to accept the user's full name and street address using JOptionPane class and construct an ID that consists of the user's initials and numeric portion of their street address. For example, John Bon Lewis and 3245 Maple Street should result in JBM3245 or Ray Simpleton, 306 Foley Road should yield RS306. My program runs smoothly when a three part name is entered, but when a two part name is entered I get a StringIndexOutOfBounds Exception. I think it comes from using substring to extract a word that is not there. I have changed my code around multiple times trying to "fix" it but nothing I change it to works. Could anyone help me out? My code is listed below.


8 years ago