Results 1 to 9 of 9
Thread: Report Display Issue
- 03-27-2009, 06:48 AM #1
Member
- Join Date
- Feb 2009
- Posts
- 22
- Rep Power
- 0
Report Display Issue
I am trying to add a report summary to my code. I have it it working to where it displays but the issue when it does display for the country and rate no matter how many times the currency exchange is done, the country and rates are what was the last choice to convert. I need some help fixing this minor issue. The code for both files are below. Thanks ahead for whomever helps me with this issue
Java Code:import java.util.Scanner; import java.text.NumberFormat; public class Lab9 { public static void main(String[] args) { final int Max = 20; int c = 0; char choice, report; String s, r; Foreign[] exchange = new Foreign[Max]; Scanner Keyboard = new Scanner(System.in); Foreign.title(); Foreign.menu(); do { exchange[c] = new Foreign(); exchange[c].choice(); exchange[c].dollars(); exchange[c].vertical(); System.out.println("\n" + exchange[c]); c++; System.out.print("\nWould you like to enter another exchange? Y/N "); s = Keyboard.nextLine(); choice = s.charAt(0); choice = Character.toUpperCase(choice); } while (choice == 'Y' && c < Max); System.out.println("\nWould you like to see a summary report? Y/N "); r = Keyboard.nextLine(); report = r.charAt(0); report = Character.toUpperCase(report); if (report == 'Y') { System.out.println("\nCountry\t\tRate\t\tDollars\t\tAmount"); System.out.println("========\t\t=======\t\t=======\t\t========="); for (int i=0; i < c; i++) System.out.println(exchange[i]); Foreign.Counter(); } } }Java Code:import java.util.Scanner; import java.text.NumberFormat; public class Foreign { private static int choice, count; private String country; private double dollars, rate, amount; private static double[] rates = {1.2418,14.5436,88.9183,0.774078}; private static String[] countries = {"Canadian Dollars", "Mexican Pesos", "Japanese Yen", "Euros"}; NumberFormat amountForm = NumberFormat.getCurrencyInstance(); NumberFormat valueFormat = NumberFormat.getCurrencyInstance(); NumberFormat dollarFormat = NumberFormat.getCurrencyInstance(); Scanner Keyboard = new Scanner(System.in); public Foreign() { dollars = 0.0; rate = 0.0; amount = 0.0; country = "null"; } public static void title() { System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"); System.out.println(" Foreign Exchange"); System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n\n"); } public static void Counter() // counter { System.out.println("\n\tThe total number of conversions is " + count); } public static void menu() { System.out.println("======================================================"); System.out.println(" Foreign Exchange Menu"); System.out.println("======================================================\n\n"); } public void choice() { for (int i=0; i<4; i++) System.out.println(i+1 + " " + "U.S. to " + countries[i]); System.out.print("\nPlease enter your choice: "); choice = Keyboard.nextInt(); count++; } public int getChoice() { return choice; } public void dollars() { System.out.print("\nEnter the amount of U.S. Dollars you want to convert: "); dollars = Keyboard.nextDouble(); rate = rates[choice-1]; country = countries[choice-1]; amount = dollars * rates[choice-1]; } public void vertical() { System.out.println("\nCountry = " + countries[choice-1]); System.out.println("Rate = " + valueFormat.format(rates[choice-1])); System.out.println("Dollars = " + dollarFormat.format(dollars)); System.out.println("Value = " + amountForm.format(amount)); } public String toString() { String line; line = countries[choice-1] + "\t" + valueFormat.format(rates[choice-1]) + "\t\t" + dollarFormat.format(dollars) + "\t\t" + amountForm.format(amount); return line; } }Last edited by JDAWG; 03-27-2009 at 06:53 AM.
- 03-27-2009, 08:16 AM #2
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
problem found in declaring improper static variable choice
- 03-27-2009, 08:20 AM #3
Member
- Join Date
- Feb 2009
- Posts
- 22
- Rep Power
- 0
still not sure what you mean or what I am doing wrong. what should the code look like?
- 03-27-2009, 08:28 AM #4
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
i would like to know why choice is static
- 03-27-2009, 09:06 AM #5
Member
- Join Date
- Feb 2009
- Posts
- 22
- Rep Power
- 0
Because my instructor has us do labs and each lab we just adjust the previous one. in the lab before he wanted us to make choice an static int... So you are basically saying I need to change that from being static to just private int choice? Thanks
- 03-27-2009, 09:12 AM #6
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
do you know what "static" means?
- 03-27-2009, 09:25 AM #7
Member
- Join Date
- Feb 2009
- Posts
- 22
- Rep Power
- 0
yes means doesnt change. I guess I was hoping you might understand more why my instructor at the time would have make choice static and now try to see whos paying attention and change that to just a private int...
- 03-27-2009, 09:45 AM #8
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
static variable means that variable share with all objects come from the same class
- 03-27-2009, 03:10 PM #9
Member
- Join Date
- Feb 2009
- Posts
- 22
- Rep Power
- 0
Similar Threads
-
Struts2 display tag Issue
By nickraj in forum Web FrameworksReplies: 0Last Post: 02-26-2009, 06:03 PM -
Issue in calendar display
By jeeva in forum New To JavaReplies: 1Last Post: 01-14-2009, 01:19 PM -
How to display a list of items and on click display subitems?
By mandyj in forum New To JavaReplies: 8Last Post: 12-29-2008, 07:12 AM -
How to display information about the display device in SWT
By Java Tip in forum SWTReplies: 0Last Post: 06-28-2008, 09:26 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks