online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
public class Main { public static void main(String[] args) { //creates an Account object with an account ID of 1122, a balance of $20,000, Account account = new Account(1122, 20000); //and an annual interest rate of 4.5% account.setAnnualInterestRate(4.5); // Use the withdraw method to withdraw $2,500 account.withdraw(2500); // use the deposit method to deposit $3,000 account.deposit(3000); //print the balance, the monthly interest, and the date when this account was created. System.out.println("Balance: " + account.getBalance()); System.out.println("Monthly Interest: " + account.getMonthlyInterest()); System.out.println("Creation Date: " + account.getDate()); } }
import java.util.Date; public class Account { //A private int data field named id for the account (default 0) private int id; //A private double data field named balance for the account (default 0). private double balance; //A private double data field named annualInterestRate private double annualInterestRate; // A private Date data field named dateCreated private Date dateCreated; //A no-arg constructor that creates a default account. public Account() { id = 0; balance = 0; dateCreated = new Date(); } //A constructor that creates an account with the specified id and initial balance. public Account(int id, double balance) { this.id = id; this.balance = balance; dateCreated = new Date(); } //The accessor and mutator methods for id, balance, and annualInterestRate. public int getId() { return id; } public double getBalance() { return balance; } public double getAnnualInterestRate() { return annualInterestRate; } public void setID(int id) { this.id = id; } public void setBalance(double balance) { this.balance = balance; } public void setAnnualInterestRate(double annualInterestRate) { this.annualInterestRate = annualInterestRate; } // The accessor method for dateCreated. public Date getDate() { return dateCreated; } // A method named getMonthlyInterestRate() that returns the monthly interest rate. public double getMonthlyInterestRate() { return annualInterestRate / 12; } //A method named withdraw that withdraws a specified amount from the account. public void withdraw(double amount) { if (balance >= amount) { balance = balance - amount; } else { System.out.println("Insufficient funds"); } } //A method named deposit that deposits a specified amount to the account. public void deposit(double amount) { if (amount >= 0) { balance = balance + amount; } else { System.out.println("Invalid Amount"); } } // A method named getMonthlyInterest() that returns the monthly interest. public double getMonthlyInterest() { return balance*getMonthlyInterestRate(); } }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue