Home Answers Viewqa Java-Beginners Java array in currency converter

 
 


tracy
Java array in currency converter
1 Answer(s)      6 months and 19 days ago
Posted in : Java Beginners

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 to

quit" + "\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","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;
}
}
View Answers

November 1, 2012 at 1:49 PM


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;
}
}









Related Pages:
Java array in currency converter
Java array in currency converter  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... converter. Maybe it is the array concept that I am not understanding but if someone can
Java Currency Converter
Java Currency Converter   Hi I was wondering if someone could help me write a program to convert Pounds into Euro's. The program should prompt the user to input the number of pounds and output the number of Euros
currency converter
currency converter  hi i have encountered a problem while creating a pdf file in jsp.... my problem is i want commas for the currency which is diplayed in the pdf file... i'm using sybase, stored procedure for the front end
Currency Converter in PHP - PHP
Currency Converter in PHP  Can anyone give me an idea on how to convert US dollar, Rupees, euro and yen to pounds
converter application
converter application  Develop a converter application using event-driven programming paradigm of Java. Procedure: 1. Design a menu bar with two menus. 2. The first menu has the following menu items, Distance, Currency
converter
converter  I want to convert my c source code to java. Please tell me any software. How I convert c code to java code
currency - Java Beginners
currency  helo guys can you share me a code about Currency... Mexican pesos sample input: ENTER TYPE OF CURRENCY:(so the user must choose a currency if dollars,swiss francs,euro dollars or mexican pesos)sample I input
Currency Symbol problem
Currency Symbol problem  Hi All, My Server side code...(); Currency currency = Currency.getInstance("MYR"); // Malaysia Code numberFormat.setCurrency(currency); int num = 12345; I want to print this in a JSP Page
currency - Java Beginners
currency  helo guys can you share me a "JAVAcode" about Currency...=9.815 Mexican pesos sample input: ENTER TYPE OF CURRENCY:(so the user must choose a currency if dollars,swiss francs,euro dollars or mexican pesos)sample I
Java String Case Converter
Java String Case Converter Here we are going to convert lowercase characters... of StringBuffer. The string is then converted into character array. Then, using for loop, we  iterate throughout the character array and check if there is space
Formatting and Parsing Locale-Specific Currency
Formatting and Parsing Locale-Specific Currency In this section, you will learn how to format and parse the locale specific currency. Through the formatting..., NumberFormat, Decimal format etc, Java has made programming easier. Here we
how to do an measure converter in netbeans - Java Beginners
how to do an measure converter in netbeans   hi im not sure... information on joptionpane visit to : http://www.roseindia.net/java/java-tips/GUI/containers/20dialogs/10joptionpane.shtml http://www.roseindia.net/java/java-tips
Array
Array  is it possible to define array like this..? int[] intArray = new int[] {4,5,6,7,8}; Explain...?   Yes, you can. Java Initialize Array
array
array  array memory allocation is dynamic or static in java   Java Arrays have dynamic memory allocation
Using Standard Converter & Custom Converter
Using Standard Converter & Custom Converter... Converter, Byte Converter, Number Converter etc. These converters convert values..., Boolean and Character. If you don't specify the converter for the component
Array
Array  can we create an array of size 1 lakh in java programming
array
array  WAP in java to store 6 element in array P and 4 element in array Q. Produce the third arra y R containing all element from p & q
currency conversion
currency conversion   hi frds.. I wan jsp code to convert currency in different formats??... if u know plz plz plz post it   Please visit the following link: http://www.roseindia.net/tutorials/I18N/currency
array
array  write a program in java which input n ,a natural number less than 12 and prints the natural number from 1 to n to the power 2 in the form of a spiral.the spiral should move in on anti clockwise direction starting from
Degree Converter
Degree Converter      ...;DegreeConverter"  for java component. After that we are going to create a method...:\corejava>java DegreeConverter 200 degrees Celcius in Fahrenheit
currency symbols in excel
currency symbols in excel  How to add a currency symbol in Excel sheet? Please guide me
javascript regex validate currency
javascript regex validate currency  How to validate currency in JavaScript?   <html> <head> <title>Currency validation... validate() { var currency = document.getElementById("currency").value
Java array
Java array   How can one prove that the array is not null but empty
converter code for audio file
converter code for audio file  how can i convert a audio file to a another file format like mp3
Java array
Java array  Java program to find first two maximum numbers in an array,using single loop without sorting array
Java Temperature Converter
Java Temperature Converter In this tutorial, you will learn how to convert temperature from Celsius to Fahrenheit and vice versa. Here is an example where we have created three functions celcius(), fahrenheit() and display table
Java Array
Java Array   a) Write an array program that perform the following: i) Declares a String array initialized with the following strings: ââ?¬Å...?¬Â?. ii) Write a loop that displays the contents of each element in the array
java array
java array  q4.array Write a program that accepts two arrays, an array of fruit names and an array of price of fruits, and a fruit name and returns the price of the fruit. (Assume that a price in the second array corresponds
java array
java array  write a java method that takes an array of float values...)){ System.out.println("There are duplicate elements."); Float array...++){ array[i]=new Float(arr[i]); } Set<Float>
Alphabet Character Case-Converter
Alphabet Character Case-Converter       In this section, you will learn to convert...:\corejava>java CharToLowercase Enter the uppercase character: R
Doubt about Xstream Converter
Doubt about Xstream Converter  Hi, I am using the Xstream freamwork to read a lot of files in a batch operation. I use a custom converter Xstream to read some properties of my Xml file, but when I changed my application
java array
java array Two cells is a matrix will be called connected if they are adjacent...], a[3,2], a[3,3] } elements with weight 6 Problem: Implement Java code which takes 2 dimensional integer array as input and prints out heaviest island
Array in Java
Array in Java  public class tn { public class State{ String s_name; int p1; int p2; } public void f(){ State[] s = new State[10]; int [] i = new int[10]; i[0] = 1
Currency Format Example
Currency Format Example       This Example shows you how to format currency according to the locale. In the code given below we are formatting Currency according to the locale. Methods
Java Array
In this section, you will learn about array in Java
array program
array program  write a java program which will take 10 elements as command line arguments and count how many times 3 occurs in array
char array java
char array java  char array programmes in java All capital letters should be replaced with the next letter
array list
array list  How to get repeate occurence values from database table in java by using arraylist
sorting array in java
sorting array in java  How to sort array in Java or JavaScript?   JavaScript Sorting array tutorial   Java Sort array of strings...[] args) { String array[]=new String[5]; Scanner input = new Scanner
Array - Java Beginners
Array  how to declare array of hindi characters in java
ARRAY TUTORIAL
- It is easy to write outsides the bounds of a String or an array in Java: True or False? If false, explain why. Q2 - In Java, you must declare an array before you... different syntaxes that can be used to declare an array in type int in Java. Q4
ARRAY TUTORIAL
- It is easy to write outsides the bounds of a String or an array in Java: True or False? If false, explain why. Q2 - In Java, you must declare an array before you... different syntaxes that can be used to declare an array in type int in Java. Q4
array sort - Java Beginners
array sort  hi all, can anybody tell me how to sort an array... array[], int len){ for (int i = 1; i < len; i++){ int j = i; int tmp = array[i]; while ((j > 0) && (array[j-1] > tmp
Array in Java - Java Beginners
Array in Java  Please help me with the following question. Thank you. Write a program that reads numbers from the keyboard into an array of type int[]. You may assume that there will be 50 or fewer entries in the array. Your
array programs
array programs  write a program in java to input 10 numbers in an array and print out the Armstrong numbers from the set.   import... Numbers: "); int array[]=new int[10]; for(int i=0;i<array.length
array programs
array programs  write a program in java to input 10 numbers in an array and print out the Armstrong numbers from the set.   import... Numbers: "); int array[]=new int[10]; for(int i=0;i<array.length
array - Java Beginners
array:5 what is the length of 2nd array:4 enter a number for 1st array: 4 enter a number for 1st array: 6 enter a number for 1st array: 2 enter a number for 1st array: 1 enter a number for 1st array: 7
java array problem
java array problem  suppose i have an array a[] at a[0] i have value 5,7 the thing is that i want to assign the value of array a[0]=5,7 to two variable let it be j,k that is j=5 and k=7 plz help regards
array - Java Beginners
array  Accept a two dimensional array from the user check if this array is symetric display a message yes,if it is symetric otherwise display it ,is not symetric

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.