Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

INSTRUCTIONS: Create Part (version 0.3) and PartTest (version 0.2) as follows: I

ID: 3862348 • Letter: I

Question

INSTRUCTIONS:

Create Part (version 0.3) and PartTest (version 0.2) as follows:

In Part.java, override these two methods, both inherited from its superclass, Object

toString() - https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#toString() (Links to an external site.)

equals() - https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#equals(java.lang.Object) (Links to an external site.)

NOTE: Notice what happens when you add the @override annotation to your overridden method! Then read the javadoc for the equals() method of Object. We will discuss.

NOTE: Two Parts are equal if and only if they have the same:

number

ncage

niin

The method toString should print all of the part information on a single line in the order name, number, ncage, niin and each value should be labeled in the text output.
    One possible example:
    PART: Widget, purple, P/N: 12345, NCAGE: OU812, NIIN: 1234-12-123-1234

Also, in the full argument constructor in Part, place some comments to yourself reminding you to implement some sort of check on the input at a later time.

In PartTest, ensure that your tests for the equals method meets the following criteria

It is reflexive: for any non-null reference value x, x.equals(x) should return true.

It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.

It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.

It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.

For any non-null reference value x, x.equals(null) should return false.

THIS IS WHAT I HAVE SO FAR TO BEGIN WITH:

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;

   }

   /**

   * @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; }

}

################### PartTest.java ###############

public class PartTest {

   public static void main(String[] args) {

      

       // creating Part Object

       Part part1 = new Part("Pravesh Kumara");

      

       part1.setNumber("AX-34R");

       part1.setNcage("MN34R");

       part1.setNiin("ABCD-RF-WDE-KLJM");

      

       // printing information

       System.out.println("Name: "+part1.getName());

       System.out.println("Number: "+part1.getNumber());

       System.out.println("Ncage: "+part1.getNcage());

       System.out.println("Niin: "+part1.getNiin());

   }

}

Also, if possible, please fully javadoc everything.

Explanation / Answer


/**
* The java test class PartTest that tests the toString
* and equals methods and print the results to console.
* */
//PartTest.java
public class PartTest
{
   public static void main(String[] args)
   {
       // creating Part Object
       Part part1 = new Part("Pravesh Kumara");
       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 Part("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.");
      
      
   }

}//end of class PartTest

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


//Part.java
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 equls takes an Object type
   * and typecast the objt to part object
   * and returns true if number,ncatge 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; }

}

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

Sample Output:

Name : Pravesh Kumara , Number : AX-34R, NCAGE : MN34R, NIIN: ABCD-RF-WDE-KLJM
Name : Widget, purple , Number : 12345, NCAGE : OU812, NIIN: 1234-12-123-1234
part1 and part2 are not equal.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote