
JAVA高手们 救命啊! 悬赏100
学校出了个问题是这样的!!!基本销售税率是10%,但是以下商品除外:书,食物,医用用品,这些产品是免销税的。进口税是一种附加的销售税,按照进口商品价格的5%收取,没有任何...
学校出了个 问题 是这样的!!!
基本销售税率是 10%,但是以下商品除外: 书,食物, 医用用品, 这些产品是免销税的。 进口税是一种附加的销售税, 按照进口商品价格的 5%收取,没有任何进口商品能免除进口税。
当我买商品的时候,我会受到一个列出了所有商品的名称和价格(含税)的收据, 在收据的最下面会提示总的销售税和总的价格。销售税四舍五入的规则是:税率是N%, 那么价格是P的商品所包含的税率是NP/100 再四舍五入到与这个数最接近的0.05, 比如如果是 3.44,那么四舍五入之后就是3.45,3.41四舍五入之后就是3.40
写一个程序,为以下的购物蓝输出上面提到的数据
INPUT:
input1:
1 book at 12.49
1 music CD at 14.99
1 chocolate bar at 0.85
OUTPUT
Output1
1 book : 12.49
1 music CD : 16.49
1 chocolate bar : 0.85
Sales Taxes : 1.50
Total 29.83
就这样 具体这么做高手们讲解一下!!!
还要加上单元测试 , 输入输出 , README, 批处理文件和解决方法!!!mark.kim1024@gmail.com 这是我的邮件能给我发下!必有重谢 展开
基本销售税率是 10%,但是以下商品除外: 书,食物, 医用用品, 这些产品是免销税的。 进口税是一种附加的销售税, 按照进口商品价格的 5%收取,没有任何进口商品能免除进口税。
当我买商品的时候,我会受到一个列出了所有商品的名称和价格(含税)的收据, 在收据的最下面会提示总的销售税和总的价格。销售税四舍五入的规则是:税率是N%, 那么价格是P的商品所包含的税率是NP/100 再四舍五入到与这个数最接近的0.05, 比如如果是 3.44,那么四舍五入之后就是3.45,3.41四舍五入之后就是3.40
写一个程序,为以下的购物蓝输出上面提到的数据
INPUT:
input1:
1 book at 12.49
1 music CD at 14.99
1 chocolate bar at 0.85
OUTPUT
Output1
1 book : 12.49
1 music CD : 16.49
1 chocolate bar : 0.85
Sales Taxes : 1.50
Total 29.83
就这样 具体这么做高手们讲解一下!!!
还要加上单元测试 , 输入输出 , README, 批处理文件和解决方法!!!mark.kim1024@gmail.com 这是我的邮件能给我发下!必有重谢 展开
3个回答
展开全部
上楼没有进行四舍五入计算,完整做法是:
package test3;
//商品类
public class Goods {
private int amount;
private String name;
private double price;
public Goods(){}
public Goods(int id,String name,double price){
this.amount = id;
this.name = name;
this.price = price;
}
/**
* @return the id
*/
public int getAmount() {
return amount;
}
/**
* @param id the id to set
*/
public void setAmount(int id) {
this.amount = id;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the price
*/
public double getPrice() {
return price;
}
/**
* @param price the price to set
*/
public void setPrice(double price) {
this.price = price;
}
}
/**
* 处理类
*/
package test3;
import java.util.ArrayList;
import java.util.Scanner;
public class SellTax {
ArrayList msgList = new ArrayList();//清单
String name;// 商品名称
Goods goods = null;
int amount = 0;// 商品件数
double price = 0.0;// 商品单价
static private double basicTax = 0.1;// 基本税
static private double entranceTax = 0.05;// 进口税
int kind = 0;// 商品种类
int entranceFlg = 0;// 是否进口
double totalTax = 0.0;// 总税收
double totalPrice = 0.0;// 总价格
String goodsMessage = "";
public void readin() {
boolean flag = true;
double tax = 0.0;
double goodPrice = 0.0;
while(flag){
System.out.println("请输入商品名称:");
Scanner scan = new Scanner(System.in);
try {
name =scan.next();
} catch (Exception e) {
System.out.println(e);
}
System.out.println("请输入购买数量:");
Scanner goodsAmount = new Scanner(System.in);
try {
amount = goodsAmount.nextInt();
} catch (Exception e) {
System.out.println("请输入正整数!");
break;
}
System.out.println("请输入商品单价:");
Scanner goodsPrice = new Scanner(System.in);
try {
price = goodsPrice.nextDouble();
} catch (Exception e) {
System.out.println("请输入数字!");
}
System.out.println("请输入商品种类: 1 书;2 食物;3 医疗用品;4 其他");
Scanner goodsKind = new Scanner(System.in);
try {
kind = goodsKind.nextInt();
if(kind > 4)
{
System.out.println("超出可选范围");
}
} catch (Exception e) {
System.out.println("请输入数字");
}
System.out.println("该商品是否进口: 1 进口;0 非进口");
Scanner goodsEntranceFlg = new Scanner(System.in);
try {
entranceFlg = goodsEntranceFlg.nextInt();
} catch (Exception e) {
System.out.println(e);
}
tax = this.computeTax();
totalTax +=tax;
goodPrice = price+tax;
goods = new Goods(amount,name,goodPrice);
msgList.add(goods);
System.out.println("是否继续添加:1.是,2.否!");
Scanner exit = new Scanner(System.in);
String arg = exit.next();
if(arg.equals("1"))
flag = true;
else
break;
}
}
// 计算税收
public double computeTax() {
double tax = 0.0;
if (kind == 4) {
tax = this.price * basicTax * this.amount;
int temp = (int)Math.round(tax * 100);
tax = (double)temp/100.00;
}
if (entranceFlg == 1) {
tax = this.price * tax * this.amount;
int temp = (int)Math.round(tax * 100);
tax = (double)temp/100.00;
}
return tax;
}
// 计算总价格
public double computePrice() {
double totalPrice=0.0;
for(int i=0;i<msgList.size();i++){
Goods good = (Goods)msgList.get(i);
totalPrice += good.getPrice();
}
int temp = (int)Math.round(totalPrice * 100);
totalPrice = (double)temp/100.00;
return totalPrice;
}
// 显示总税收和总价
public void view() {
for(int i=0;i<msgList.size();i++){
Goods good = (Goods)msgList.get(i);
goodsMessage = good.getAmount() + " " + good.getName() + " " + good.getPrice();
System.out.println(goodsMessage + "\n");
}
System.out.println("Sales Taxes: " + totalTax);
System.out.println("Sales TotlePrice:"+computePrice());
}
}
/**
* 主测试类
*/
package test3;
import java.lang.Math;
import java.util.ArrayList;
import java.util.Scanner;
public class MainTest {
public static void main(String[] args) {
SellTax selltax = new SellTax();
selltax.readin();
selltax.view();
}
}
package test3;
//商品类
public class Goods {
private int amount;
private String name;
private double price;
public Goods(){}
public Goods(int id,String name,double price){
this.amount = id;
this.name = name;
this.price = price;
}
/**
* @return the id
*/
public int getAmount() {
return amount;
}
/**
* @param id the id to set
*/
public void setAmount(int id) {
this.amount = id;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the price
*/
public double getPrice() {
return price;
}
/**
* @param price the price to set
*/
public void setPrice(double price) {
this.price = price;
}
}
/**
* 处理类
*/
package test3;
import java.util.ArrayList;
import java.util.Scanner;
public class SellTax {
ArrayList msgList = new ArrayList();//清单
String name;// 商品名称
Goods goods = null;
int amount = 0;// 商品件数
double price = 0.0;// 商品单价
static private double basicTax = 0.1;// 基本税
static private double entranceTax = 0.05;// 进口税
int kind = 0;// 商品种类
int entranceFlg = 0;// 是否进口
double totalTax = 0.0;// 总税收
double totalPrice = 0.0;// 总价格
String goodsMessage = "";
public void readin() {
boolean flag = true;
double tax = 0.0;
double goodPrice = 0.0;
while(flag){
System.out.println("请输入商品名称:");
Scanner scan = new Scanner(System.in);
try {
name =scan.next();
} catch (Exception e) {
System.out.println(e);
}
System.out.println("请输入购买数量:");
Scanner goodsAmount = new Scanner(System.in);
try {
amount = goodsAmount.nextInt();
} catch (Exception e) {
System.out.println("请输入正整数!");
break;
}
System.out.println("请输入商品单价:");
Scanner goodsPrice = new Scanner(System.in);
try {
price = goodsPrice.nextDouble();
} catch (Exception e) {
System.out.println("请输入数字!");
}
System.out.println("请输入商品种类: 1 书;2 食物;3 医疗用品;4 其他");
Scanner goodsKind = new Scanner(System.in);
try {
kind = goodsKind.nextInt();
if(kind > 4)
{
System.out.println("超出可选范围");
}
} catch (Exception e) {
System.out.println("请输入数字");
}
System.out.println("该商品是否进口: 1 进口;0 非进口");
Scanner goodsEntranceFlg = new Scanner(System.in);
try {
entranceFlg = goodsEntranceFlg.nextInt();
} catch (Exception e) {
System.out.println(e);
}
tax = this.computeTax();
totalTax +=tax;
goodPrice = price+tax;
goods = new Goods(amount,name,goodPrice);
msgList.add(goods);
System.out.println("是否继续添加:1.是,2.否!");
Scanner exit = new Scanner(System.in);
String arg = exit.next();
if(arg.equals("1"))
flag = true;
else
break;
}
}
// 计算税收
public double computeTax() {
double tax = 0.0;
if (kind == 4) {
tax = this.price * basicTax * this.amount;
int temp = (int)Math.round(tax * 100);
tax = (double)temp/100.00;
}
if (entranceFlg == 1) {
tax = this.price * tax * this.amount;
int temp = (int)Math.round(tax * 100);
tax = (double)temp/100.00;
}
return tax;
}
// 计算总价格
public double computePrice() {
double totalPrice=0.0;
for(int i=0;i<msgList.size();i++){
Goods good = (Goods)msgList.get(i);
totalPrice += good.getPrice();
}
int temp = (int)Math.round(totalPrice * 100);
totalPrice = (double)temp/100.00;
return totalPrice;
}
// 显示总税收和总价
public void view() {
for(int i=0;i<msgList.size();i++){
Goods good = (Goods)msgList.get(i);
goodsMessage = good.getAmount() + " " + good.getName() + " " + good.getPrice();
System.out.println(goodsMessage + "\n");
}
System.out.println("Sales Taxes: " + totalTax);
System.out.println("Sales TotlePrice:"+computePrice());
}
}
/**
* 主测试类
*/
package test3;
import java.lang.Math;
import java.util.ArrayList;
import java.util.Scanner;
public class MainTest {
public static void main(String[] args) {
SellTax selltax = new SellTax();
selltax.readin();
selltax.view();
}
}
展开全部
下面这个跟你这个有点接近
你自己再改改吧
import java.io.*;
import java.util.Scanner;
class SellTax{
String name;//商品名称
int amount = 0;//商品件数
double price = 0.0;//商品单价
static private double basicTax = 0.1;//基本税
static private double entranceTax = 0.05;//进口税
int kind=0;//商品种类
int entranceFlg=0;//是否进口
double totalTax = 0.0;//总税收
double totalPrice = 0.0;//总价格
String goodsMessage = "";
void readin(){
System.out.println("请输入商品名称:");
BufferedReader goodsName = new BufferedReader(new InputStreamReader(System.in));
try{name=goodsName.readLine();}catch(Exception e){System.out.println(e);}
System.out.println("请输入购买数量:");
Scanner goodsAmount = new Scanner(System.in);
try{amount=goodsAmount.nextInt();}catch(Exception e){System.out.println(e);}
System.out.println("请输入商品单价:");
Scanner goodsPrice = new Scanner(System.in);
try{price=goodsPrice.nextDouble();}catch(Exception e){System.out.println(e);}
System.out.println("请输入商品种类: 1 书;2 食物;3 医疗用品;4 其他");
Scanner goodsKind =new Scanner(System.in);
try{kind=goodsKind.nextInt();}catch(Exception e){System.out.println(e);}
System.out.println("该商品是否进口: 1 进口;0 非进口");
Scanner goodsEntranceFlg =new Scanner(System.in);
try{entranceFlg=goodsEntranceFlg.nextInt();}catch(Exception e){System.out.println(e);}
goodsMessage = amount+" "+name+" "+price;
System.out.println(goodsMessage+"\n");
totalTax = this.computeTax();
totalPrice = this.computePrice();
}
//计算税收
public double computeTax(){
if(kind==4){
totalTax += this.price * basicTax * this.amount;
}
if(entranceFlg==1){
totalTax += this.price * entranceTax * this.amount;
}
return totalTax;
}
//计算总价格
public double computePrice(){
totalPrice += this.price * this.amount;
return totalPrice;
}
//显示总税收和总价
public void view(){
System.out.println("Sales Taxes: " + totalTax);
System.out.println("totalPrice: " + totalPrice);
}
}
public class Goods{
public static void main(String[] args){
SellTax selltax = new SellTax();
selltax.readin();
selltax.view();
}
}
楼下的写的非常好,有个问题请教一下:
我编译你的SellTax.java时有个警告:
“SellTax.java:88:警告: [unchecked]对作为普通类型java.util.ArrayList的成员的add(E)的调用未经检查 msgList.add(goods);”
上面的警告怎么样才能消除呢?
你自己再改改吧
import java.io.*;
import java.util.Scanner;
class SellTax{
String name;//商品名称
int amount = 0;//商品件数
double price = 0.0;//商品单价
static private double basicTax = 0.1;//基本税
static private double entranceTax = 0.05;//进口税
int kind=0;//商品种类
int entranceFlg=0;//是否进口
double totalTax = 0.0;//总税收
double totalPrice = 0.0;//总价格
String goodsMessage = "";
void readin(){
System.out.println("请输入商品名称:");
BufferedReader goodsName = new BufferedReader(new InputStreamReader(System.in));
try{name=goodsName.readLine();}catch(Exception e){System.out.println(e);}
System.out.println("请输入购买数量:");
Scanner goodsAmount = new Scanner(System.in);
try{amount=goodsAmount.nextInt();}catch(Exception e){System.out.println(e);}
System.out.println("请输入商品单价:");
Scanner goodsPrice = new Scanner(System.in);
try{price=goodsPrice.nextDouble();}catch(Exception e){System.out.println(e);}
System.out.println("请输入商品种类: 1 书;2 食物;3 医疗用品;4 其他");
Scanner goodsKind =new Scanner(System.in);
try{kind=goodsKind.nextInt();}catch(Exception e){System.out.println(e);}
System.out.println("该商品是否进口: 1 进口;0 非进口");
Scanner goodsEntranceFlg =new Scanner(System.in);
try{entranceFlg=goodsEntranceFlg.nextInt();}catch(Exception e){System.out.println(e);}
goodsMessage = amount+" "+name+" "+price;
System.out.println(goodsMessage+"\n");
totalTax = this.computeTax();
totalPrice = this.computePrice();
}
//计算税收
public double computeTax(){
if(kind==4){
totalTax += this.price * basicTax * this.amount;
}
if(entranceFlg==1){
totalTax += this.price * entranceTax * this.amount;
}
return totalTax;
}
//计算总价格
public double computePrice(){
totalPrice += this.price * this.amount;
return totalPrice;
}
//显示总税收和总价
public void view(){
System.out.println("Sales Taxes: " + totalTax);
System.out.println("totalPrice: " + totalPrice);
}
}
public class Goods{
public static void main(String[] args){
SellTax selltax = new SellTax();
selltax.readin();
selltax.view();
}
}
楼下的写的非常好,有个问题请教一下:
我编译你的SellTax.java时有个警告:
“SellTax.java:88:警告: [unchecked]对作为普通类型java.util.ArrayList的成员的add(E)的调用未经检查 msgList.add(goods);”
上面的警告怎么样才能消除呢?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public double computeTax() {
double tax = 0.0;
if (kind == 4) {
tax = this.price * basicTax * this.amount;
int temp = (int)Math.round(tax * 100);
tax = (double)temp/100.00;
}
if (entranceFlg == 1) {
tax = this.price * tax * this.amount;
int temp = (int)Math.round(tax * 100);
tax = (double)temp/100.00;
}
return tax;
}
double tax = 0.0;
if (kind == 4) {
tax = this.price * basicTax * this.amount;
int temp = (int)Math.round(tax * 100);
tax = (double)temp/100.00;
}
if (entranceFlg == 1) {
tax = this.price * tax * this.amount;
int temp = (int)Math.round(tax * 100);
tax = (double)temp/100.00;
}
return tax;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询