Question

WHERE in this code should you put the main method so that the code will compile...

WHERE in this code should you put the main method so that the code will compile WITHOUT changing anything else in the code? Simply adding the main method only?

public class Account

{

private String name;

private double balance;

  

public Account(String name, double balance)

{

this.name = name;

if (balance > 0.0)

this.balance = balance;

}

public void deposit(double depositAmount)

{

if (depositAmount > 0.0)

balance += depositAmount;

}

  

public double getBalance()

{

return balance;

}

public String getName()

{

return name;

}

  

public void withdraw(double amount)

{

if (this.balance

System.out.printf("Given amount not available in your account.");

}

else

{

this.balance = this.balance - amount;

System.out.printf("Amount withdrawn successfully.");

}

}

} //

0 0
Add a comment Improve this question Transcribed image text
Answer #1

public class Account {
    private String name;
    private double balance;

    public Account(String name, double balance) {
        this.name = name;
        if (balance > 0.0)
            this.balance = balance;
    }

    public void deposit(double depositAmount) {
        if (depositAmount > 0.0)
            balance += depositAmount;
    }

    public double getBalance() {
        return balance;
    }

    public String getName() {
        return name;
    }

    public void withdraw(double amount) {
        if (this.balance < amount) {
            System.out.printf("Given amount not available in your account.");
        } else {
            this.balance = this.balance - amount;
            System.out.printf("Amount withdrawn successfully.");
        }
    }

    public static void main(String[] args) {
        // Test your code here...
    }
} //
Add a comment
Know the answer?
Add Answer to:
WHERE in this code should you put the main method so that the code will compile...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • NOTE: Use the Account class codes in the section below these questions. Modify the main method...

    NOTE: Use the Account class codes in the section below these questions. Modify the main method in the CheckingAccountDemo class: Take out all previous code. Declare an object array with 10 accounts. Create a for loop to ask user to input each account’s information (name, account number, and initial balance) from keyboard and then initialize for each account object. Create a while loop to allow one to work on depositing and withdrawing operations on any account till one want to...

  • Use the Java codes below (Checking Account and Checking Account Demo), and work on these problems....

    Use the Java codes below (Checking Account and Checking Account Demo), and work on these problems. You have to do both of your java codes based on the two provided Java codes. Create one method for depositing and one for withdrawing. The deposit method should have one parameter to indicate the amount to be deposited. You must make sure the amount to be deposited is positive. The withdraw method should have one parameter to indicate the amount to be withdrawn...

  • I need to update the code listed below to meet the criteria listed on the bottom....

    I need to update the code listed below to meet the criteria listed on the bottom. I worked on it a little bit but I could still use some help/corrections! import java.util.Scanner; public class BankAccount { private int accountNo; private double balance; private String lastName; private String firstName; public BankAccount(String lname, String fname, int acctNo) { lastName = lname; firstName = fname; accountNo = acctNo; balance = 0.0; } public void deposit(int acctNo, double amount) { // This method is...

  • please rewrite this code as Pseudo-Code,.. basically rewrite the code but in english language , Thank...

    please rewrite this code as Pseudo-Code,.. basically rewrite the code but in english language , Thank you so much! public abstract class BankAccount {    //declare the required class variables    private double balance;    private int num_deposits;    private int num_withdraws;    private double annualInterest;    private double serviceCharges;       //constructor that takes two arguments    // one is to initialize the balance and other    // to initialize the annual interest rate       public BankAccount(double balance,...

  • Write a Java class called BankAccount (Parts of the code is given below), which has two...

    Write a Java class called BankAccount (Parts of the code is given below), which has two fields name (String) and balance (double), two constructors and five methods getName(), getBalance(), deposit (double amount), withdraw(double amount) and toString(). The first constructor should initialize name to null and balance to 0. The second constructor initializes name and balance to the parameters passed. deposit method deposits the amount to the account causing the current balance to increase, withdraw method withdraws the amount causing the...

  • Write a Java class called BankAccount (Parts of the code is given below), which has two...

    Write a Java class called BankAccount (Parts of the code is given below), which has two fields name (String) and balance (double), two constructors and five methods getName(), getBalance(), deposit (double amount), withdraw(double amount) and toString(). The first constructor should initialize name to null and balance to 0. The second constructor initializes name and balance to the parameters passed. deposit method deposits the amount to the account causing the current balance to increase, withdraw method withdraws the amount causing the...

  • Point out errors in the following codes and correct them public class CheckingAccount {       //...

    Point out errors in the following codes and correct them public class CheckingAccount {       // Create attributes accountNum, Balance       private int accountNum; // Account Number       private double balance; // Account balance       // Constructor       public void CheckingAccount(int aNum, double balance) {             // Call setters to initialize attribute values             setAccountNumber(aNum);             setBalance;       }       // Setters       public void setAccountNumber(int aNum) {             if (accountNum >= 100) {                   accountNum = aNum;             }...

  • Write a unit test to test the following class. Using Java : //Test only the debit...

    Write a unit test to test the following class. Using Java : //Test only the debit method in the BankAccount. : import java.util.*; public class BankAccount { private String customerName; private double balance; private boolean frozen = false; private BankAccount() { } public BankAccount(String Name, double balance) { customerName = Name; this.balance = balance; } public String getCustomerName() { return customerName; } public double getBalance() { return balance; } public void setDebit(double amount) throws Exception { if (frozen) { throw...

  • NETBEANS JAVA BANK PROGRAM (TAKE SCREENSHOTS FROM NETBEANS INCLUDING OUTPUT PLEASE) Display the accounts for the...

    NETBEANS JAVA BANK PROGRAM (TAKE SCREENSHOTS FROM NETBEANS INCLUDING OUTPUT PLEASE) Display the accounts for the current displayed customer PLEASEEEEEEEEEE package bankexample; import java.util.UUID; public class Customer { private UUID id; private String email; private String password; private String firstName; private String lastName;    public Customer(String firstName, String lastName, String email, String password) { this.id = UUID.randomUUID(); this.firstName = firstName; this.lastName = lastName; this.email = email; this.password = password; } public String getFirstName() { return firstName; } public void setFirstName(String...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT