gpt4 book ai didi

java - 不确定如何创建使用其他类方法的菜单

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:52:22 25 4
gpt4 key购买 nike

<分区>

到目前为止我已经创建了两个类,我将在下面展示

我已经测试了这两个类,它们似乎都有效。

我现在需要创建一个菜单,它将使用我创建的两个类并允许用户输入信息并在他们的帐户中查找以下信息:

  1. 添加客户详细信息
  2. 向企业账户存入资金
  3. 将抄表记录到企业帐户
  4. 显示企业账户的当前余额
  5. 显示完整的帐户详细信息
  6. 更改企业帐户的折扣值
  7. 更改所有企业帐户的单位成本
  8. 如何使用菜单系统

虽然我已尽最大努力使用在线资源找出如何做到这一点,但我目前迷路了。到目前为止,每次我尝试创建菜单系统时,我都无法让它工作。如果有人可以帮助我了解如何去做的基础知识,我将不胜感激。

谢谢:)


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());

用户输入的内容与我调用的方法之间没有联系,不知道如何解决。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com