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 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 Tutorials/Questions & Answers:
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
Advertisements
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
ModuleNotFoundError: No module named 'ofx-currency-converter'
ModuleNotFoundError: No module named 'ofx-currency-converter'  Hi...: No module named 'ofx-currency-converter' How to remove the ModuleNotFoundError: No module named 'ofx-currency-converter' error? Thanks   Hi
ModuleNotFoundError: No module named 'py-currency-converter'
ModuleNotFoundError: No module named 'py-currency-converter'  Hi...: No module named 'py-currency-converter' How to remove the ModuleNotFoundError: No module named 'py-currency-converter' error? Thanks   Hi
ModuleNotFoundError: No module named 'python-rt-currency-converter'
ModuleNotFoundError: No module named 'python-rt-currency-converter'  ...: No module named 'python-rt-currency-converter' How to remove the ModuleNotFoundError: No module named 'python-rt-currency-converter' error
ModuleNotFoundError: No module named 'python-rt-currency-converter'
ModuleNotFoundError: No module named 'python-rt-currency-converter'  ...: No module named 'python-rt-currency-converter' How to remove the ModuleNotFoundError: No module named 'python-rt-currency-converter' error
ModuleNotFoundError: No module named 'temrinal-currency-converter'
ModuleNotFoundError: No module named 'temrinal-currency-converter'  ...: No module named 'temrinal-currency-converter' How to remove the ModuleNotFoundError: No module named 'temrinal-currency-converter' error? Thanks
ModuleNotFoundError: No module named 'temrinal-currency-converter'
ModuleNotFoundError: No module named 'temrinal-currency-converter'  ...: No module named 'temrinal-currency-converter' How to remove the ModuleNotFoundError: No module named 'temrinal-currency-converter' error? Thanks
ModuleNotFoundError: No module named 'temrinal-currency-converter'
ModuleNotFoundError: No module named 'temrinal-currency-converter'  ...: No module named 'temrinal-currency-converter' How to remove the ModuleNotFoundError: No module named 'temrinal-currency-converter' error? Thanks
ModuleNotFoundError: No module named 'terminal-currency-converter'
ModuleNotFoundError: No module named 'terminal-currency-converter'  ...: No module named 'terminal-currency-converter' How to remove the ModuleNotFoundError: No module named 'terminal-currency-converter' error? Thanks
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 - 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 array
Java array   How can one prove that the array is not null but empty
Java array
Java array  Java program to find first two maximum numbers in an array,using single loop without sorting array
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>
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
jagged array in java
jagged array in java   jagged array in java with example
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
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
Java Array
In this section, you will learn about array in Java
What is Array in Java?
What is Array in Java?  Hi, What is Array in Java? How to create an array in Java and use it? Thanks   Hi, Array is very important in Java as it is used heavily in programming. Array is Java is a container object
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
char array java
char array java  char array programmes in java All capital letters should be replaced with the next letter
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
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
What is array in java with example?
What is array in java with example?  Hi, I am beginner in Java and want to learn Java Array concepts. Which is the best tutorials for learn Java Array with example codes? What is array in java with example? Thanks
Array - Java Beginners
Array  how to declare array of hindi characters in java
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
How to declare array in Java?
How to declare array in Java?  Hi, How to declare array in Java? Thanks   Hi, Following is a code of declaration of String array... more example at Java Array declaration. Thanks
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
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 in Java
_TO_REPLACE_1 Different types of array used in Java are One-dimensional, Two... of an Array Arrays in Java for different data types can be declared as follows... in different way, like: int i[]; Construction of an array in Java:ADS_TO_REPLACE_5
array in javascript - Java Beginners
://www.roseindia.net/java/javascript-array/index.shtml Hope...array in javascript  how to initialize array in javascript and can we increase the size of array later on? is Array class in javascript ? also
array manipulation - Java Beginners
array manipulation  We'll say that a value is "everywhere" in an array if for every pair of adjacent elements in the array, at least one of the pair is that value. Return true if the given value is everywhere in the array
Java Array Types
Java Array Types  Hi, Can Some one guide me how many types of Java Array uses in developing an application. I need the online tutorial to learn syntax or code of the various types of Java arrays. Thanks
java program based on array
java program based on array  write a program to create an array of 10 integers in main.accept values from the user in that array .now again ask the use another nomber and pass the array and the no. entered to function called
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
array
array  array memory allocation is dynamic or static in java   Java Arrays have dynamic memory allocation
Array in java
Array in java In following example we will discuss about Array in Java. Array... in memory at fixed size. We can use multiple type array. It can be used in Java, C..., Boolean, String object. We can store only primitive data in array. We have
Array
Array  can we create an array of size 1 lakh in java programming
array variable in a java program
array variable in a java program  How do i write a program that will prompt the user for a list of 5 prices, that cosist of the sum of all the prices, the average of the prices, and all prices that are higher than the calculated
in_array
in_array  in_array in php
is _array()
is _array()  is_array() in php   Hi Friend, This function is of Boolean type.It checks whether a variable is an array or not. Here is an example: <?php $yes = array('Hello', 'World'); echo is_array($yes) ? 'Array
is _array()
is _array()  is _array()   Hi Friend, This function is of Boolean type.It checks whether a variable is an array or not. Here is an example: <?php $yes = array('Hello', 'World'); echo is_array($yes) ? 'Array
How to fill double array in java
How to fill double array in java  how to fill double array in java
Simplest way to print an array in Java
Simplest way to print an array in Java  Simplest way to print an array in Java

Ads