Results 1 to 4 of 4
Thread: Simple question about this class
- 12-07-2011, 11:38 AM #1
Member
- Join Date
- Nov 2011
- Posts
- 13
- Rep Power
- 0
Simple question about this class
When a user clicks 1 in the do while loop. it will enter case 1 and method option1(pl) will execute. After this method has exectued how does it get back into the loop and display the menu again???
Java Code:public class PaymentListTester { public static void main(String[] args) { char choice; int total; // declare PaymentList object to test PaymentList pl; // get size of list System.out.print("\nMaximum number of payments? "); total = EasyIn.getInt(); //create PaymentList object to test pl = new PaymentList(total); do { System.out.println("\n[1] Add a payment"); System.out.println("[2] List all payments"); System.out.println("[3] Get number of payments made"); System.out.println("[4] Get total payments made"); System.out.println("[5] Quit"); System.out.println("\nEnter a choice [1,2,3,4,5]: "); //get choice choice = EasyIn.getChar(); switch(choice){ case '1': option1(pl); break; case '2': option2(pl); break; case '3': option3(pl); break; case '4': option4(pl); break; case '5': System.out.println("\n\nBYE"); break; default: System.out.print("\n1-5 only"); } } while(choice !='5'); } // Static Worker Methods // add payment private static void option1(PaymentList listIn){ if(!listIn.isFull()){ System.out.print("\nEnter Month: \t"); String month = EasyIn.getString(); System.out.print("Enter amount: \t"); double amount = EasyIn.getDouble(); listIn.add(new Payment(month, amount)); } else{ System.out.println("\n!!! SORRY, LIST IS FULL!!!"); } } // display payment private static void option2(PaymentList listIn){ System.out.print("\nMONTH \tAMOUNT\n"); // header // loop through payments in list for(int i =1; i<=listIn.getTotal();i++){ Payment p = listIn.getPayment(i); System.out.print(p.getMonth()); System.out.println("\t" + p.getAmount()); } } // Get total number of payments private static void option3(PaymentList listIn){ System.out.print("\nTotal number of payments made: "); System.out.println(listIn.getTotal()); } // get total of payments made private static void option4(PaymentList listIn){ System.out.print("\ntotal sum of payments made: "); System.out.println(listIn.calculateTotalPaid()); } }
- 12-07-2011, 12:37 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
Re: Simple question about this class
It never leaves the loop, so it doesn't need to get back into it...
Or have I misunderstood your question?
- 12-07-2011, 02:12 PM #3
Member
- Join Date
- Nov 2011
- Posts
- 49
- Rep Power
- 0
Re: Simple question about this class
I would change out the switch for a loop and then add a control variable. Or add a loop after after the switch to get back into the display menu again. Something like asking if they are done with their transaction..."y" or "n."
- 12-07-2011, 02:54 PM #4
Member
- Join Date
- Nov 2011
- Posts
- 13
- Rep Power
- 0
Similar Threads
-
A simple question
By chris.bos in forum New To JavaReplies: 11Last Post: 12-02-2011, 05:37 PM -
simple question
By agater in forum New To JavaReplies: 5Last Post: 11-07-2011, 02:22 AM -
Please help. Simple question
By owencain in forum New To JavaReplies: 14Last Post: 06-16-2011, 01:07 AM -
some simple question?
By jperson in forum New To JavaReplies: 4Last Post: 05-03-2010, 05:32 PM -
Simple Question
By barusk in forum NetworkingReplies: 13Last Post: 03-04-2009, 07:33 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks