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

Using Eclipse, create a class Product which has a String field called company th

ID: 3535489 • Letter: U

Question

Using Eclipse, create a class Product which has a String field called company that refers to the constant string "Tech Industries". It also has a String field name that refers to the product name, as well as an int field serNo containing the serial number of the product. The constructor takes one parameter, being the name of the product, and initializes that field. It also initializes the serNo field in the following way: The serial numbers start with 1001, and each next product generated gets a serial number that is one larger than the previous product. The constructor will therefore need to remember what the next serial number has to be. The class also contains a void method toString with no parameter that returns a String that contains the company name, the product name, and the product serial number, along with appropriate labels. Then create a Tester method with the regular main method that starts up the program. It should create an array Product[ ] that is initialized with three Product objects. Then print out the objects in the array using a loop.

Explanation / Answer

public class Global { public static int serNoTemp=1; } class Product{ private String company = "Tech Industries"; private productname; int serNo; void Product(String pName){ productname = pName; serNo = Global.serNoTemp; Global.serNoTemp+=1; } void toString(){ System.out.println("Company Name: "+this.company+" Product Name: "+this.productname+" Serial No: "+this.serNo): } } class Tester{ public static void main(){ Product testProduct = Product("testProductName"); testProduct.toString(); } }

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