Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Java array in currency converter
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


tracy
Java array in currency converter
1 Answer(s)      a year and 10 months 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;
}
}

Advertisement
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
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
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
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
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
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
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 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
pdf to voice converter
pdf to voice converter  is it possible to implement PDF to speech converter by extracting text from pdf and then text to speech
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   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>
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
jagged array in java
jagged array in java   jagged array in java with example
Why not use Double or Float to represent currency?
Why not use Double or Float to represent currency?  Why not use Double or Float to represent currency
Java Array
In this section, you will learn about array in Java
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
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
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
 

 

 

DMCA.com