【问题标题】:Describe the algorithm of currency conversion描述货币转换的算法
【发布时间】:2017-05-15 22:46:04
【问题描述】:

CurrencyConversion 为用户提供将美元转换为英镑或其他方式的选择。 (你可以假设 1 美元 = 1.64 英镑。)

// Import scanner 
import java.util.Scanner;

public class MoneyConversion {

    public static void main (String[] args) {

        // Declare variable
        final double RATE  = 1.64;

        // Declare currency 
        double dollar;
        double Pounds;

        // Call scanner from keyBoard
        Scanner fromKeyboard = new Scanner(System.in);

        // Ask user to enter the amount of pounds 
        System.out.print("Please write number of pounds");

        // Read the value into variable 
        Pounds = fromKeyboard.nextDouble();

        // Write the method for currency conversion
        dollar = Pounds * RATE;

        System.out.println("The number of dollars is "  +  dollar);

    } // End of main


} // End currency conversion

【问题讨论】:

    标签: java algorithm converter currency pseudocode


    【解决方案1】:

    为不同的货币换算制作不同的类如下:

    public static void main(String[] args) {
            Scanner fromKeyboard = new Scanner(System.in);
            System.out.print("Please write number of pounds");
            System.out.println("The number of dollar is "  +  convertToDollar(fromKeyboard.nextDouble()));
        }    
    
    public static double convertToDollar(double pound){
            double rate  = 1.64;
            double Pounds;
            return( pound * rate);
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-15
      相关资源
      最近更新 更多