Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am trying to run this program throguh the compiler and cannot run it, it says

ID: 3586545 • Letter: I

Question

I am trying to run this program throguh the compiler and cannot run it, it says its missing the Java Main Method.

Please help! I need the code to run through the compiler.

Thanks!

Account
================
-int id = 0
-double balance = 0
-double annualInterestRate = 0 //remember this is a percentage so will /100
-Date dateCreated
================
+Account() //no args account (will need to give dateCreated)
+Account(int id, double InitialBalance)
+getters and setters for id, balance, and annual interest rate
+getter for dateCreated
+getMonthlyInterestRate()
+getMonthlyInterest()
+withdraw()
+deposit()


Test.java

public class Test {
    public static void main(String[] args) {
        //create account and set annual interest rate
        Account acc = new Account(1122, 20000);
        acc.setAnnualInterestRate(4.5);
      
        //withdraw and diposit
        acc.withdraw(2500);
        acc.diposit(3000);
      
        //output values
        System.out.println("Account ID: " + acc.getId());
        System.out.println("Account Balance: " + acc.getBalance());
        System.out.println("Account monthly interest: " + acc.getMonthlyInterest());
        System.out.println("Account Account created on: " + acc.getDateCreated().getTime());
    }
}


Account.java


import java.util.Calendar;
import java.util.Date;

public class Account {

    private int id;
    private double balance;
    private Calendar dateCreated;

    public Account() { //no args but still have to set current date
        dateCreated = Calendar.getInstance(); //sets the dateCreated to the current time
    }

    public Account(int id, double InitialBalance){
        this.id = id;
        balance = InitialBalance;
        dateCreated = Calendar.getInstance(); //sets the dateCreated to the current time
    }
  
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    private double annualInterestRate;

    public double getAnnualInterestRate() {
        return annualInterestRate;
    }

    public void setAnnualInterestRate(double annualInterestRate) {
        this.annualInterestRate = annualInterestRate;
    }

    public Calendar getDateCreated() {
        return dateCreated;
    }

    public double getMonthlyInterestRate(){
        return (annualInterestRate / 100) / 12; //div 100 as is percentage
    }
  
    public double getMonthlyInterest(){
        return balance * getMonthlyInterestRate();
    }
  
    public void withdraw(double amount){
        balance = balance - amount;
    }
  
    public void diposit(double amount){
        balance = balance + amount;
    }
  
}

Explanation / Answer

Hi,

I dont see any issue wit the code. Please place two java files in same foldr and also name it the files as same like below and run the Test class. If you are executing in ccmd then like below

> javac *.java

>java Test

Test.java


public class Test {
public static void main(String[] args) {
//create account and set annual interest rate
Account acc = new Account(1122, 20000);
acc.setAnnualInterestRate(4.5);
  
//withdraw and diposit
acc.withdraw(2500);
acc.diposit(3000);
  
//output values
System.out.println("Account ID: " + acc.getId());
System.out.println("Account Balance: " + acc.getBalance());
System.out.println("Account monthly interest: " + acc.getMonthlyInterest());
System.out.println("Account Account created on: " + acc.getDateCreated().getTime());
}
}

Account.java


import java.util.Calendar;
import java.util.Date;
public class Account {
private int id;
private double balance;
private Calendar dateCreated;
public Account() { //no args but still have to set current date
dateCreated = Calendar.getInstance(); //sets the dateCreated to the current time
}
public Account(int id, double InitialBalance){
this.id = id;
balance = InitialBalance;
dateCreated = Calendar.getInstance(); //sets the dateCreated to the current time
}
  
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
private double annualInterestRate;
public double getAnnualInterestRate() {
return annualInterestRate;
}
public void setAnnualInterestRate(double annualInterestRate) {
this.annualInterestRate = annualInterestRate;
}
public Calendar getDateCreated() {
return dateCreated;
}
public double getMonthlyInterestRate(){
return (annualInterestRate / 100) / 12; //div 100 as is percentage
}
  
public double getMonthlyInterest(){
return balance * getMonthlyInterestRate();
}
  
public void withdraw(double amount){
balance = balance - amount;
}
  
public void diposit(double amount){
balance = balance + amount;
}
  
}

Output:

Account ID: 1122
Account Balance: 20500.0
Account monthly interest: 76.875
Account Account created on: Thu Oct 05 06:31:05 IST 2017

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote