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

用java编写一个程序,可实现人民币,美元,日元,欧元,台币,港币之间的任意转换~

package Test;import javax.swing.JOptionPane;public class Test2 { public static void main(String[] args) { int numOf10=0; int numOf5=0; int numOf1=0; int numOf0_5=0; int numOf0_1=0; Double money=Double.parseDouble(JOptionPane.showInputDialog("输入money")); int total=(int)(money*10); while(total>0){ if((total-100)>=0){ total-=100; numOf10++; }else if((total-50)>=0){ total-=50; numOf5++; }else if((total-10)>=0){ total-=10; numOf1++; }else if((total-5)>=0){ total-=5; numOf0_5++; }else if((total-1)>=0){ total-=1; numOf0_1++; } } if(numOf10!=0){ System.out.println("10元人民币:"+numOf10+"张"); } if(numOf5!=0){ System.out.println("5元人民币:"+numOf5+"张"); } if(numOf1!=0){ System.out.println("1元人民币:"+numOf1+"张"); } if(numOf0_5!=0){ System.out.println("5角人民币:"+numOf0_5+"张"); } if(numOf0_1!=0){ System.out.println("1角人民币:"+numOf0_1+"张"); } }}

做了个互换的.输入人民币换美元. 人民币为空,光输入美元转成人民币


/*
* 这个程序实现输入身高算出标准体重,输入体重,算出身高的功能
*/
import java.awt.*; //导入相关类包,这才样使用相应awt图形界面的类
import java.awt.event.*;//同上

public class changeDollar extends Frame { //定义一个类Change, 父类是Frame(图形界面的)
Button b = new Button("转换"); //创建一个按钮的对象b,显示为"互查"
Label l1 = new Label("人民币:");//创建一个lable.显示身高
Label l2 = new Label("美元");//创建一个lable 显示体重
double heigth, weigth; //定义变量
double x, y; //定义变量
TextField tf1 = new TextField(null, 10);//添加Text框
TextField tf2 = new TextField(null, 10);//添加Text框

public changeDollar() {//类的构造函数,完成初始化
super("转换表");//创建窗口,标题为互查表
setLayout(new FlowLayout(FlowLayout.LEFT));//设置布局
add(l1);//把lable 身高放到window里
add(tf1);//把Text 框 放到窗口上
add(l2); //把lable 体重放到window里
add(tf2);//Test放到窗口里
add(b);//把button放到窗口上
pack();//自动放到窗口里排列上边的组件
setVisible(true);//可以让用户看到窗口
addWindowListener(new WindowAdapter() {//如果按 X, 关闭窗口
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
b.addActionListener(new ButtonListener());//添加button监听函数
}

class ButtonListener implements ActionListener {//实现click button时功能操作
public void actionPerformed(ActionEvent e) {//当click调用

if (tf1.getText()!=null) {//检查tf1 test 是否为空
try {//取异常
x = Double.parseDouble(tf1.getText());//字符转为double型
weigth = x*6.82;//
tf2.setText("" + weigth);//显示
} catch (NumberFormatException ex) {
tf1.setText("");//如果输入不是数字,设为空
}
}
if (tf1.getText().equals("")==true){//tf1是否为空
y = Double.parseDouble(tf2.getText());//把tf2里的文本转为double 型 的
heigth = y /6.82; //

tf1.setText("" + heigth);}//
}

}

public static void main(String[] args) {//主函数,程序入口
new changeDollar(); //建立类Change的对象,并调用他的构造函数Change().显示窗口
}

}

程序:
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

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication8;
/**
*
* @author Administrator
*/
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);
}
});
}
}

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication8;
/**
*
* @author Administrator
*/
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问题?还是图形问题。还是表格问题?

晕,汇率每分每秒都在变化,怎么写程序?

用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); ...

用java编写个程序,确定存钱罐里的硬币总面值并以美元和美分为单位输出钱...
答:import java.util.Scanner;public class 美元{private static Scanner sc=new Scanner(System.in);public static void main(String[] args) {System.out.println("\n\t\t===提示:1美元=100美分===\n");System.out.println("请输入钱数美元为单位,自动转换成美分!");while(true)init(sc.next...

用Java编写某类,可以将外币和本币互兑,并编写测试程序创建一些不同国...
答: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 ...

用java 完成整钱兑零钱程序,要求:输入一个double值,代表总零钱数,输出...
答:public static void splitMoney(Double unSplitMoney) { if (unSplitMoney <= 0) { System.out.println("请输入正确的金额."); } int unSplitMoneyCents = (int) (unSplitMoney * 100); int[] splitArray = {100 * 100, 50 * 100, 20 * 100, 10 * 100, 5 * 100...

如何用Java获取实时汇率
答:1.SE80 创建代理类 2.LPCONFIG 创建逻辑端口 3.写程序 如果根据URL创建代理类的时候出现SPRX084的错误,请参考Notes:1046046、976964

使用JAVA编写一个简单的银行存取款程序
答:/ public class Account { private String id;private int password;private String name;private double balence;public String getId() { return id;} public void setId(String id) { this.id = id;} public int getPassword() { return password;} public void setPassword(int password) { th...

跪谢!求用JAVA编写一个自动贩卖机的程序
答:import java.util.Scanner;public class Shop { private String coffee="咖啡";private String coke="可乐";private String tea="茶";private double coffeeprice=2.00;private double cokeprice=3.00;private double teaprice=5;private double price=0.0;public Shop(){ } public void getName(...

java 美元人民币汇率转换小问题,跳出的这个框的标题“输入”是在哪里...
答://JDK API 1.6.0 showInputDialog(Component parentComponent, Object message, String title,int messageType)显示请求用户输入内容的对话框,它以 parentComponent 为父级,该对话框的标题为 title,消息类型为 messageType。实例:JOptionPane.showInputDialog(null, "gain focus!","tiltle",JOptionPane....

用Java写个小程序:创建银行账号类SavingAccount,利用静态变量存储年利率...
答:import java.util.Scanner;public class SavingAccount { public static double account = 3000;public static double rate = 0.03;public void update(double rate){ this.rate = rate;} //flag 用来计算年利息和月利息,flag等true计算月利息 public double calc(double account , double rate , ...

用java编写程序:求银行本息的!题目如下:
答:private double lilu;//年利率 //计算本息 private double resBenxi(double money,int year){ benxi=money+money*getLilu(year)*year;return benxi;} //选择利率 private double getLilu(int year){ switch(year){ case 1:lilu=2.25/100;break;case 2:lilu=2.7/100;break;case 3:lilu=3....

IT评价网,数码产品家用电器电子设备等点评来自于网友使用感受交流,不对其内容作任何保证

联系反馈
Copyright© IT评价网