Menu
Question Index
...

In chess, assuming that the columns are numbered A to H and the rows are numbered 1 to 8. Write a program to find whether a camel can kill a pawn. Assume that there is nothing else on the chess board.

Input (Position, Position) Output (Boolean)
Camel = C2 and pawn = B3 true
Camel = D4 and pawn = B3 false
Camel = F8 and pawn = F7 false
Camel = H1 and pawn = B7 true


import java.util.*;
class CamelCanKillPawn
{
    public static void main(String s[])
    {
        ChessPosition camel = new ChessPosition('C', 2);
        ChessPosition pawn = new ChessPosition('B', 3);
        System.out.println("Can camel kill pawn: " + canKillPawn(camel, pawn));

    }


    public static boolean canKillPawn(ChessPosition camel, ChessPosition pawn) {
    }

}
class ChessPosition {

char column;
int row;

public ChessPosition(char column, int row) {
this.column = column;
this.row = row;
}

@Override
public String toString() {
return column + "" + row;
}
}

Doubts

Problems

Topic: Behavior Of Java Classes Using Methods

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App