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
//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
--------------------------------------------
//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
Get step-by-step solutions from verified subject matter experts
