Northern Kentucky University Object Oriented Programming Engineering Task

User Generated

fnen1999

Engineering

Northern Kentucky University

Description

more information it's will help you also in homework

public class BishopMoves {
	public static int numBishopMoves(String square) {
		square.toUpperCase();
		
		// Convert from uppercase letter to integer representation of column 
		// number
		int col = square.charAt(0) - 64;
		// Convert from character to integer representation of row number
		int row = square.charAt(1) - 48;
		
		int numMoves = 0;
		for (int newCol = 1; newCol < 8; newCol++) {
			int offset = newCol - col;
			
			int newRowAbove = row + offset;
			if (newRowAbove >= 1 && newRowAbove <= 8) {
				numMoves++;
				System.out.println((char) (newCol+64) 
						+ (char) (newRowAbove+48));
			}
			
			int newRowBelow = row - offset;
			if (newRowBelow >= 1 && newRowBelow <= 8) {
				numMoves++;
				System.out.println((char) (newCol+64) 
						+ (char) (newRowBelow+48));
			}
		}
		
		return numMoves;
	}
}

Unformatted Attachment Preview

A chess board consists of an 8x8 grid, where each square is identified by a letter and number denoting the column and row, respectively. For example, 04 denotes the square located on the 3rd column from the left and the 4 row from the bottom. A bishop can move along the chess board only in a diagonal fashion, as illustrated in the figure below. Any white square along any of the arrows constitutes a valid move. a b c d e f g h 7 6 5 5 4 3 N 2 1 a b c d e f g h The method numBishopMoves in the class BishopMoves (sce attached file BishopMoves.java) attempts to count the number of valid squares the bishop may move to, given the current position of the bishop as a string, such as "c4" or "C4" (letter can be either lowercase or uppercase). Additionally, it attempts to print to the console the letter and number denoting cach valid square, such as D. Unfortunately, the method contains several mistakes and does not perform its intended purpose. Correct the method by changing as few lines of code as possible (it should be possible to correct it by changing only 5 lines). A portion of your grade will be based on how many lines you changed! Your corrected method should not output any squares more than once. No duplicate squares should be counted either in the return value for your method. Submit your source code in a file named BishopMoves Correct.java! Do not include a main() method in your submission! (Either place the main() method in another class, which you don't submit, or delete it from the class BishopMoves). A chess board consists of an 8x8 grid, where each square is identified by a letter and number denoting the column and row, respectively. For example, c4 denotes the square located on the 3rd column from the left and the 4th row from the bottom. A bishop can move along the chess board only in a diagonal fashion, as illustrated in the figure below. Any white square along any of the arrows constitutes a valid move. 8 7 6 5 3 2 1 a b c d e f g h 10 a b c d e f g h The method numBishopMoves in the class BishopMoves (see attached file BishopMoves.java) attempts to count the number of valid squares the bishop may move to, given the current position of the bishop as a string, such as "c4" or "C4" (letter can be either lowercase or uppercase). Additionally, it attempts to print to the console the letter and number denoting each valid square, such as D5. Unfortunately, the method contains several mistakes and does not perform its intended purpose. Correct the method by changing as few lines of code as possible (it should be possible to correct it by changing only 5 lines). A portion of your grade will be based on how many lines you changed! Your corrected method should not output any squares more than once. No duplicate squares should be counted either in the return value for your method. Your corrected method should output squares in the format "D5" with letter in uppercase! Submit your source code in a file named BishopMoves Correct.java! Do not include a main () method in your submission! (Either place the main() method in another class, which you don't submit, or delete it from the class BishopMoves).37 38 39 10 //int s = obj.sum (num1, num2); c4 cannot be resolved to a variablember of move } "131 32 Illegal modifier for the method main; only public, protected, private, abstract, static, final, synchronized, native & strictfp are 33 permitted i m m m m m 34 35 36 27 //System.out.println("sum of 10 and 20: " + obj.sum (10,20)); //int num1 = 25, num2 = 10; //int ohi um/num1 num31.1 public class BishopMoves Correct{ 20 GUAWNH 3 4 public static int numBishopMoves (String square). { square.toUpperCase(); // Convert from uppercase letter to integer representation of column // number31 32Ⓒ 33 34 35 36 37 38 39 40 41 } 42 } } public static void main(String[] args) { //Test obj. = new Test(); //System.out.println("sum of 10 and 20: + obj.sum (10,20)); //int num1 = 25, num2 = 10; //int s = obj.sum (num1, num2); System.out.println("number of move " + numBishopMoves (c4));The selection cannot be launched, and there are no recent launches.
Purchase answer to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

there are 2 program with 2 name. remember to send the BishopMovesCorrectJava, as the instruction said, delete the main method i...


Anonymous
Goes above and beyond expectations!

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Related Tags