我目前正在學計算機科學,我有點卡在我的實驗室。 下面列出了說明,我們需要使用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;
}
}