JAVA作业:PP2.3 编写一个应用程序,读取两个浮点数,然后打印输出它们的和、差、乘积。
import javax.swing.*;import java.util.*;public class First {/*** 作业PP2.3 编写一个应用程序,读取两个浮点数,然后打印输出它们的和、差、乘积。
*/public static void main(String[] args) {float f1=0.0f, f2=0.0f;float sum=0.0f;float difference=0.0f;float product=0.0f;String tempstr=JOptionPane.showInputDialog("Input Please");f1=Float.parseFloat(tempstr);tempstr=JOptionPane.showInputDialog("Input Please Again");f2=Float.parseFloat(tempstr);sum=f1+f2;difference=f1-f2;product=f1*f2;JOptionPane.showMessageDialog(null,"The First Number is:"+f1+"\n"+"The Second Number is:"+f2+"\n"+"The Sum is:"+sum+"\n"+"The Differenceis:"+difference+"\n"+"The productis:"+product,"Result",RMATION_MESSAGE);}}PP2.4 编写一个应用程序TempConverter1,读取用户输入的华氏温度,然后转换成摄氏温度。
import javax.swing.*;public class TempConverter1 {/*** 作业PP2.3编写一个应用程序TempConverter1,读取用户输入的华氏温度,然后转换成摄氏温度。
*/public static void main(String[] args) {final int BASE=32;final double CONERSION_FACTOR=5.0/9.0;float fahrenheiTemp;double celsiusTemp;String tempstr=JOptionPane.showInputDialog("Input Please");fahrenheiTemp=Float.parseFloat(tempstr);celsiusTemp=(fahrenheiTemp-BASE)*CONERSION_FACTOR;JOptionPane.showMessageDialog(null,"FahrenheiTempis:"+fahrenheiTemp+"\n"+"CelsiusTempis:"+celsiusTemp,"Result",RMATION_MESSAGE);}}PP2.5 编写一个应用程序,将英里转换为千米(1英里等于1.60935千米)。
以浮点数类型读取用户输入的英里数。
import javax.swing.JOptionPane;public class Third {/*** 作业PP2.5 编写一个应用程序,将英里转换为千米(1英里等于1.60935千米)。
以浮点数类型读取用户输入的英里数。
*/public static void main(String[] args) {final double rewire=1.60935;float mile=0.0f;double kilometer=0.0f;String tempstr=JOptionPane.showInputDialog("Input Please");mile=Float.parseFloat(tempstr);kilometer=mile*rewire;JOptionPane.showMessageDialog(null,"Mileis:"+mile+"\n"+"Kilometer:"+kilometer,"Result",RMATION_MESSAGE) ;}}PP2.6 编写一个应用程序,以小时、分、秒读取时间长度,然后全部换算成秒并打印输出结果(例如,1小时28分42秒等于5322秒)。
import javax.swing.*;public class forth {/*** 作业PP2.6 编写一个应用程序,以小时、分、秒读取时间长度,然后全部换算成秒并打印输出结果(例如,1小时28分42秒等于5322秒)。
*/public static void main(String[] args) {int hour,minute,second,change;final int CONERSION_FACTOR=60;String tempstr=JOptionPane.showInputDialog("Input Hour Please");hour=(int)Float.parseFloat(tempstr);tempstr=JOptionPane.showInputDialog("Input Minute Please");minute=(int)Float.parseFloat(tempstr);tempstr=JOptionPane.showInputDialog("Input Second Please");second=(int)Float.parseFloat(tempstr);change=hour*CONERSION_FACTOR*CONERSION_FACTOR+minute*CONERSIO N_FACTOR+second;JOptionPane.showMessageDialog(null,"The Hour is:"+hour+"\n"+"The Minute is:"+minute+"\n"+"The Second is:"+second+"\n"+"The Change is:"+change,"Result",RMATION_MESSAGE);}}PP2.7 编写一个应用程序,读入一个以秒为单位的时间长度,然后换算成小时、分、秒的组合表达方式并打印输出结果(例如,9999秒等于2小时46分39秒)。
import javax.swing.*;public class firth {/*** 作业PP2.7 编写一个应用程序,读入一个以秒为单位的时间长度,然后换算成小时、分、秒的组合表达方式并打印输出结果(例如,9999秒等于2小时46分39秒)。
*/public static void main(String[] args) {int hour,minute,second,time;final int CONERSION_FACTOR=60;String tempstr=JOptionPane.showInputDialog("Input Time Please");time=(int)Float.parseFloat(tempstr);hour=(int)time/CONERSION_FACTOR/CONERSION_FACTOR;minute=(int)(time-hour*CONERSION_FACTOR*CONERSION_FACTOR)/CONERSION_ FACTOR;second=(int)time-hour*CONERSION_FACTOR*CONERSION_FACTOR-minute*CONER SION_FACTOR;JOptionPane.showMessageDialog(null,"The Time is:"+time+"\n"+"The Hour is:"+hour+"\n"+"The Minute is:"+minute+"\n"+"The Second is:"+second,"Result",RMATION_MESSAGE);}}PP2.9 编写一个应用程序,提示输入一个代表总钱数的双精度值,然后确定每种纸币和硬币需要的最小数量以达到输入的总钱数(假设10人民币为所需要的最大面额)。
例如,如果输入的值为47.63(47元6角3分),那么程序应当输出如下结果:4 ten yuan1 five yuan2 one yuan6 one jiao3 one fenimport javax.swing.*;public class sixth {/*** 作业PP2.9 编写一个应用程序,提示输入一个代表总钱数的双精度值,然后确定每种纸币和硬币需要的最小数量以达到输入的总钱数(假设10人民币为所需要的最大面额)。
*/public static void main(String[] args) {double money;int a,b,c,d,e;final int number=10;final int number1=5;String tempstr=JOptionPane.showInputDialog("Input Money Please");money=(double)Float.parseFloat(tempstr);a=(int) (money/number);b=(int)((money-a*number)/number1);c=(int)((money-a*number-b*number1)/1);d=(int)((money-a*number-b*number1-c*1)*number)/1;e=(int)(((money-a*number-b*number1-c*1)*number*number)%10);JOptionPane.showMessageDialog(null,"The Money is"+" "+money+"\n"+a+" "+"ten yuan"+"\n"+b+" "+"five yuan"+"\n"+c+" "+"one yuan"+"\n"+d+" "+"one jiao"+"\n"+e+" "+"one fen","Result",RMATION_MESSAGE);}}PP2.11 编写一个应用程序,提示输入两个整数分别作为分数的分子和分母,然后打印输出其小数表示。