Write a program using class and object and show the function of a game character name Rock
We are writing a program to know how app and game are coded in java. I am making a function like walking, Firing, Punching, Bombing and calculate a total number of people kill by Rock.
package com.ritesh;
import java.sql.SQLOutput;
import java.util.Scanner;
class Rock
{
public void walk()//the method is not returning any things so their is void
{
System.out.println("Rock is walking");
}
public void fire()//the method is not returning any things so their is void
{
System.out.println("Rock is firing the akm towards the enemy");
}
public void punch()//the method is not returning any things so their is void
{
System.out.println("Rock is punching to enemy");
}
public void bomb()
{
System.out.println("Enter the password to open the box");
Scanner sc=new Scanner(System.in);
int num1=sc.nextInt();
if(num1==1234)
{
System.out.println("lock open password matched");
System.out.println("Enter the countdown to blast a bomb");
int num2= sc.nextInt();
int i=num2;
while(i>=0)
{
System.out.println("The bomb is blasting is "+ i);
i--;
}
System.out.println();
System.out.println("Finally the bomb is blasted");
}
else
System.out.println("Wrong password please try again");
}
public int calculate(int a,int b)//the method is returning somethings things so their is int
{
Scanner sc=new Scanner(System.in);
System.out.println();
System.out.println("Rock you are a superhuman");
System.out.println("You kill the enemy from two places");
System.out.println("Gauradaha and Juropani");
System.out.println("so we want to know that how many people do you kill in war");
System.out.println("Enter the number of people you kill in Gauradaha");
a= sc.nextInt();
System.out.println("Enter the number of people you kill in Juropani");
b= sc.nextInt();
return a+b;
}
}
public class Main {
public static void main(String[] args) {
Rock gm = new Rock();
System.out.println("Enter the code for mission");
Scanner sc3=new Scanner(System.in);
int num4= sc3.nextInt();
if(num4==1234) {
System.out.println("password match");
System.out.println("be Ready for the mission");
System.out.println();
gm.walk();//calling the walk method
gm.fire();//calling the fire method
gm.punch();//calling the punch method
gm.bomb(); //calling the bomb method
int f = 0;
int g = 0;
System.out.println("The total number of enemy you kill in war is " + gm.calculate(f, g));
}
else
System.out.println("Incorrect password Please try again");
}
}
Comments
Post a Comment