Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, can someone change this printf to println method. public class Account { private String name; private double balance; public Account(String

Hi, can someone change this "printf" to "println" method.

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.");

}

}

}//end class Account

Fig 7.9

import java.util.Scanner;

public class AccountTest

{

public static void main(String[] args)

{

Account account1 = new Account("Jane Green", 50.00);

Account account2 = new Account("John Blue", -7.53);

System.out.printf("%s balance: $%.2f%n", account1.getName(), account1.getBalance());

System.out.printf("%s balance: $%.2f%n%n", account2.getName(), account2.getBalance());

Scanner input = new Scanner(System.in);

System.out.print("Enter deposit amount for account1: ");

double depositAmount = input.nextDouble();

System.out,printf("%nadding %.2f to account1 balance%n%n", depositAmount);

account1.deposit(depositAmount);

System.out.printf("%s balance: $%.2f%n", account1.getName(), account1.getBalance());

System.out.printf("%s balance: $%.2f%n%n", account2.getName(), account2.getBalance());

System.out.print("Enter deposit amount for account2: ");

depositAmount = input.nextDouble();

System.out.printf("%nadding %.2f to account2 balance%n%n", depositAmount);

account2.deposit(depositAmount);

System.out.printf("%s balance: $%.2f%n", account1.getName(), account1.getBalance());

System.out.printf("%s balance: $%.2f%n%n", account2.getName(), account2.getBalance());

System.out.print("Input an amount for withdraw : ");

double amount = input.nextDouble();

account1.withdraw(amount);

}

}//end class AccountTest

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Logistics Lifeline Supply Chain Strategies

Authors: Ehsan Sheroy

1st Edition

7419377502, 978-7419377503

More Books

Students also viewed these Databases questions