Results 1 to 6 of 6
- 11-01-2012, 05:13 PM #1
Member
- Join Date
- Mar 2012
- Location
- Ireland
- Posts
- 18
- Rep Power
- 0
Advice on Java programming design
I am very new to java, basically i am self learning for fun and taking hints and tips from anywhere i can get them. I have written some small programs, nothing very difficult at all, i find i can solve many of the problems i encounter using (Do While - IF & IF Else), my problem is this, i don't know enough of the Java commands to vary how i structure my programming designs, there are obviously many other Java commands which can make the programming experience more interesting and efficient but not knowing which ones to use and how to construct them is a bit of a problem, i don't have a specific question but i will attach some code if your interested in viewing it and maybe giving me some feedback on how to re-write the code in a more efficient way, if that's possible. I don't want to be a Java programmer who only use's a small portion of the available commands.
Java Code:import java.util.Scanner; public class Q10 { public static void main(String[] args) { Scanner myinput = new Scanner(System.in); int accno, balance = 0, ItemsCharged = 0, TotalCreditApplied = 0, CreditLimit = 2000; System.out.println("Please enter your account number "); accno = myinput.nextInt(); System.out.println("Hi, your account number is "+accno+" your current Credit Limit is "+CreditLimit); System.out.println(); do { System.out.println("Please enter the value of your current purchases for today "); ItemsCharged = myinput.nextInt(); TotalCreditApplied = ItemsCharged+TotalCreditApplied; balance = CreditLimit - TotalCreditApplied; if(TotalCreditApplied > CreditLimit) { System.out.println("You have reached your available Credit Limit"); } else { System.out.println("Total value of items charged to your account in this sale is "+ItemsCharged); System.out.println("Total overall Credit applied to your account is "+TotalCreditApplied); System.out.println("Your account balance available to spend is "+balance); } } while(TotalCreditApplied < CreditLimit); } }Last edited by JosAH; 11-01-2012 at 06:42 PM. Reason: fixed the [code] ... ]/code] tags (and indentation)
- 11-01-2012, 05:57 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: Advice on Java programming design
My first comment (and only one at the moment) is to indent your code correctly.
Unindented (unformatted) code is very hard to read.Please do not ask for code as refusal often offends.
- 11-01-2012, 06:09 PM #3
Member
- Join Date
- Mar 2012
- Location
- Ireland
- Posts
- 18
- Rep Power
- 0
Re: Advice on Java programming design
Hi Tolls,
When you say indent code, what does this mean ?
Helen
- 11-01-2012, 06:27 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: Advice on Java programming design
Java Code:public class SomeClass { private int someId; public void someMethod() { while(someBoolean) { doSomethingElse(); } } }Please do not ask for code as refusal often offends.
- 11-01-2012, 06:33 PM #5
Member
- Join Date
- Mar 2012
- Location
- Ireland
- Posts
- 18
- Rep Power
- 0
Re: Advice on Java programming design
I have tried to paste the code so that it looks like yours, indented, but it just appears on the screen the same way as my original post, i thought it would appear correctly once i entered [code] at the begining and end of the code i entered, but obviously not, any help in solving this would be appreciated.
HelenLast edited by helen1974; 11-01-2012 at 06:36 PM.
- 11-01-2012, 06:43 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Quick Advice on bad design
By garnaout in forum New To JavaReplies: 1Last Post: 05-08-2012, 08:53 PM -
Learning java for Android. VERY interested in OO, design patterns, Xtreme programming
By StateMachine in forum IntroductionsReplies: 1Last Post: 12-26-2011, 01:50 PM -
Looking for database program design advice from experienced programmers
By Nighthawk in forum JDBCReplies: 2Last Post: 03-03-2011, 08:23 AM -
New to Swing, need some advice on programming style
By Gorgro in forum AWT / SwingReplies: 1Last Post: 10-31-2010, 07:41 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks