gpt4 book ai didi

java - 在 Java 中未将类对象检测为类

转载 作者:行者123 更新时间:2023-11-29 03:16:17 24 4
gpt4 key购买 nike

所以这是我的完整代码,我已经完成了重命名之类的操作,但它仍然没有检测到我的对象“atm”。我总是收到此错误。

C:\Users\USER\Documents\JCreator LE\MyProjects\oreo\src\oreo.java:30: error: cannot find symbol System.out.println("\nYour Savings balance is now: " + atm.gbalance + "\n");

import java.util.Scanner;

public class oreo {
private static Scanner input = new Scanner(System.in);

public static void main(String[] args) {
Account atm = new Account();

atm.intBalance(0.00);

boolean atm_status = true;
while(atm_status) {
System.out.print("1.Deposit\n");
System.out.print("\n2.Withdraw");
System.out.print("\n3.Check Balance");
System.out.print("\n4.Exit");
System.out.print("\nOption: ");
int option = input.nextInt();

switch(option) {
case 1:
System.out.print("How much would you like to deposit?");
double deposit = input.nextDouble();
atm.deposit(deposit);
break;
case 2:
double withdraw;
System.out.print("Your balance is:" + atm.gbalance + "\n");
System.out.print("How much would you like to withdraw?" );
withdraw= input.nextDouble();
System.out.println("\nYour Savings balance is now: " + atm.gbalance + "\n");
break;
case 3:
System.out.println("Your current balance is: " + atm.gbalance + "\n");
break;
case 4:
atm_status = false;
break;
}
}
}
}


class Account {
double balance;

void intBalance(double set) {
balance = set;
}

void deposit(double depo) {
balance +=depo;
}

void withdraw(double with){
balance -=with;
}

double gbalance(){
return balance;
}
}

最佳答案

atm.gbalance 是一种方法,而不是您的 Account 类中的变量,因此您在访问它时需要括号 ()。所以改变这些

atm.gbalance

atm.gbalance()

关于java - 在 Java 中未将类对象检测为类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26395862/

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