Computer Science, asked by pleasantcookies, 7 months ago

Write a program that creates a class Account that stores a variable balance(double data type). The class has the following methods: a. void startAccount(double amt) b. void deposit(double amt) c. double withdraw(double amt) d. double getBalance() Invoke these functions from main().

Answers

Answered by Anonymous
0

Answer:

We now declare an Account class that maintains the balance of a bank account in addition to the name. Most account balances are not integers. So, class Account represents the account balance as a floating-point number—a number with a decimal point, such as 43.95, 0.0, -129.8873. [In Chapter 8, we’ll begin representing monetary amounts precisely with class BigDecimal as you should do when writing industrial-strength monetary applications.]

Java provides two primitive types for storing floating-point numbers in memory—float and double. Variables of type float represent single-precision floating-point numbers and can hold up to seven significant digits. Variables of type double represent double-precision floating-point numbers. These require twice as much memory as float variables and can hold up to 15 significant digits—about double the precision of float variables.

Most programmers represent floating-point numbers with type double. In fact, Java treats all floating-point numbers you type in a program’s source code (such as 7.33 and 0.0975) as double values by default. Such values in the source code are known as floating-point literals. See Appendix D, Primitive Types, for the precise ranges of values for floats and doubles.

Similar questions