Tmpj3 01 201181102muhammad_tohir

106 views
63 views

Published on

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
106
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Tmpj3 01 201181102muhammad_tohir

  1. 1. Nama : Muhammad Tohir Nim : 201181102 Seksi :01 Tugas 03 Account import java.util.Scanner; public class Account { public double Balance; public Account(double initialBalance) { if (initialBalance > 0.0) Balance = initialBalance; Scanner input = new Scanner(System.in); } public void credit (double Amount) { Balance = Balance + Amount; } public double getBalance() { return Balance; } }
  2. 2. Accounttest import java.util.Scanner; public class accounttest { public static void main (String[]args) { Account account1 = new Account(50.00); Account account2 = new Account(-7.53); System.out.printf("Account1 balance :$%.2fnn",account1.getBalance()); System.out.printf("Account2 balance :$%.2fnn",account2.getBalance()); Scanner input = new Scanner(System.in); double depositAmount; System.out.print("Enter deposit amount for account1:" ); depositAmount = input.nextDouble(); System.out.printf("nadding %.2f to account1 blance nn",depositAmount); account1.credit(depositAmount); System.out.printf("account1 blance : $%.2fn",account1.getBalance()); System.out.printf("account2 blance : $%.2fn",account2.getBalance()); System.out.printf("Enter deposit account for account2: "); depositAmount =input.nextDouble();
  3. 3. System.out.printf("nadding %.2f to account2 balancenn", depositAmount); account2.credit(depositAmount); System.out.printf("account1 balance: $%.2fn",account1.getBalance()); System.out.printf("account2 balance : $%.2fn",aaccount2.getBalance()); } }

×