Advertisement
fiqriachmada

Hero.Java

Sep 19th, 2019
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Hero {
  4.     static class hero{
  5.         int hp, damage;
  6.  
  7.         //inputan
  8.         public hero(){
  9.             Scanner input=new Scanner(System.in);
  10.             System.out.print("Masukkan Nilai HP hero = ");
  11.             int a=input.nextInt();
  12.             System.out.print("Masukkan Nilai Damage hero = ");
  13.             int b=input.nextInt();
  14.             this.hp=a;
  15.             this.damage=b;
  16.         }
  17.         //cetak
  18.         void cetak(){
  19.             System.out.println("HP adalah "+hp);
  20.             System.out.println("Damage adalah "+damage);
  21.         }
  22.         void up_level(){
  23.             hp=hp+10;
  24.             damage=damage+10;
  25.             System.out.println("HP adalah "+hp);
  26.             System.out.println("Damage adalah "+damage);
  27.         }
  28.     }
  29.     public static void main(String[] args){
  30.  
  31.         System.out.println("Lesley");
  32.         hero lesley=new hero();
  33.         lesley.cetak();
  34.         lesley.up_level();
  35.  
  36.         System.out.println("*========*");
  37.  
  38.         System.out.println("Gatot");
  39.         hero gatot=new hero();
  40.         gatot.cetak();
  41.         gatot.up_level();
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement