Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Tmpj3 01 201181102muhammad_tohir

148 views

Published on

Published in: Education
  • Be the first to comment

  • Be the first to like this

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()); } }

×