Question: java program Western Canada has decided to form a navy consisting of Carriers (CV), Battleships (BB), and Destroyers (DD). The naming of the ships in

java program

Western Canada has decided to form a navy consisting of Carriers (CV), Battleships (BB), and Destroyers (DD). The naming of the ships in this new navy is to follow these rules.

  • All ship names are to begin with HMWC (Her Majestys Western Canadian).
  • Carrier Names start with HMWCCV and have a 3-digit value after them that is evenly divisible by 100 (i.e. HMWCCV100, HMWCCV200 are valid, HMWCCV150 is not).
  • Battleships names begin with HMWCBB and have a 2 digit value after them that is evenly divisible by 10 (i.e., HMWCBB10 and HMWCBB30 are valid, HMWCBB15 is not)
  • Destroyer names with begin with MHWCDD and have Single Letter in the range A to G (i.e. HMWCDDD, HMWCDDE are valid, HMWCDDM is not).

Complete the method stub in Q2 call isValidName to use a Regular expression to determine if the given name is a valid ship name by the rules described above.

this is what i have

package mid1;

public class Q2 { public static boolean isValidName(String sName) { //Replace the following with required implementation to fufill Q2 in the mid1 return false; }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!