Please fix my code I submit my code but my output result wro
Please fix my code
I submit my code, but my output result wrong. check this.
Main.java
public class Main {
public static void main(String[] args) {
// Feel free to add more to this to test things out.
// You will be graded by the automatic tests you get from \"Run Tests\"
BankAccount b1 = new BankAccount(\"abc\");
BankAccount b2 = new BankAccount(\"123\");
b1.deposit(300);
b2.deposit(400);
b1.transfer(150, b2); // should remove 150 from b2 and put it in b1
// Should show a deposit, a move from b1, and a final balance of 450
System.out.println(b1.report());
// Should show a deposit, a move to b1, and a final balance of 250
System.out.println(b2.report());
}
}
public class BankAccount {
public int balance;
public final String accountNumber;
public String transactionLog;
public BankAccount(String accountNumber) {
this.accountNumber = accountNumber;
this.balance = 0;
this.transactionLog = \"\";
}
public String report() {
// FILL ME IN!
String s = \"\";
s = transactionLog +\"\ \" + \"Balance:$\"+balance;
return s;
}
public int getBalance() {
// FILL ME IN!
return balance;
}
public void transfer(int transferAmount, BankAccount fromAccount) {
// FILL ME IN!
if(transferAmount<0 && transferAmount >fromAccount.balance){
}
else{
balance = balance + transferAmount;
fromAccount.balance = fromAccount.balance - transferAmount;
transactionLog = \"Deposit:$\" +balance + \"\ \"+ \"Transfer from\" +fromAccount.accountNumber+ \":$\" + transferAmount;
System.out.println(report());
}
}
public void withdraw(int withdrawalAmount) {
// FILL ME IN!
if(withdrawalAmount < 0 && withdrawalAmount >balance){}
else{
balance = balance - withdrawalAmount;
transactionLog = \"Deposit:$\" +balance + \"\ \"+\"Withdrawal:$\" +withdrawalAmount;
System.out.println(report());
}
}
public void deposit(int depositAmount) {
// FILL ME IN!
if(depositAmount<0){}
else
{
balance = balance + depositAmount;
transactionLog = \"Deposit:$\"+balance;
System.out.println(report());
}
}
}
Solution
I had made changes in it.Now,the calculations and all are showing correct values
![Please fix my code I submit my code, but my output result wrong. check this. Main.java public class Main { public static void main(String[] args) { // Feel free Please fix my code I submit my code, but my output result wrong. check this. Main.java public class Main { public static void main(String[] args) { // Feel free](/WebImages/34/please-fix-my-code-i-submit-my-code-but-my-output-result-wro-1101693-1761582236-0.webp)
![Please fix my code I submit my code, but my output result wrong. check this. Main.java public class Main { public static void main(String[] args) { // Feel free Please fix my code I submit my code, but my output result wrong. check this. Main.java public class Main { public static void main(String[] args) { // Feel free](/WebImages/34/please-fix-my-code-i-submit-my-code-but-my-output-result-wro-1101693-1761582236-1.webp)