Java array in currency converter

Ads
 

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

Ads









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
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
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>
jagged array in java
jagged array in java   jagged array in java with example
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
Java Array
In this section, you will learn about array in Java
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
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
char array java
char array java  char array programmes in java All capital letters should be replaced with the next letter
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
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
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
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 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
Array in Java
. Different types of array used in Java are One-dimensional, Two-dimensional and multi... of an Array Initialization of an Array Arrays in Java for different data... above arrays in different way, like: int i[]; Construction of an array in Java
java program based on array
java program based on array  Create Student class with attributes... StudentDemo which will have main method. Declare array of Student object with size 10. Initialize all 10 elements of this array with new objects. Write logic which
How to fill double array in java
How to fill double array in java  how to fill double array in java

Ads