In: Computer Science
Each apple has a unique ID . In the format of AppleID.
Where D is the serial number, starting from 1.
That is the first apple object gets Apple 1 and the second Apple 2
public class Apple{
String AppleID;
// create an apple with appleD of form apple-XX
public Apple(){
}
}
Add fields if you think you need one. Write none if you dont
Complete the constructor so that the 1st apple gets Apple ID apple-1, the second apple gets apple-2.
HI,
Created a complete program where you can create number of apples id and form by class constructor.
Run below program and you will get 5 form of apples.
public class Apple{
private String AppleID; //Apple id
private String AppleType; // representing apples varieties
// create an apple with appleD of form apple-XX
//apple contructor
public Apple(String id, String type){
this.AppleID = id;
this.AppleType = type;
}
// to string method to print apple id and apple name
public String toString() {
return AppleID+" "+AppleType+"\n";
}
//driver method
public static void main(String[] args)
{
Apple apple1 = new Apple("apple-1", "Ambri Apple"); // create a apple form based on apple id by class contructor
Apple apple2 = new Apple("apple-2", "McIntosh apple");
Apple apple3 = new Apple("apple-3", "Granny Smith");
Apple apple4 = new Apple("apple-4", "Golden Delicious");
Apple apple5 = new Apple("apple-5", "Honeycrisp");
System.out.println("\n");
System.out.println("AppleID Apple form\n");
System.out.println(apple1);// displaying output
System.out.println(apple2);
System.out.println(apple3);
System.out.println(apple4);
System.out.println(apple5);
}
}
Thanks