Hi all,
My sister is trying to teach me java. She's in school for programming and I'm not but I am just trying to learn alongside her. I am quite lost with this multidimensional array. I do not have any programming experience. Right now I am working on this currency converter. Maybe it is the array concept that I am not understanding but if someone can give me a starting point that will get me going. Thanks!
Here is what is required:
Modify Lab 8 by adding an array of objects. Within the loop, instantiate each individual object. Make sure the user cannot keep adding another Foreign conversion beyond your array size. After the user selects quit from the menu, prompt if the user want to display a summary report. If they select ââ?¬Ë?Yââ?¬â?¢ then, using your array of objects, display the following report:
Item Conversion Dollars Amount 1 Japanese Yen 100.00 32,000.00 2 Mexican Peso 400.00 56,000.00 3 Canadian Dollar 100.00 156.00
etc.
Number of Conversions = 3
(the numbers above are only used for example, and do not represent real values)
Lab8.java:
import java.util.Scanner; import java.text.DecimalFormat; public class Lab8 { public static void main(String[] args) { final int Max = 5; int c = 0; Foreign Exchange = new Foreign(); Scanner read = new Scanner(System.in); Foreign.opening(); do { c=Exchange.getchoice(); if (c >= 1 && c <= 4) { Exchange.dollars(); Exchange.amount(); Exchange.vertical(); System.out.println("\n" + Exchange + "\n"); } else if (c > 4) { System.out.println("\n" + "Please select 1 through 4, or 0 toquit" + "\n"); } } while (c != 0);
Foreign.counter(); } }
Foreign.java:import java.util.Scanner; import java.text.DecimalFormat; public class Foreign { Scanner read = new Scanner(System.in); private static int count =0; private static int choice; private static double[] rates = {0.976250,12.8765,78.1800,0.770250}; private static String[]countries = {"Candian Dollars","MexicanPesos","Japanese Yen","European Euros"}; private double dollars, amount, rate; private String country; DecimalFormat money = new DecimalFormat("$###,##0.00");
public static void opening() { System.out.println(" Foreign Exchange"); System.out.println("======================"); System.out.println(); } public static void counter() { System.out.println("\nThe total amount of conversions is " + count); } public Foreign() { choice=0; dollars=0.00; amount=0.00; } public int getchoice() { for (int i=0; i<4; i++) System.out.println(i+1 + " " + "USDollars to " + countries[i]); System.out.print("\nPlease enter your choice: "); choice = read.nextInt(); return choice; }
public void dollars() { System.out.print("\nPlease enter the amount of U.S. Dollars: "); dollars= read.nextDouble(); count++; } public void amount() { rate = rates[choice-1]; country = countries[choice-1]; amount = dollars * rate; } public void vertical() { System.out.println("\nCountry = " + country); System.out.println("Rate = " + rate); System.out.println("Dollars = " + money.format(dollars)); System.out.println("Converted value = " + money.format(amount)); } public String toString() { String horizontal; horizontal = country + " " + rate + " " + money.format(dollars) + " " + money.format(amount); return horizontal; } }
Sorry my original post did not post correctly. Here is is again
Modify your prior Lab 8 by adding an array of objects. Within the loop, instantiate each individual object. Make sure the user cannot keep adding another Foreign conversion beyond your array size. After the user selects quit from the menu, prompt if the user want to display a summary report. If they select â??Yâ?? then, using your array of objects, display the following report:
Item Conversion Dollars Amount 1 Japanese Yen 100.00 32,000.00 2 Mexican Peso 400.00 56,000.00 3 Canadian Dollar 100.00 156.00 etc.
Number of Conversions = 3
(the numbers above are only used for example, and do not represent real values)
import java.util.Scanner; import java.text.DecimalFormat; public class Lab8 { public static void main(String[] args) { final int Max = 5; int c = 0; Foreign Exchange = new Foreign(); Scanner read = new Scanner(System.in); Foreign.opening(); do { c=Exchange.getchoice(); if (c >= 1 && c <= 4) { Exchange.dollars(); Exchange.amount(); Exchange.vertical(); System.out.println("\n" + Exchange + "\n"); } else if (c > 4) { System.out.println("\n" + "Please select 1 through 4, or 0 to quit" + "\n"); } } while (c != 0); Foreign.counter(); } }import java.util.Scanner; import java.text.DecimalFormat; public class Foreign { Scanner read = new Scanner(System.in); private static int count =0; private static int choice; private static double[] rates = {0.976250,12.8765,78.1800,0.770250}; private static String[]countries = {"Candian Dollars","Mexican Pesos","Japanese Yen","European Euros"}; private double dollars, amount, rate; private String country; DecimalFormat money = new DecimalFormat("$###,##0.00"); public static void opening() { System.out.println(" Foreign Exchange"); System.out.println("======================"); System.out.println(); } public static void counter() { System.out.println("\nThe total amount of conversions is " + count); } public Foreign() { choice=0; dollars=0.00; amount=0.00; } public int getchoice() { for (int i=0; i<4; i++) System.out.println(i+1 + " " + "US Dollars to " + countries[i]); System.out.print("\nPlease enter your choice: "); choice = read.nextInt(); return choice; } public void dollars() { System.out.print("\nPlease enter the amount of U.S. Dollars: "); dollars= read.nextDouble(); count++; } public void amount() { rate = rates[choice-1]; country = countries[choice-1]; amount = dollars * rate; } public void vertical() { System.out.println("\nCountry = " + country); System.out.println("Rate = " + rate); System.out.println("Dollars = " + money.format(dollars)); System.out.println("Converted value = " + money.format(amount)); } public String toString() { String horizontal; horizontal = country + " " + rate + " " + money.format(dollars) + " " + money.format(amount); return horizontal; } }