-3
我試圖使用繼承來編寫程序,它將根據用戶使用情況打印最具成本效益的寬帶/電話包。 (所以基本的想法是用戶輸入所需的分鐘數和MB寬度,並且程序打印使用方面最接近的匹配。) 我一直收到錯誤「類帳戶中的構造函數帳戶不能應用於給定的類型「每當我嘗試在終端在調用方法時,類中的構造函數不能應用於給定的類型錯誤
用戶類調用來自其它類的方法 錯誤在下面的圖片
錯誤消息:
import java.util.*;
public class UserAccount {
public static void main(String [] args){
Scanner input = new Scanner(System.in);
BronzeAccount newBronzeAccount;
SilverAccount newSilverAccount;
GoldAccount newGoldAccount;
double dayPhone;
double evePhone;
double extBroadband;
調用方法在用戶等級:
newBronzeAccount = new BronzeAccount(dayPhone, evePhone, extBroadband);
newSilverAccount = new SilverAccount(dayPhone, evePhone, extBroadband);
newGoldAccount = new GoldAccount(dayPhone, evePhone, extBroadband);
System.out.println("Account Summary for Bronze Account");
newBronzeAccount.printPackageBronze();
System.out.println("Account Summary for Silver Account");
newSilverAccount.printPackageSilver();
System.out.println("Account Summary for Gold Account");
newGoldAccount.printPackageGold();
構造從子類:
public BronzeAccount(double newdayPhone, double newevePhone,
doublenewextBroadband,double newtotCost){
public SilverAccount(double newdayPhone, double newevePhone,
double newextBroadband, double newtotCost, String newextras){
super(newdayPhone, newevePhone, newextBroadband, newtotCost);
public GoldAccount(double newdayPhone, double newevePhone,
double newextBroadband, double newtotCost, String newextras,
String newdmusic){
super(newdayPhone, newevePhone, newextBroadband, newtotCost, newextras);
我試着改變了在子類,這似乎更有意義,聲明的變量,以那些因爲那是什麼錯誤信息似乎需要,但似乎沒有辦法。
您沒有將'newtotCost'作爲您的構造函數所需的參數傳遞給'BronzeAccount',對於剩下的類,您沒有將參數的數量傳遞給其餘的構造函數子類需要。 – px06
你的子類需要4個參數,但是你傳遞的參數與四個參數不匹配。 – Shriram
僅供參考,在這樣的情況下,最好閱讀編譯器錯誤消息,因爲它們在發佈問題之前完全有意義。 [閱讀關於構造函數](https://docs.oracle.com/javase/tutorial/java/javaOO/constructors.html)。 – px06