资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

java中的货币代码,货币代码采用

用Java编写某类,可以将外币和本币互兑,并编写测试程序创建一些不同国家货币的对象。

//试着写了一个~~

创新互联建站是一家专注于网站设计、网站制作与策划设计,林州网站建设哪家好?创新互联建站做网站,专注于网站建设10多年,网设计领域的专业建站公司;建站业务涵盖:林州等地区。林州做网站价格咨询:028-86922220

///: Filename: ForeignCurrency.java

public class ForeignCurrency {

/**font color='blue'外币兑本币,Bca/B 要兑换的外币金额*/

public double f2RMB(Currency src,double ca){

return ca*src.getExchangeRate();

}

/**font color='blue'本币兑外币,BRMB/B 要兑换的本币金额*/

public double RMB2F(Currency dest,double RMB){

return RMB/dest.getExchangeRate();

}

/**font color='blue'外币兑外币,Bcash/B 要兑换的原外币(src)金额*/

public double f2F(Currency src,Currency dest,double cash){

return src.getExchangeRate()/dest.getExchangeRate()*cash;

}

public static void main(String[] args){

ForeignCurrency x = new ForeignCurrency();

Currency rmb = new Currency(CurType.本币,1);//定义一个RMB类,兑RMB的汇率是 1

Currency us$ = new Currency(CurType.美元,7.3);//定义一个美金类,兑RMB的汇率是 7.3

Currency au$ = new Currency(CurType.澳元,9.65);//定义一个澳元类,兑RMB的汇率是 9.65

Currency jp$ = new Currency(CurType.日元,0.0101);//定义一个日元类,兑RMB的汇率是 0.0101

double RMB = 888;

double US$ = 123;

double AU$ = 234;

double JP$ = 5678.9;

//美元兑换RMB;

double us2rmb = x.f2RMB(us$, US$);

System.out.println(us$.getCURName()+": "+US$+" - "+rmb.getCURName()+": "+us2rmb+" 汇率:"+us$.getExchangeRate()/rmb.getExchangeRate());

//澳元兑换RMB

double au2rmb = x.f2RMB(au$, AU$);

System.out.println(au$.getCURName()+": "+AU$+" - "+rmb.getCURName()+": "+au2rmb+" 汇率:"+au$.getExchangeRate()/rmb.getExchangeRate());

//日元兑换RMB

double jp2rmb = x.f2RMB(jp$, JP$);

System.out.println(jp$.getCURName()+": "+JP$+" - "+rmb.getCURName()+": "+jp2rmb+" 汇率:"+jp$.getExchangeRate()/rmb.getExchangeRate());

//美元兑换澳元

double us2au = x.f2F(us$, au$,US$);

System.out.println(us$.getCURName()+": "+US$+" - "+au$.getCURName()+": "+us2au+" 汇率:"+us$.getExchangeRate()/au$.getExchangeRate());

//....................

//RMB兑换澳元

double rmb2au = x.RMB2F(au$,RMB);

System.out.println(rmb.getCURName()+": "+RMB+" - "+au$.getCURName()+": "+rmb2au+" 汇率:"+rmb.getExchangeRate()/au$.getExchangeRate());

//....................

}

}

//货币名称枚举

enum CurType{

本币,美元,澳元,日元,法郎//分别指:人民币,美金,澳元,日元,法郎...

}

//货币类,所有汇率都是以RMB为基准的

class Currency{

private double xr;//对RMB的汇率

private CurType type;//名称,比如US$

/**font color='red'参数 CUR 货币名称,double 对RMB的汇率*/

public Currency(CurType c,double xRMB){

xr = xRMB;

type = c;

}

/**font color='blue'获取外币对RMB的汇率*/

public double getExchangeRate() {

return xr;

}

/**font color='blue'获取货币名称*/

public String getCURName(){return type.name();}

}

java怎么输出货币符号

java输出货比符号测试方法:

import java.text.NumberFormat;

import java.util.Locale;

public class FormatTest {

public static void main(String args[]) {

// 不使用格式化输出数

double d = 10.0 / 3.0;

System.out.println("无格式化输出:" + d);

// 使用本地默认格式输出数

NumberFormat numberFormat = NumberFormat.getNumberInstance();

//numberFormat.setMaximumFractionDigits(4);

//numberFormat.setMinimumIntegerDigits(6);

String numberString = numberFormat.format(d);

System.out.println("本地默认格式输出数:" + numberString);

// 使用本地默认格式输出货币值

NumberFormat currencyFormat = NumberFormat.getCurrencyInstance();

System.out.println("本地默认格式输出货币值:" + currencyFormat.format(d));

// 使用本地默认格式输出百分数

NumberFormat percentFormat = NumberFormat.getPercentInstance();

System.out.println("本地默认格式输出百分数:" + percentFormat.format(d));

// 在不同的国家和地区数字表示的格式也有区别。如德国

// 使用德国的格式化输出数

NumberFormat numberFormatG = NumberFormat

.getNumberInstance(Locale.GERMANY);

System.out.println("德国数字输出形式:" + numberFormatG.format(d));

// 使用德国货币输出形式

NumberFormat currencyFormatG = NumberFormat

.getCurrencyInstance(Locale.GERMANY);

System.out.println("德国货币输出形式:" + currencyFormatG.format(d));

// 使用美国货币输出形式

NumberFormat currencyFormatA = NumberFormat

.getCurrencyInstance(Locale.US);

System.out.println("美国货币输出形式:" + currencyFormatA.format(d));

// 使用德国百分数输出形式

NumberFormat percentFormatG = NumberFormat

.getPercentInstance(Locale.GERMANY);

System.out.println("德国百分数输出形式:" + percentFormatG.format(d));

System.exit(0);

}

}

用java写一个汇率的程序:将人民币与美元、欧元、英镑等多种货币的汇率保存在指定文件中,设计图形用

程序:

import java.io.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; class test8{ public static void main(String[] args) { JFrame f=new JFrame(); f.setSize(200, 200); JTextArea t1 = new JTextArea(1,5); JTextArea t2 = new JTextArea(1,5); JButton b1=new JButton("test it"); Label l1,l2; l1 = new Label(); l2 = new Label(); l1.setText("Please Enter The Number"); l2.setText("The Result Of The Test"); Choice c = new Choice(); c.add("RMB"); c.add("KRW"); c.add("DOLLAR"); Choice c1 = new Choice(); c1.add("RMB"); c1.add("KRW"); c1.add("DOLLAR"); f.add(l1); f.add(t1); f.add(c); f.add(l2); f.add(t2); f.add(c1); f.add(b1); b1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {if(c.getSelectedItem()=="RMB"c1.getSelectedItem()=="DOLLAR") {String s; s=t1.getText(); int q=0; q=Integer.parseInt(s); double w; w=q*0.1452; String r = Double.toString(w); t2.setText(r); } else if(c.getSelectedItem()=="DOLLAR"c1.getSelectedItem()=="RMB") {String s; s=t1.getText(); int q=0; q=Integer.parseInt(s); double w; w=q*6.8866; String r = Double.toString(w); t2.setText(r); } else if(c.getSelectedItem()=="RMB"c1.getSelectedItem()=="KRW") {String s; s=t1.getText(); int q=0; q=Integer.parseInt(s); double w; w=q*164.9824; String r = Double.toString(w); t2.setText(r); } else if(c.getSelectedItem()=="KRW"c1.getSelectedItem()=="RMB") {String s; s=t1.getText(); int q=0; q=Integer.parseInt(s); double w; w=q*0.0061; String r = Double.toString(w); t2.setText(r); } else if(c.getSelectedItem()=="DOLLAR"c1.getSelectedItem()=="KRW") {String s; s=t1.getText(); int q=0; q=Integer.parseInt(s); double w; w=q*1136.2500; String r = Double.toString(w); t2.setText(r); } else if(c.getSelectedItem()=="KRW"c1.getSelectedItem()=="DOLLAR") {String s; s=t1.getText(); int q=0; q=Integer.parseInt(s); double w; w=q*0.0009; String r = Double.toString(w); t2.setText(r); } } } ); f.setLayout(new FlowLayout()); f.setVisible(true); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); } }

操作环境:java 版型号:8.64

拓展资料:

1、Java是一门面向对象编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承、指针等概念,因此Java语言具有功能强大和简单易用两个特征。Java语言作为静态面向对象编程语言的代表,极好地实现了面向对象理论,允许程序员以优雅的思维方式进行复杂的编程。 Java具有简单性、面向对象、分布式、健壮性、安全性、平台独立与可移植性、多线程、动态性等特点。Java可以编写桌面应用程序、Web应用程序、分布式系统和嵌入式系统应用程序等

2、由于C++所具有的优势,该项目组的研究人员首先考虑采用C++来编写程序。但对于硬件资源极其匮乏的单片式系统来说,C++程序过于复杂和庞大。另外由于消费电子产品所采用的嵌入式处理器芯片的种类繁杂,如何让编写的程序跨平台运行也是个难题。为了解决困难,他们首先着眼于语言的开发,假设了一种结构简单、符合嵌入式应用需要的硬件平台体系结构并为其制定了相应的规范,其中就定义了这种硬件平台的二进制机器码指令系统(即后来成为“字节码”的指令系统),以待语言开发成功后,能有半导体芯片生产商开发和生产这种硬件平台。对于新语言的设计,Sun公司研发人员并没有开发一种全新的语言,而是根据嵌入式软件的要求,对C++进行了改造,去除了留在C++的一些不太实用及影响安全的成分,并结合嵌入式系统的实时性要求,开发了一种称为Oak的面向对象语言。

操作环境:java 版型号:8.64

操作环境:C++ 版型号:8.2.64

java编写:计算一元钱硬币有多少种表达方式。例如,可以使用1元钱完成,也可以使用两个5角完成。

import java.util.ArrayList;

/*

* 一元钱硬币有多少种表达方式

* 可供选择:1分,2分,5分,1角,2角,5角,1元

* 如:

* 1元=1元;

* 1元=5角+5角;

* ....

*/

public class Test {

private static int count;

public static void main(String args[]){

int max = 100;//一元

int[] cents = {100,50,20,10,5,2,1};//币值

String[] money = {"1元","5角","2角","1角","5分","2分","1分"};

ArrayList collect = new ArrayList();

collectMoney(cents, money,0, max, 0, collect);

System.out.println("总共有"+count+"种搭配方法!");

}

public static void collectMoney(int[] cents,String[] money,int beginIndex,int max,int result,ArrayList collect){

if(result=max){

if(result==max){

count++;

System.out.print("1元=");

for(int i=0;icollect.size();i++){

System.out.print(money[(Integer) collect.get(i)]);

if(icollect.size()-1){

System.out.print("+");

}

}

System.out.println();

}

return;

}

for(int i=beginIndex;icents.length;i++){

int cent = cents[i];

collect.add(i);

collectMoney(cents, money,i, max, result+cent, collect);

collect.remove(Integer.valueOf(i));

}

}

}

java程序。 输入为CNY USD等货币缩写。 输出为 ¥ $等 该货币的符号。currency类

因为我们用的都是中文环境(默认),所以你的程序只能输入中国的货币符号,要通过Locale类的: public static void setDefault(Locale newLocale)方法设置下语言环境

具体代码可参考如下的:

import java.util.Currency;

import java.util.Locale;

import java.util.Scanner;

/**

*

* @author top

*/

public class CurrencySymbol {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

// TODO code application logic here

System.out.println("Please input a valid ISO 4217 currency code: ");

Scanner scan = new Scanner(System.in);

String code1 = scan.nextLine();

Locale.setDefault(Locale.CHINA);//中文语言环境下

Currency currency1 = Currency.getInstance(code1);

System.out.println(currency1.getSymbol());

String code2 = scan.nextLine();

Locale.setDefault(Locale.US);//美国

Currency currency2 = Currency.getInstance(code2);

System.out.println(currency2.getSymbol());

}

}


网页标题:java中的货币代码,货币代码采用
分享地址:http://cdkjz.cn/article/hoeoes.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220