Question

Please comment the important lines in the .java file as shown in the template. The important lines including but not limited to i) variables, ii) for-loop, iii) while-loop, iv) if-else statement, iv) methods. Please use your own words to describe what is your purpose to write this line.

Panther ID - 002357394

Purpose: Instance variables belong to the instance of a class, i.e., an object. Every object of that class has its own copy o

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Java code for ablove problem

class Park
{
   public String ParkName;
   public int ParkID;
   public String ParkShape;
   private double ParkLength;
   Park(String ParkName,int ParkID,String ParkShape,double ParkLength)
   {
       this.ParkName=ParkName;
       this.ParkID=ParkID;
       this.ParkShape=ParkShape;
       this.ParkLength=ParkLength;
   }
   public String ParkNameGetter()
   {
       return this.ParkName;
   }
   public int ParkIDGetter()
   {
       return this.ParkID;
   }
   public double ParkLengthGetter()
   {
       return this.ParkLength;
   }
   public String toString()
   {
       return "Name: "+this.ParkName+"\nID: "+this.ParkID+"\nShape: "+this.ParkShape+"\nLength: "+this.ParkLength+"\n";
   }
}
class ParkClient
{
   public static void main(String args[])
   {
       Park [] ParkArray=new Park[5];
       ParkArray[0]=new Park("CSC1302",94,"Circle",5);
       ParkArray[1]=new Park("CSC1302",97,"Square",6);
       ParkArray[2]=new Park("CSC1303",100,"Circle",4);
       ParkArray[3]=new Park("CSC1304",103,"Circle",5);
       ParkArray[4]=new Park("CSC1304",106,"Square",9);
      
       for(int i=0;i<5;i++)
       {
           System.out.println("Information of Park-"+(i+1));
           System.out.println(ParkArray[i]);
       }
      
       double max_len=0;
       int max_len_index=-1;
       for(int i=0;i<5;i++)
       {
           if(max_len<ParkArray[i].ParkLengthGetter())
           {
               max_len=ParkArray[i].ParkLengthGetter();
               max_len_index=i;
           }
       }
      
       System.out.println("Information of Largest Park:");
       System.out.println(ParkArray[max_len_index]);
      
   }
}

Sample output

Information of Park-1 Name: CSC1302 ID: 94 Shape: Circle Length: 5.0 Information of Park-2 Name: CSC1302 ID: 97 Shape: Square

Mention in comments if any mistakes or errors are found. Thank you.

Add a comment
Know the answer?
Add Answer to:
Please comment the important lines in the .java file as shown in the template. The important...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • CompSci 251: Intermediate Computer Programming Spring 2017 -Java Lab 5 For this lab we will be...

    CompSci 251: Intermediate Computer Programming Spring 2017 -Java Lab 5 For this lab we will be looking at static, or class variables. Remember that where instances variables are associated with a particular instance, static variables are associated with the particular class. Specifically, if there are n instances of a class, there are n copies of an instance variable, but exactly one copy of a static variable (even when n = 0). Student - uniqueId : int - id: int -...

  • Write method createTeams() that Has no parameters Has return type void Instantiate the member variable of...

    Write method createTeams() that Has no parameters Has return type void Instantiate the member variable of type ArrayList<Team> Instantiates two instances of class Team one for TeamOne one for TeamTwo set names for each team as appropriate add each instance to the ArrayList<Team> member variable Instantiate the member variable of class Scanner passing “System.in” as the argument to the constructor Using System.out.println() static method, prompt the user for the human player’s name Instantiate an instance of class String set equal...

  • java

    You may not add any instance variables to any class, though you may create local variables inside of a method to accomplish its task. No other methods should be created other than the ones listed here.   Step 1Develop the following class:ClassName: CollegeDegreeAccess Modifier: publicInstance variablesName: majorAccess modifier: privateData type: StringName: numberOfCoursesAccess modifier: privateData type: intName: courseNameArrayAccess modifier: privateData type: String [ ]Name: courseCreditArrayAccess modifier: privateData type: int [ ]Static variablesName: maximumNumberOfCoursesAccess modifier: privateData type: intInitial Value: 40ConstructorName: CollegeDegreeAccess modifier: publicParameters: none...

  • Java Object Array With 2 Elements In 1 Object

    1. Create a UML diagram to help design the class described in Q2 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Person class object; should they be private or public? Determine what class methods are required; should they be private or public?2. Write Java code for a Person class. A Person has a name of type String and an age of type integer.Supply two constructors: one will be...

  • Programming assignment for Java: Do not add any other instance variables to any class, but you...

    Programming assignment for Java: Do not add any other instance variables to any class, but you can create local variables in a method to accomplish tasks. Do not create any methods other than the ones listed below. Step 1 Develop the following class: Class Name: College Degree Access Modifier: public Instance variables Name: major Access modifier: private Data type: String Name: numberOfCourses Access modifier: private Data type: int Name: courseNameArray Access modifier: private Data type: String Name: courseCreditArray Access modifier:...

  • Write java program The purpose of this assignment is to practice OOP with Array and Arraylist,...

    Write java program The purpose of this assignment is to practice OOP with Array and Arraylist, Class design, Interfaces and Polymorphism. Create a NetBeans project named HW3_Yourld. Develop classes for the required solutions. Important: Apply good programming practices Use meaningful variable and constant names. Provide comment describing your program purpose and major steps of your solution. Show your name, university id and section number as a comment at the start of each class. Submit to Moodle a compressed folder of...

  • JAVA QUESTION 16 Write and submit the java source for the following class specification: The name...

    JAVA QUESTION 16 Write and submit the java source for the following class specification: The name of the class is Question_16 Class Question_16 has 3 instance variables: name of type String, age of type int and height of type double. Class Question_16 has the following methods: print - outputs the data values stored in the instance variables with the appropriate label setName - method to set the name setAge - method to set the age setHeight - method to set...

  • JAVA :The following are descriptions of classes that you will create. Think of these as service...

    JAVA :The following are descriptions of classes that you will create. Think of these as service providers. They provide a service to who ever want to use them. You will also write a TestClass with a main() method that fully exercises the classes that you create. To exercise a class, make some instances of the class, and call the methods of the class using these objects. Paste in the output from the test program that demonstrates your classes’ functionality. Testing...

  • This is a java file and I am very confused on how to do this project!...

    This is a java file and I am very confused on how to do this project! please help!! Specifications Overview: You will write a program this week that is composed of three classes: the first class defines Ellipsoid objects, the second class defines EllipsoidList objects, and the third, Ellipsoid ListApp, reads in a file name entered by the user then reads the list name and Ellipsoid data from the file, creates Ellipsoid objects and stores them in an ArrayList of...

  • Java Eclipse Coding question: Use data abstraction (real-world modeling) to come up with 3 instance variables...

    Java Eclipse Coding question: Use data abstraction (real-world modeling) to come up with 3 instance variables and 2 effectors for a new data type – the class HospitalPatient. You have the freedom to design the instance variables and effectors. instance variables effectors 1. 1. 2. 2. 3. Write the code for class HospitalPatient, according to the requirement above. Include the default constructors with no argument, and the constructor with all arguments. Provide a getter and setter for each individual instance...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT