Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Clean up

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,

This code has no issues, but is there another way this could have been made cleaner/neater or did i get the basics correct?


 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would be a good habit to start avoiding floating point data types (like float and double) to represent monetary values, because those values will always need to be exact and floating point data types just don't offer that accuracy. Use BigDecimal instead, or possibly even int or long if the situation allows for it. Also, are you worried at all about Object Orientation at this point or are you just familiarizing yourself with the basics of Java?

 
Adrian Martinez
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm taking a class on java, so i'm just learning the basics.

 
Marshal
Posts: 15896
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not much to say about the code itself - it's just basic calculations and output. You should learn how to format your code better though. And follow coding conventions. Class names are capitalized.

You should use spaces instead of hard tabs to indent your code. Tabs can get expanded differently in different editors/viewers.
 
Adrian Martinez
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have only been using notepad to edit/view the code.

But I see what you are saying along with the capitalization.
 
Junilu Lacar
Marshal
Posts: 15896
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Adrian Martinez wrote:I have only been using notepad to edit/view the code.


Consider switching to Notepad++ or some other programmer's editor for Windows. Notepad sucks.
 
Marshal
Posts: 70370
283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Move all that code out of the main method.
 
Campbell Ritchie
Marshal
Posts: 70370
283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:

Adrian Martinez wrote:I have only been using notepad to edit/view the code.


Consider switching to . . . Notepad sucks.

Couldn't agree more. A few more suggestions here and here.
 
Space pants. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic