我目前正在学计算机科学,我有点卡在我的实验室。 下面列出了说明,我们需要使用OOP。 问题是我得到的输出超级奇怪,我真的不知道发生了什么。Java-OOP我一直在得到这个奇怪的输出
我运行该文件DiscountRunner.java
(代码如下所示)后得到的输出是:
Enter the original bill amount :: 4000
[email protected]
为什么我不断得到[email protected]
一部分?
/**==================================================================================================
* Objective : This lab was designed to teach you how to use if statements.
* Lab Description : Determine the amount of discount a person should receive.
* If the bill is more than 2000, then the person should receive a 15% discount.
* If the bill is 2000 dollars or less, the person does not receive a
* discount of any kind.
===================================================================================================*/
import static java.lang.System.*;
import java.util.Scanner;
public class DiscountRunner
{
public static void main(String [] args)
{
Scanner keyboard = new Scanner(System.in);
out.print("Enter the original bill amount :: ");
int amt = keyboard.nextInt();
int Discount;
Discount bill=new Discount();
bill.getDiscountedBill();
System.out.println(bill);
//instantiate a new Discount object called "bill"
//print the output of bill.getDiscountedBill() with amt as the parameter
}
}
这是文件一。
这里是文件二。
import static java.lang.System.*;
import java.util.Scanner;
public class Discount
{
//instance variables and constructors could be used, but are not really needed
int amt;
int bill;
//getDiscountedBill() will return final amount of the bill
// if the bill is >2000, the bill receives a 15% discount
public int getDiscountedBill()
{
if (amt>2000)
bill=amt*(int).85;
if (amt<=2000)
bill=amt*1;
return bill;
}
}