CONVERSION

Currency conversion

Page 1 of 1

4 Replies - 858 Views - Last Post: 04 February 2009 - 07:25 AM Rate Topic: -----

#1 oteggis  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 54
  • Joined: 04-February 09

CONVERSION

Post icon  Posted 04 February 2009 - 06:59 AM

I am trying to write a program to convert US Dollars to Hong Kong Dollars. The exchange rate is 1 US Dollar for 7.7807 Hong Kong Dollars. I am asked to use US Dollar 100 as a predefined number amd to test it by writing in the main method a System.out.println("100 dollar is in Hong Kong dollar: " + conDollarToHkDollar());.

Now I want the program to calculate the exchange rate for different amount of US Dollars. When I used US Dollar 800, the answer is always the value of US dollar 100.

Please i need some help!!!

Attached Image

Is This A Good Question/Topic? 0
  • +

Replies To: CONVERSION

#2 ayman_mastermind  Icon User is offline

  • human.setType("geek");
  • member icon

Reputation: 126
  • View blog
  • Posts: 1,860
  • Joined: 12-December 08

Re: CONVERSION

Posted 04 February 2009 - 07:13 AM

can you please post you code? :code:
your method should contain a parameter that holds the variable that was input by the user, and it would be much better if you declare your variables outside...

This post has been edited by ayman_mastermind: 04 February 2009 - 07:16 AM

Was This Post Helpful? 0
  • +
  • -

#3 oteggis  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 54
  • Joined: 04-February 09

Re: CONVERSION

Posted 04 February 2009 - 07:15 AM

View Postayman_mastermind, on 4 Feb, 2009 - 06:13 AM, said:

can you please post you code? :code: thanks...

[public class DollarConverter {

public static double conDollarToHkDollar(){

double amount = 100;
double rate= 7.7807;
return amount * rate;

}

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

// Obtain input
System.out.print("Write the dollar amount: ");
double dollar = input.nextDouble();
System.out.println("100 dollar is in Hong kong dollar: " + conDollarToHkDollar());

}

}]
Was This Post Helpful? 0
  • +
  • -

#4 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 726
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: CONVERSION

Posted 04 February 2009 - 07:21 AM

this is simple math stuff, am sure if you think about it a lil, you'll reach the solution
Was This Post Helpful? 0
  • +
  • -

#5 ayman_mastermind  Icon User is offline

  • human.setType("geek");
  • member icon

Reputation: 126
  • View blog
  • Posts: 1,860
  • Joined: 12-December 08

Re: CONVERSION

Posted 04 February 2009 - 07:25 AM

import java.util.Scanner; //dont forget to add the import statement for the scanner class or else your input wont work...
public class DollarConverter{

public static double conDollarToHkDollar(double dollar){ //the method now contains the parameter dollar


double rate= 7.7807;
return dollar * rate;//multiply the dollar by the rate 

}

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

// Obtain input
System.out.print("Write the dollar amount: ");
double dollar = input.nextDouble();
System.out.println("100 dollar is in Hong kong dollar: " + conDollarToHkDollar(dollar));//the method will compute according to the dollar ammount which us the parameter

}

}


here is your code corrected and i added comments next to the corrected code... hope this helps, good luck ;)

This post has been edited by ayman_mastermind: 04 February 2009 - 07:32 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1