|
查看: 1117|回复: 16
|
JAVA问题,帮帮忙!
[复制链接]
|
|
|
请问这道问题要怎么做?还有double是什么意思?
Write a program that reads the subtotal and the gratuity rate, and computes the gratuity and total. For example, if the user enters 10 for subtotal and 15% for gratuity rate, the program displays $1.5 as gratuity and $11.5 as total. |
|
|
|
|
|
|
|
|
|
|
发表于 17-8-2008 12:36 AM
|
显示全部楼层
原帖由 skyblueyin 于 16-8-2008 04:59 PM 发表 
请问这道问题要怎么做?还有double是什么意思?
Write a program that reads the subtotal and the gratuity rate, and computes the gratuity and total. For example, if the user enters 10 for subtotal and ...
- double subtotal;
- double total;
- double gratuity_rate;
- double gratuity;
- String input1 = JOptionPane.showInputDialog (null,"Please the subtotal", "subtotal",JOptionPane.QUESTION_MESSAGE);
- subtotal = Double.parseDouble(input1);
- String input2 = JOptionPane.showInputDialog (null,"Please the gratuity rate", "gratuity rate",JOptionPane.QUESTION_MESSAGE);
- gratuity_rate = Double.parseDouble(input2);
- gratuity = subtotal * gratuity_rate;
- total = subtotal + gratuity;
- JOptionPane.showMessageDialog (null, "The gratuity : " + gratuity + "\nThe total : " + total,"", JOptionPane.QUESTION_MESSAGE);
复制代码
这是你要的答案吗?如果看不明白就问吧!
double是让你的数字可以拥有小数点。就像11.50。 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 17-8-2008 03:02 PM
|
显示全部楼层
为什么要放String input1?
这又是什么意思JOptionPane.showInputDialog?
你是programmer吗?
谢谢你的帮忙!!! |
|
|
|
|
|
|
|
|
|
|
发表于 17-8-2008 04:03 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 17-8-2008 04:29 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 18-8-2008 12:26 AM
|
显示全部楼层
jasonmun给的link应该解释很清楚了。你现在明白了吧! |
|
|
|
|
|
|
|
|
|
|
发表于 18-8-2008 12:45 AM
|
显示全部楼层
原帖由 平凡小男孩 于 17-8-2008 12:36 AM 发表 double subtotal;double total;double gratuity_rate;double gratuity;String input1 = JOptionPane.showInputDialog (null,"Please the subtotal", "subtotal",JOptionPane.QUESTION_MESSAGE);subt ... 不过,答案好像有差异...简易的版本: -     Scanner in = new Scanner(System.in);    System.out.print("Please enter the subtotal: ");    double subtotal = in.nextDouble();    System.out.print("Please enter gratuity rate(%): ");    double gratuityRate = in.nextDouble();    double gratuity = gratuityRate / subtotal;    //double gratuity = subtotal * gratuityRate;  //wrong?    System.out.printf("The gratuity: $%.2f, total: $%.2f\n", gratuity, gratuity + subtotal);
复制代码
[ 本帖最后由 黄sir 于 18-8-2008 12:50 AM 编辑 ] |
|
|
|
|
|
|
|
|
|
|
发表于 18-8-2008 12:56 AM
|
显示全部楼层
唉...为什么佳礼不能顺畅读取LF? 就一定要CR+LF.... - import java.util.Scanner;
- ...Scanner in = new Scanner(System.in);System.out.print("Please enter the subtotal: ");double subtotal = in.nextDouble();System.out.print("Please enter gratuity rate(%): ");double gratuityRate = in.nextDouble();double gratuity = gratuityRate / subtotal;//double gratuity = subtotal * gratuityRate;  //wrong?System.out.printf("The gratuity: $%.2f, total: $%.2f\n", gratuity, gratuity + subtotal);
复制代码
[ 本帖最后由 黄sir 于 18-8-2008 12:58 AM 编辑 ] |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 18-8-2008 10:09 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 18-8-2008 10:11 PM
|
显示全部楼层
回复 8# 黄sir 的帖子
你给的好像不是java,而是C叻!!!!还是看的一头雾水。。。
不过还是要谢谢你们啦! |
|
|
|
|
|
|
|
|
|
|
发表于 19-8-2008 04:34 PM
|
显示全部楼层
原帖由 skyblueyin 于 18-8-2008 10:11 PM 发表 你给的好像不是java,而是C叻!!!!还是看的一头雾水。。。不过还是要谢谢你们啦! 绝对不是C。
- import java.util.Scanner;
- ...
- Scanner in = new Scanner(System.in);
- System.out.print("lease enter the subtotal: ";
- double subtotal = in.nextDouble();
- System.out.print("lease enter gratuity rate(%): ";
- double gratuityRate = in.nextDouble();
- double gratuity = gratuityRate / subtotal;
- //double gratuity = subtotal * gratuityRate; //wrong?
- System.out.printf("The gratuity: $%.2f, total: $%.2f\n", gratuity, gratuity + subtotal);
复制代码
[ 本帖最后由 黄sir 于 19-8-2008 04:38 PM 编辑 ] |
|
|
|
|
|
|
|
|
|
|
发表于 20-8-2008 09:51 AM
|
显示全部楼层
回复 10# skyblueyin 的帖子
java和c都分不清楚
黃sir的code很明顯是java來的 |
|
|
|
|
|
|
|
|
|
|
发表于 20-8-2008 08:29 PM
|
显示全部楼层
原帖由 skyblueyin 于 18-8-2008 10:09 PM 发表
不过他给的link我都进不到。。。
进不到?
http://java.sun.com
你以为以上网站是什么地方.. 检查你的电脑吧.. 可以已经有问题了.. |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 20-8-2008 10:10 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 21-8-2008 11:07 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 22-8-2008 12:43 AM
|
显示全部楼层
double d1 = 10;
System.out.println("gratuity="+d1*0.15+", total="+d1*1.15); |
|
|
|
|
|
|
|
|
|
|
发表于 29-8-2008 01:13 AM
|
显示全部楼层
大家都很熱心. 這個可以嗎?
public class CountGratuityAndTotal {
public static void main(String[] args) {
double rate = 0;
double subTotal = 0;
if (args.length == 2){
rate = Double.parseDouble(args[0]);
subTotal = Double.parseDouble(args[1]);
}
System.out.println("gratuity="+rate*subTotal+", total="+subTotal*(rate+1));
}
} |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|