Java School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a Java Expert!

Join 306,819 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,727 people online right now. Registration is fast and FREE... Join Now!




Converting U.S. dollars to Euro values

 

Converting U.S. dollars to Euro values, write an application that converts U.S. dollar values to euro values.

gmillerlight

31 May, 2009 - 09:52 AM
Post #1

New D.I.C Head
*

Joined: 30 Apr, 2009
Posts: 26

I have an error in my conversionApplication on the line that states myConverter.convertToEuros(dollarAmt). The red dotted line in under convertToEurros. It tlls me it can not find symbol. What did I forget?


package conversionapplication;

/**
*
* @author yomomma
*/
public class EuroConverter
{
// Instance variables (characteristics)
private double conversionRate;

public EuroConverter (double initialRate)
{
}

/**
* @param conversionRate the conversionRate to set
*/
public void setConversionRate(double conversionRate)
{
this.conversionRate = conversionRate;
}

public double convertToEurors(double dollars)
{
double convertToEurrors = 0.00;
double dollarAmount = 0.00;
return 0.00;
}
/**
* converts a dollar amount to Euros
* @param dollars
* @return the conversionRate
*/
public double getConversionRate()
{
double convertedValue = 0.00;

return conversionRate;
}

}
package conversionapplication;
import java.util.Scanner;
/**Currency Converter Application
*
*
* @author yomomma
*/
public class ConversionApplication {

/**
* @param args the command line arguments
*/
public static void main(String[] args)
{


// variable declarations
double convRate;
double dollarAmt = -1;
double euroAmt;

EuroConverter myConverter;
Scanner input = new Scanner(System.in);


// Get user input for conversion rate and construct EroConverter
System.out.print( "Please enter conversion rate (x.xx): ");
convRate = input.nextDouble();
while (convRate <= 0)
{
System.out.print( "Rate cannot be less than zero. Try again: ");
convRate = input.nextDouble();
}

myConverter = new EuroConverter(convRate);

while (dollarAmt != 0)
{
System.out.print( "\nPlease enter the dollar amount to convert or 0 to quit: ");
dollarAmt = input.nextDouble();

if (dollarAmt != 0)
{
// error trap
while (dollarAmt < 0)
{
System.out.print( "Dollar amount cannot be negative: ");
dollarAmt = input.nextDouble();
}

//
myConverter.convertToEuros(dollarAmt);

// displays the converted value in Euros
System.out.printf( "The equivalent value is %.2f Euros.");
}

}

System.out.println("Thank you for using our Euro converter.");
}

}


User is offlineProfile CardPM
+Quote Post


g00se

RE: Converting U.S. Dollars To Euro Values

31 May, 2009 - 10:04 AM
Post #2

D.I.C Lover
Group Icon

Joined: 19 Sep, 2008
Posts: 1,234



Thanked: 144 times
My Contributions
QUOTE
public double convertToEurors(double dollars)


You have a typo - it should be convertToEuros
User is offlineProfile CardPM
+Quote Post

cmaster

RE: Converting U.S. Dollars To Euro Values

31 May, 2009 - 10:27 AM
Post #3

D.I.C Head
**

Joined: 18 Nov, 2008
Posts: 53



Thanked: 2 times
My Contributions
QUOTE(g00se @ 31 May, 2009 - 10:04 AM) *

QUOTE
public double convertToEurors(double dollars)


You have a typo - it should be convertToEuros


Sorry for offtopic, but it looks like Freudian misprint: Eurors - Errors. Must have debugged the program for a long time :-)

This post has been edited by cmaster: 31 May, 2009 - 10:27 AM
User is offlineProfile CardPM
+Quote Post

333OnlyHalfEvil

RE: Converting U.S. Dollars To Euro Values

31 May, 2009 - 07:22 PM
Post #4

D.I.C Addict
****

Joined: 19 Mar, 2009
Posts: 540



Thanked: 18 times
My Contributions
Post your code inbetween the code tags next time. Like this: [*code] code here [*/code]. The actual tags don't have the asterisks in them (*).
User is offlineProfile CardPM
+Quote Post

Fuzzyness

RE: Converting U.S. Dollars To Euro Values

31 May, 2009 - 08:44 PM
Post #5

Comp Sci Student
Group Icon

Joined: 6 Mar, 2009
Posts: 1,183



Thanked: 181 times
Dream Kudos: 150
My Contributions
Its polite to say please, and thread is already over question answered what are chances he came back? and next time please tell him to post codes by posting it like this :*code: without the asterisk.

Hooray for online arguing! biggrin.gif
User is offlineProfile CardPM
+Quote Post

gmillerlight

RE: Converting U.S. Dollars To Euro Values

1 Jun, 2009 - 03:59 AM
Post #6

New D.I.C Head
*

Joined: 30 Apr, 2009
Posts: 26

I can not get a value other than 0.00 what is wrong with this

[/codepackage conversionapplication;

/**
*
* @author yomomma
*/
public class EuroConverter
{
// Instance variables (characteristics)
private double conversionRate;

public EuroConverter (double initialRate)
{
}

/**
* @param conversionRate the conversionRate to set
*/
public void setConversionRate(double conversionRate)
{
this.conversionRate = conversionRate;
}

public double convertToEuros(double dollars)
{
double convertToEuros = 0.00;
double dollarAmount = 0.00;
return convertToEuros ;
}
/**
* converts a dollar amount to Euros
* @param dollars
* @return the conversionRate
*/
public double getConversionRate()
{
double convertedValue = 0.00;
return conversionRate;
}

}
package conversionapplication;
import java.util.Scanner;
/**Currency Converter Application
*
*
* @author yomomma
*/
public class ConversionApplication {

/**
* @param args the command line arguments
*/
public static void main(String[] args)
{


// variable declarations
double convRate;
double dollarAmt = -1;
double euroAmt;

EuroConverter myConverter;
Scanner input = new Scanner(System.in);


// Get user input for conversion rate and construct EroConverter
System.out.print( "Please enter conversion rate (x.xx): ");
convRate = input.nextDouble();

while (convRate <= 0)
{
System.out.print( "Rate cannot be less than zero. Try again: ");
convRate = input.nextDouble();
}

myConverter = new EuroConverter(convRate);

while (dollarAmt != 0)
{
System.out.print( "\nPlease enter the dollar amount to convert or 0 to quit: ");
dollarAmt = input.nextDouble();

if (dollarAmt != 0)
{
// error trap
while (dollarAmt < 0)
{
System.out.print( "Dollar amount cannot be negative: ");
dollarAmt = input.nextDouble();
}

//
myConverter.convertToEuros(dollarAmt);

// displays the converted value in Euros
System.out.printf( "The equivalent value is %.2f Euros.", myConverter.convertToEuros(dollarAmt));
}

}

System.out.println("Thank you for using our Euro converter.");
}

}


User is offlineProfile CardPM
+Quote Post

g00se

RE: Converting U.S. Dollars To Euro Values

1 Jun, 2009 - 04:14 AM
Post #7

D.I.C Lover
Group Icon

Joined: 19 Sep, 2008
Posts: 1,234



Thanked: 144 times
My Contributions
QUOTE
public EuroConverter (double initialRate)
{
}


Should be

java

public EuroConverter (double initialRate)
{
conversionRate = initialRate;
}



You also need to return conversionRate in your getter and do something in the convertToEuros method (or it will return 0)

This post has been edited by g00se: 1 Jun, 2009 - 04:15 AM
User is offlineProfile CardPM
+Quote Post

NeoTifa

RE: Converting U.S. Dollars To Euro Values

1 Jun, 2009 - 05:23 AM
Post #8

Yay caek! ZOMG!!!
Group Icon

Joined: 24 Sep, 2008
Posts: 6,525



Thanked: 83 times
Dream Kudos: 150
My Contributions
code.gif .... It's a smiley >_>
User is offlineProfile CardPM
+Quote Post

gmillerlight

RE: Converting U.S. Dollars To Euro Values

1 Jun, 2009 - 05:37 AM
Post #9

New D.I.C Head
*

Joined: 30 Apr, 2009
Posts: 26

CODE
I can not get a value other than 0.00 what is wrong with this


package conversionapplication;

/**
*
* @author yomomma
*/
public class EuroConverter
{
    // Instance variables (characteristics)
    private double conversionRate;

    public EuroConverter (double initialRate)
    {
        conversionRate = initialRate;
        
        }

    /**
     * @param conversionRate the conversionRate to set
     */
    public void setConversionRate(double conversionRate)
    {
        this.conversionRate = conversionRate;
    }

    public double convertToEuros(double dollars)
    {
        double convertToEuros = 0.00;
        double dollarAmount = .29;
        return convertToEuros;
    }
    /**
     * converts a dollar amount to Euros
     * @param dollars
     * @return the conversionRate
     */
    public double getConversionRate()
    {
        double convertedValue = 0.00;
        return conversionRate;
    }

}




CODE
public class ConversionApplication {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {


        // variable declarations
        double convRate;
        double dollarAmt = -1;
        double euroAmt;

        EuroConverter myConverter;
        Scanner input = new Scanner(System.in);


        // Get user input for conversion rate and construct EroConverter
        System.out.print( "Please enter conversion rate (x.xx): ");
        convRate = input.nextDouble();

        while (convRate <= 0)
        {
            System.out.print( "Rate cannot be less than zero. Try again: ");
            convRate = input.nextDouble();
        }

        myConverter = new EuroConverter(convRate);

        while (dollarAmt != 0)
        {
            System.out.print( "\nPlease enter the dollar amount to convert or 0 to quit: ");
            dollarAmt = input.nextDouble();

            if (dollarAmt != 0)
            {
                // error trap
                while (dollarAmt < 0)
                {
                    System.out.print( "Dollar amount cannot be negative: ");
                    dollarAmt = input.nextDouble();
                }

                //
                myConverter.convertToEuros(dollarAmt);

                // displays the converted value in Euros
                System.out.printf( "The equivalent value is %.2f Euros.", myConverter.convertToEuros(dollarAmt));
            }

        }

        System.out.println("Thank you for using our Euro converter.");
    }
  
}
/*run:
Please enter conversion rate (x.xx): 1.42

Please enter the dollar amount to convert or 0 to quit: 5
The equivalent value is 0.00 Euros.
Please enter the dollar amount to convert or 0 to quit: 0
Thank you for using our Euro converter.
BUILD SUCCESSFUL (total time: 14 seconds)*/





]
QUOTE(NeoTifa @ 1 Jun, 2009 - 05:23 AM) *

code.gif .... It's a smiley >_>


This post has been edited by gmillerlight: 1 Jun, 2009 - 06:13 AM
User is offlineProfile CardPM
+Quote Post

NeoTifa

RE: Converting U.S. Dollars To Euro Values

1 Jun, 2009 - 06:25 AM
Post #10

Yay caek! ZOMG!!!
Group Icon

Joined: 24 Sep, 2008
Posts: 6,525



Thanked: 83 times
Dream Kudos: 150
My Contributions
You have your myConverter set to 0.00, which will make the answer zero. That's what I'm seeing.

Why is your dollar amount .29? Your dollars is still 0. You never pulled your parameter out and mutated it.

This post has been edited by NeoTifa: 1 Jun, 2009 - 06:28 AM
User is offlineProfile CardPM
+Quote Post

computerfox

RE: Converting U.S. Dollars To Euro Values

1 Jun, 2009 - 06:27 AM
Post #11

straight vegetarian kid
*****

Joined: 29 Jan, 2009
Posts: 3,772



Thanked: 48 times
Dream Kudos: 1700
My Contributions
you're always returning 0.00 in the conversion process.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/20/09 10:22PM

Live Java Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month