![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
|
first java assignment
This is my first programming assignment. I am new to java but have some backgroun in qbasic and C++. I would like your comments and suggestions for making this code better.
java Syntax (Toggle Plain Text)
__________________
i dont know much about programming but i try to help |
|
|
|
|
|
#2 |
|
Sexy Programmer
|
Not bad for a first programming assignment!
I only see one little thing. After a user enters invalid data, you have the System.exit(0); and then the break statement. Take out the break statement because it is unreachable. It's located in the default case.
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Dec 2006
Posts: 53
Rep Power: 0
![]() |
Yeah, it looks great! As reggaeton_king said, the break statement after the System.exit(0); is unneeded. I suggest using a continue statement instead of killing the program, it makes it "user friendly".
Last edited by BinarySurfer; Jan 15th, 2007 at 12:43 AM. Reason: oops... |
|
|
|
|
|
#4 |
|
Expert Programmer
|
The data type for equipment prices should be double. Also, when you print the list of prices, you should use the stored prices rather than hard-coding them:
Java Syntax (Toggle Plain Text)
Java Syntax (Toggle Plain Text)
Just a nitpick, but to print a newline, all you need to do is exclude the parameter: Java Syntax (Toggle Plain Text)
When you perform a mathematical operation with a floating-point data type (say, a double) and a non-floating-point data type (say, an int) the result will be a floating-point number, so the 1.5F in the following line of code could just as easily be 1.5: Java Syntax (Toggle Plain Text)
Java Syntax (Toggle Plain Text)
All in all, not bad for a first program. Last edited by titaniumdecoy; Jan 15th, 2007 at 2:01 AM. |
|
|
|
|
|
#5 | ||||
|
Hobbyist Programmer
|
I have totalBill declared as float b/c i thought the bill would never get big enough to require a double varriable. so when I did my LAWN_MOWER * 1.5 I would get an error saying "found double, required float". I remembered that java by defualt is double so I added the F to 1.5 make it a float operation. That fixed my problem.
Quote:
Quote:
Quote:
Quote:
thanks for the help. I will be here alot over the next months
__________________
i dont know much about programming but i try to help |
||||
|
|
|
|
|
#6 | |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Quote:
titaniumdecoy is suggesting that instead of: Java Syntax (Toggle Plain Text)
Java Syntax (Toggle Plain Text)
Java Syntax (Toggle Plain Text)
|
|
|
|
|
|
|
#7 |
|
Programmer
Join Date: Dec 2006
Posts: 53
Rep Power: 0
![]() |
Isn't killing the program a little drastic? Replacing System.exit(0) with a continue statement makes it run smoother when a incorrect entry is made instead of having to re-run the program over a simple mistake.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Programming with Java: Tutorial | ReggaetonKing | Java | 7 | May 20th, 2008 11:58 AM |
| Special browser in Java (Project) | stalefish | Java | 3 | Feb 9th, 2008 5:22 PM |
| First Java Program | duale2005 | Java | 3 | May 22nd, 2006 6:17 PM |
| Java programmers, game developers, artists, be ware! RPG game team is recruiting! | atcomputers.us | Paid Job Offers | 7 | Sep 25th, 2005 8:25 PM |
| Begin my first lesson to learn Java | satimis | Java | 7 | Mar 3rd, 2005 3:45 AM |