top of page

Scrabble, RotateMatrix, Normalize - Java Project help

Java project work:

You are tasked to develop a Java program that matches the below specified tasks


Task 1:

In the game of Scrabble, each letter has points associated with it. The total score of a word is the sum of the scores of its letters. More common letters are worth fewer points while less common letters are worth more points.


The points associated with each letter are shown below:


Write a static function called "scrabble" that takes an array of strings" as input and computes and displays the Scrabble score for the words.


scrabble(new String[]{"HI", "BEN"}) should print out "HI BEN is worth 10 points." scrabble(new String[]{"JAVA"}) should print out "JAVA is worth 14 points."

Note: Assume that input strings are of capital letters (i.e., uppercase characters)


Task 2:

Write a static method rotate Matrix that accepts a two-dimensional (2D) integer array as square matrix NxN (i.e., N rows and N columns), and returns a 2D integer array as square matrix after rotating the input matrix by 90 degrees in clockwise direction.

Example 1:

If input 4x4 integer matrix is:

{{1, 2, 3, 4},

{5, 6, 7, 8},

{9, 10, 11, 12},

{13, 14, 15, 16}}

After rotation, rotate Matrix should return the following 2D integer array:

{{13, 9,5, 1},

{14, 10, 6, 2},

{15, 11, 7, 3},

{16, 12, 8, 4}}


Example 2:

If input 2x2 integer matrix is:

{{1, 2},

{5, 6}}

After rotation, rotateMatrix should return the following 2D integer array:

{{5, 1},

{6, 2}}


Note: NxN matrix is declared as "int array_name[N][N];". E.g., 4x4 matrix would be "int array_name[4][4];"


Task 3:

Write a static function called "normalize" that takes a two-dimensional (2D) array of integer elements and returns normalized 2D array of elements of type double. For normalizing, the method should divide each input element with its row average (i.e., mean).

If a row is {1, 2, 3} then mean is (1+2+3)/3 = 2.0, and the row in result array should be {1/2.0, 2/2.0, 3/2.0} i.e., {0.5, 1.0, 1.5).


Example:

Here is the full example of 2D array: normalize(new int[][]{{1,2,3}, {3,4,5}}) should return {{0.5, 1.0, 1.5}, {0.75, 1.0, 1.25}}. For the row {3,4,5}, mean is (3+4+5)/3 = 4.0, thus the values after normalizing would be {0.75, 1.0, 1.25}.


Task 4:

Write a java class called House with the following two private attributes, and three methods:


Attributes:

1) type (String)

2) height (int)


The valid values of attribute "type" are: "Cabin", "Bungalow", and "High Rise". A house can be upgraded to the next type. For example, a house of type "Cabin" can be upgraded to "Bungalow" which can be later upgraded to "High Rise". A house is never downgraded.


Method: 1)

constructor that takes accepts two input parameters to initialize the attributes if input parameters are valid. The constructor should "Throw IllegalArgumentException" with a reasonable message (Invalid House type or Invalid height) if input parameter for house type is invalid or input parameter for height is less than or equal to 0. The constructor should include try/catch blocks and the catch block should print the exception message and terminate program with "System.exit(1);"


Method: 2)

upgrade method that takes no input parameters. It doubles the height of a house of type Cabin or Bungalow, then revises the value of type to next value (i.e., Cabin to Bungalow, Bungalow to High Rise, and High Rise remains the same).


For example: upgrade() method will update a house of type "Cabin" with height 200 to next type "Bungalow" with height value of 400.


For example: upgrade() method will update a house of type "Bungalow" with height 400 to next type "High Rise" with height value of 800.


If the type of house is "High Rise", the upgrade() method should throw an IllegalArgumentException with message "High Rise house cannot be upgraded". The upgrade() method should include try/catch blocks, and the catch block should print the message and allow the program to continue executing.


Method: 3)

toString method which returns a string with first character of type and height.


For example:

tostring() should return a "C200" if the house is of "Cabin" with height 200.

tostring() should return a "B500" if the house is of "Bungalow" with height 500.

tostring() should return a "H1000" if the house is of "High Rise" with height 1000.


Task 5:

Create a class called Map that uses the class House which was developed in Task 4. The Map class should include the following two private attributes:


1) private static House [][] houses; // (as 2D array of houses of size MxN. Example: 8x7 array would be declared as House [8][7]. 3x4 array would be declared as House[3][4], etc. 2) private static final String FILE_NAME = "house.txt";


Write the following methods:

You must determine if they should be private/public and static/non-static:


Method: 1) loadHouses() method that takes no input. This method should initialize the houses attribute by putting the house data into the attribute. The data should be loaded from the text file which is given in the FILE_NAME attribute. The data format in the house.txt is described as follows:


house.txt file contents are as follows data lines:


Cabin:5, Cabin:1, Bungalow:9, High Rise:11

Cabin:2, Cabin:4, Bungalow:8, Bungalow:10

High Rise:13, Cabin:3, Bungalow:6, Bungalow:7

High Rise:15, High Rise:14, High Rise:12, High Rise:16


After calling loadHouses(), the houses are loaded in the 2D array, such that System.out.println(Arrays.deepToString(houses));

should print the following:

[[C5, C1, B9, H11], (C2, C4, B8, B10], [H13, C3, B6, B7], [H15, H14, H12, H16]]


Method: 2) A method upgrade Houses that takes two integers (first being row, and second being column) of houses. The entire row and column should be upgraded (each house by only once).

Example: Before calling upgrade Houses method if System.out.println(Arrays.deepToString(houses));

prints the following:

[[C5, C1, B9, H11], [C2, C4, B8, B10], [H13, C3, B6, B7], [H15, H14, H12, H16]] after calling upgrade Houses(1,2) method, the System.out.println(Arrays.deepToString(houses));

Should print the following:

[[C5, C1, H18, H11], [B4, B8, H16, H20], [H13, C3, H12, B7], [H15, H14, H12, H16]]


Method: 3) A main method with the following statements:


• call Map.loadHouses() method.

• print the houses array with: System.out.println(Arrays.deepToString(houses));


• call upgrade Houses(1, 2);

• print the houses array with: System.out.println(Arrays.deepToString(houses));


How does CodersArts help you in Java coding?

CodersArts provide :

  • Java assignment Help

  • Help in Java development Projects

  • Mentorship from Experts Live 1:1 session

  • Course and Project completions

  • CourseWork help




Comments


bottom of page