Question: Language is Java, any help is appreciated. Thank you! WHERE TO START FROM: import java.util.ArrayList; //PartTest.java //package simple; public class PartTest { public static void

Language is Java, any help is appreciated. Thank you!

WHERE TO START FROM:

import java.util.ArrayList;

//PartTest.java //package simple; public class PartTest { public static void main(String[] args) { ArrayList system=new ArrayList(); // creating Part Object Part part1 = new ExpendablePart("Last, First"); part1.setNumber("AX-34R"); part1.setNcage("MN34R"); part1.setNiin("ABCD-RF-WDE-KLJM"); // printing information System.out.println(part1.toString()); //Create a part2 object of class Part Part part2=new ConsumablePart("Widget, purple"); part2.setNumber("12345"); part2.setNcage("OU812"); part2.setNiin("1234-12-123-1234"); // printing information System.out.println(part2.toString()); //checking equality of two Part class objects if(part1.equals(part2)) System.out.println("part1 and part2 are equal."); else System.out.println("part1 and part2 are not equal."); //testing expendable part ExpendablePart expPart = new ExpendablePart(); expPart.setFailureRate(3); expPart.setLeadTime(20);

//testing consumable part ConsumablePart conPart = new ConsumablePart(); conPart.setReplacementCost(23); conPart.setUsesLeft(6);

//adding to expPart and calling fail method expPart.addTool(conPart); expPart.fail();

} }//end of class PartTest

--------------------------------------------------

import java.util.ArrayList;

//ExpendablePart.java //package simple; public class ExpendablePart extends Part{ private int failureRate; //holds the average number of failures per operational hour of the part private int leadTime; //holds the number of days it takes to replace the part in the supply system private ArrayList toolsRequired=new ArrayList(); public ExpendablePart() { } public ExpendablePart(String string) { // TODO Auto-generated constructor stub super(string); } public void addTool(ConsumablePart c) { toolsRequired.add(c); } /** * * @return failure rate */ public int getFailureRate() { return failureRate; } /** * * @param failureRate */ public void setFailureRate(int failureRate) { this.failureRate = failureRate; } /** * * @return lead time */ public int getLeadTime() { return leadTime; } /** * * @param leadTime */ public void setLeadTime(int leadTime) { this.leadTime = leadTime; } /** * Prints the failure reason and time to replace the part */ @Override public void fail() { for(ConsumablePart c:toolsRequired) { c.fail(); } }}

--------------------------------------------

//ConsumablePart.java

public class ConsumablePart extends Part{ private double replacementCost; private int usesLeft; private static final int USES=10; public ConsumablePart() { // TODO Auto-generated constructor stub } public ConsumablePart(String string) { // TODO Auto-generated constructor stub super(string); } /** * * @return replacement cost */ public double getReplacementCost() { return replacementCost; } /** * sets the replacement cost * @param replacementCost */ public void setReplacementCost(double replacementCost) { this.replacementCost = replacementCost; } /** * * @return uses left */ public int getUsesLeft() { return usesLeft; } /** * sets the uses left * @param usesLeft */ public void setUsesLeft(int usesLeft) { this.usesLeft = usesLeft; } /** * Prints the failure reason and time to replace the part */ @Override public void fail() { usesLeft--; if(usesLeft!=0) { System.out.println(" consumable part "+getName()+" has been used and now has "+usesLeft+" uses left");

} else { System.out.println(String.format(" consumable part %s has been used up and will cost %.2f",getName(),replacementCost));

usesLeft=USES; } } }

--------------------------------------------

//Part.java

package simple;

public class Part

{

private String name;

private String number; // this is sequence of alphanumeric

private String ncage; // this is also 5 character sequence

private String niin; // 13 character code

/**

* Default constructor

*/

public Part()

{

this("", "", "", ""); // calling full argument constructor

}

/**

* @param name

*/

public Part(String name)

{

this(name, "", "", ""); // calling full argument constructor

}

/**

* @param name

* @param number

* @param ncage

* @param niin

*/

public Part(String name, String number, String ncage, String niin)

{

this.name = name;

this.number = number;

this.ncage = ncage;

this.niin = niin;

}

/**

* The method toString that returns the string

* representation of the instance variables of the part

* object as string .

* */

public String toString()

{

return String.format("Name : %s , Number : %s, NCAGE : %s, NIIN: %s", name,number,ncage,niin);

}

/**

* The method equals takes an Object type

* and typecast the object to part object

* and returns true if number,ncage and niin

* are equal .otherwise returns false.

* */

public boolean equals(Object obj)

{

Part other=(Part)obj;

return number.equals(other.getName())

&& ncage.equals(other.getNcage())

&&niin.equals(other.getNiin());

}

/**

* @param name

*/

public void setName(String name) { this.name = name; }

/**

* @return name

*/

public String getName() { return name; }

/**

* @param number

*/

public void setNumber(String number) { this.number = number; }

/**

* @return number

*/

public String getNumber() { return number; }

/**

* @param ncage

*/

public void setNcage(String ncage) { this.ncage = ncage; }

/**

* @return ncage

*/

public String getNcage() { return ncage; }

/**

* @param niin

*/

public void setNiin(String niin) { this.niin = niin; }

/**

* @return niin

*/

public String getNiin() { return niin; }

/**

* prints a generic failure message

*/

//This will be an abstract method later

public void fail()

{

System.out.println("Something went wrong!");

}

}

/**

* The java test class PartTest that tests the toString

* and equals methods and print the results to console.

* */

INSTRUCTIONS:

Make changes as follows:

Add a regular expression-based check to ensure that the input to setNIIN() and the full argument constructors for all Parts (which is every Class in the project) is correct.

Remember, a NIIN must be of the form NNNN-NN-NNN-NNNN, where each N is a digit ( e.g. a 0,1,2,3,4,5,6,7,8, or 9)

Add a regular expression-based check to ensure that the input to setNcage() and the full argument constructors for all Parts (which is every Class in the project) is correct.

Remember, a NCAGE must be of the form NNNNN, where each N is a number or capital letter

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!