我正在做讲师给的作业,所有输出都是正确的,但折扣后的价格和付款输出不正确,我不知道问题出在哪里..有人可以帮我解决这个问题吗?我仍然试图理解编码..
这是我的编码..
import java.util.*;
public class Apps {
public static void main (String args []) {
double price=0.0, discount=0.0, total=0.0;
Scanner sc = new Scanner (System.in);
String lineSeparator = System.getProperty("line.separator");
System.out.print("Please input your name : ");
String name = sc.next();
System.out.print("What is your status [A-Adult | C-Children] : ");
String status = sc.next();
System.out.print("Please enter type of treatment[1-Restoration | 2-Extraction | 3-Scaling] : ");
int type = sc.nextInt();
if(status=="C"){
if(type=='1'){
price = 6.0;
discount = price * 0.90;}
else if(type=='2'){
price = 15.5;
discount = price * 0.90;}
else{
price = 4.0;
discount = price * 0.90;}}
else if(status=="A"){
if(type=='1'){
price = 7.5;
discount = price * 0.95;}
else if(type=='2'){
price = 18.0;
discount = price * 0.95;}
else{
price = 5.5;
discount = price * 0.95;}}
System.out.println(" \n\n HUSNA DENTAL");
System.out.println(" ====================================================================");
System.out.println(" Name : "+name);
System.out.println(" Type of treatment : "+type);
System.out.println(" Payment before discount: "+price);
System.out.println(" Payment after discount : "+(total=price-discount));
System.out.println(" ====================================================================");
}
}
输出是这样的。。
请输入您的姓名:deena
您的状态是什么 [A-成人 | C-儿童] : C
请输入治疗类型[1-修复 | 2-萃取 | 3-缩放]:1
HUSNA DENTAL
====================================================================
Name : deena
Type of treatment : 1
Payment before discount: 0.0
Payment after discount : 0.0
====================================================================