佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1116|回复: 16

JAVA问题,帮帮忙!

[复制链接]
发表于 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 15% for gratuity rate, the program displays $1.5 as gratuity and $11.5 as total.
回复

使用道具 举报


ADVERTISEMENT

发表于 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  ...

  1. double subtotal;
  2. double total;
  3. double gratuity_rate;
  4. double gratuity;

  5. String input1 = JOptionPane.showInputDialog (null,"Please the subtotal", "subtotal",JOptionPane.QUESTION_MESSAGE);
  6. subtotal = Double.parseDouble(input1);

  7. String input2 = JOptionPane.showInputDialog (null,"Please the gratuity rate", "gratuity rate",JOptionPane.QUESTION_MESSAGE);
  8. gratuity_rate = Double.parseDouble(input2);


  9. gratuity = subtotal * gratuity_rate;

  10. total = subtotal + gratuity;

  11. 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 | 显示全部楼层
http://java.sun.com/docs/books/t ... ponents/dialog.html
http://java.sun.com/j2se/1.4.2/d ... ng/JOptionPane.html

那是JAVA Swing 的 CLASS 啦..
不懂的话, 就善用google.. 除非没打算做程序员..
回复

使用道具 举报

 楼主| 发表于 17-8-2008 04:29 PM | 显示全部楼层
这是功课,没学过当然要问啦!
谢谢你啦!
回复

使用道具 举报

发表于 18-8-2008 12:26 AM | 显示全部楼层
jasonmun给的link应该解释很清楚了。你现在明白了吧!
回复

使用道具 举报

Follow Us
发表于 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 ...
不过,答案好像有差异...简易的版本: 
  1.     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....
  1. import java.util.Scanner;
  2. ...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 编辑 ]
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 18-8-2008 10:09 PM | 显示全部楼层
原帖由 平凡小男孩 于 18-8-2008 12:26 AM 发表
jasonmun给的link应该解释很清楚了。你现在明白了吧!


不过他给的link我都进不到。。。
回复

使用道具 举报

 楼主| 发表于 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。
  1. import java.util.Scanner;
  2. ...
  3. Scanner in = new Scanner(System.in);
  4. System.out.print("lease enter the subtotal: ";
  5. double subtotal = in.nextDouble();
  6. System.out.print("lease enter gratuity rate(%): ";
  7. double gratuityRate = in.nextDouble();
  8. double gratuity = gratuityRate / subtotal;
  9. //double gratuity = subtotal * gratuityRate;  //wrong?
  10. 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 | 显示全部楼层
原帖由 Squall_Chua 于 20-8-2008 09:51 AM 发表
java和c都分不清楚

黃sir的code很明顯是java來的


因为printf 啊!java 不是println 吗?
我是初学者,分不清楚也不奇怪啊!!!
回复

使用道具 举报

发表于 21-8-2008 11:07 PM | 显示全部楼层
原帖由 skyblueyin 于 20-8-2008 10:10 PM 发表


因为printf 啊!java 不是println 吗?
我是初学者,分不清楚也不奇怪啊!!!

printf和format是JDK 1.5的新方法

http://java.sun.com/j2se/1.5.0/docs/api/java/io/PrintWriter.html#printf(java.lang.String,%20java.lang.Object...)

但是用之前请教你的老师他是否“支持“JDK 1.5。
回复

使用道具 举报

发表于 22-8-2008 12:43 AM | 显示全部楼层
double d1 = 10;
                System.out.println("gratuity="+d1*0.15+", total="+d1*1.15);
回复

使用道具 举报


ADVERTISEMENT

发表于 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));

        }

}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 23-12-2025 09:13 AM , Processed in 0.147066 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表