到目前爲止,我還創建了兩個類,方法,我會告訴下面不知道如何創建一個使用從我的其他類
我檢測了兩個班,他們都似乎工作的菜單。
我現在需要創建將使用我創建了兩個類,並允許用戶輸入的信息,並找到他們的帳戶信息,以下菜單:
- 添加客戶詳細介紹
- 進行存款的業務帳戶
- 錄製抄表業務帳戶
- 顯示業務帳戶
- 顯示器充分考慮d的當前餘額etails
- 更改折扣價值,爲企業帳戶
- 更改單位成本爲所有業務佔
- 如何使用菜單系統
雖然我已經盡了最大努力找出如何在線使用資源,我現在丟失了。到目前爲止,每次嘗試創建菜單系統時,我都無法使其工作。如果有人能夠幫助我瞭解如何去做,我會非常感激。
謝謝:)
public class GasAccount
{
private int intAccRefNo;
private String strName;
private String strAddress;
public double dblBalance;
private double dblUnits;
public static double dblUnitsCosts = 0.02;
public GasAccount (int intNewAccRefNo , String strNewName , String strNewAddress)
{
}
public GasAccount (int intNewAccRefNo , String strNewName , String strNewAddress , double dblNewUnits)
{
intAccRefNo = intNewAccRefNo;
strName = strNewName;
strAddress = strNewAddress;
dblUnits = dblNewUnits;
dblBalance = dblUnits * dblUnitsCosts;
}
public int getAccRefNo()
{
return intAccRefNo;
}
public String getName()
{
return strName;
}
public String getAddress()
{
return strAddress;
}
public void deposit(double dblDepositAmount)
{
dblBalance = dblBalance - dblDepositAmount;
}
public double getBalance()
{
return dblBalance;
}
public double getUnitCost()
{
return dblUnitsCosts;
}
public void recordUnits (double dblUnitsUsed)
{
dblBalance = dblBalance + dblUnitsUsed * dblUnitsCosts;
dblUnits = dblUnitsUsed + dblUnits;
}
public double getUnits()
{
return dblUnits;
}
public void updateUnitsCosts(double dblNewUnitsCosts)
{
this.dblUnitsCosts = dblNewUnitsCosts;
}
}
而另一延伸它 -
public class BusinessAccount extends GasAccount
{
private double dblDiscount;
public BusinessAccount (int intNewAccRefNo, String strNewName, String strNewAddress, double dblNewUnits, double dblNewDiscount)
{
super (intNewAccRefNo , strNewName , strNewAddress, dblNewUnits);
dblDiscount = dblNewDiscount;
}
public void setNewDiscount(double dblNewDiscount)
{
dblDiscount = dblNewDiscount;
}
public double getDiscount()
{
return dblDiscount;
}
@Override
public void recordUnits (double dblUnitsUsed)
{
double dblNewBalance;
dblBalance = dblBalance + dblUnitsUsed * dblUnitsCosts;
dblNewBalance = dblUnitsUsed * dblUnitsCosts * dblDiscount/100;
dblBalance = dblBalance - dblNewBalance;
}
這裏是我的嘗試菜單看起來像到第五個選項。由於BuisnessAccount.getMethod始終顯示爲錯誤,因此我正在調用其他類的方法時發生了可怕的錯誤。我也很確定再次聲明變量是完全錯誤的,因爲他們沒有鏈接到我的其他類。
如果有人可以幫我解決這一點,將不勝感激
import java.util.Scanner;
public class Menu
{
public static void main(String [] args)
{
Scanner input = new Scanner(System.in);
int Choice;
{
System.out.println("------------------------------");
System.out.println ("1. Add the customers details") ;
System.out.println ("2. Make a deposit to the business account");
System.out.println ("3. Record a meter reading to the business account") ;
System.out.println ("4. Display current balance of the business account") ;
System.out.println ("5. Display full account details") ;
System.out.println ("6. Change the discount value for the business account") ;
System.out.println ("7. Change the cost per unit for all business accounts ");
System.out.println ("8. How to use the menu system ");
System.out.println ("Any other number will exit the program");
System.out.println("------------------------------");
System.out.println ("\n\nEnter a number from 1 to 8");
Choice = input.nextInt();
switch (Choice)
{
case 1 :
int intNewAccRefNo;
String strNewName;
String strNewAddress;
Double dblNewUnits;
Double dblNewDiscount;
System.out.println("Please enter the account number?");
intNewAccRefNo = input.nextInt();
System.out.println("Please enter the account name?");
input.nextLine();
strNewName = input.nextLine();
System.out.println("Please enter the account address?");
strNewAddress = input.nextLine();
System.out.println("Please enter the number of initial number of units used?");
dblNewUnits = input.nextDouble();
System.out.println("Please enter the discount?");
dblNewDiscount = input.nextDouble();
case 2:
double dblDeposit;
System.out.println("Please enter the amount you want to deposit?");
dblDeposit = input.nextDouble();
System.out.println ("The current balance: " + BusinessAccount.getBalance()) ;
case 3:
double dblUnits;
System.out.println("Enter the number of Units Used");
dblUnits = input.nextDouble();
BusinessAccount.recordUnits(dblUnits);
case 4:
System.out.println("\n Current Balance: £"+ BusinessAccount.getBalance());
case 5:
System.out.println("Account Reference Number: " + BusinessAccount.getAccRefNo());
System.out.println("Address: " + BusinessAccount.getAddress());
System.out.println("Name: " + BusinessAccount.getName());
System.out.println("Balance: " + BusinessAccount.getBalance());
System.out.println("Discount: " + BusinessAccount.getDiscount());
System.out.println("Units: " + BusinessAccount.getUnits());
case 1 :
String strAddress;
System.out.println("Please enter the account address?");
strAddress = input.nextLine();
System.out.println("Address:" + firstAccount.getAddress());
有什麼用戶輸入和我打電話的方法之間沒有聯繫,不知道如何固定。
的[不知道如何創建一個菜單可能重複它使用我的其他類](http://stackoverflow.com/questions/16631050/not-sure-how-to-create-a-menu-which-uses-my-other-class) – camickr