This is a Java question, I really appreciate any help. Part 1: A Part is an obje
ID: 3821229 • Letter: T
Question
This is a Java question, I really appreciate any help.
Part 1:
A Part is an object that has four values associated with it:
name - A textual name
number - an alphanumeric sequence that may contain hyphens
ncage - A five character alphanumeric code for a business of the form NNNNN
niin - a 13 digit code of the form XXXX-XX-XXX-XXXX
Create the class and its members, accessors, and mutators.
Save it in a class called Part.java.
Part 2:
Take your base Part class from the last version, and add the following
Create overloaded constructors for Parts, using the this() call to the full argument constructor for any constructor that has fewer than four arguments.
Then create a PartTest program that does basic testing on the Part object. Call constructors, print out members with accessors. The tests don't have to be fully exhaustive, but it should at least give a reasonable sense of the Part object.
Bonus help:
Also, add full Javadoc documentation, if possible, please. Thanks.
This is what I have so far for Part 1, I would really appreciate any help that you could provide on part 2:
public class Part
{
private String name;
private int number;
private int ncage;
private int niin;
public Part()
{
name = null;
number = 0;
ncage = 0;
niin = 0;
}
public Part(String name, int number, int ncage, int niin)
{
this.name = name;
this.number = number;
this.ncage = ncage;
this.niin = niin;
}
public void setName(String name) { this.name = name; }
public String getName() { return name; }
public void setNumber(int number) { this.number = number; }
public int getNumber() { return number; }
public void setNcage(int ncage) { this.ncage = ncage; }
public int getNcage() { return ncage; }
public void setNiin(int niin) { this.niin = niin; }
public int getNiin() { return niin; }
}
Explanation / Answer
HI, Please find my implementation.
Please let me know in case of any issue.
############# 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;
}
/**
* @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());
}
}
/*
Sample run:
Name: Pravesh Kumara
Number: AX-34R
Ncage: MN34R
Niin: ABCD-RF-WDE-KLJM
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.