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

Java please, in netBean 8.2 1. Create a file with inputs (diameters of planets)

ID: 3858598 • Letter: J

Question

Java please, in netBean 8.2

1. Create a file with inputs (diameters of planets) (name: planets.data):
4866
12106
12742
6760
139516
116438
46940
45432
2274
2. Google "java read file by line", cut/paste correct code, verify it works.
3. Google "Liang CircleWithPrivateDataFields", get java class, put in its own file, verify it works.
4. Google "Liang TestCircleWithPrivateDataFields", get java class, rename to L-18, verify it works.
5. Edit the L-18 java file, create an ArrayList of CircleWithPrivateDataFields,
6. Create method to read file above into Circles and place Circle into ArrayList.
7. Create toString method in Circle class, print all info on a Circle.
8. Create method to print entire ArrayList, accessing the toString method.
9. Create method to sum all diameters of all circles in the ArrayList.
10. Indentation and comment block.

Explanation / Answer

Note: As per the chegg rules we are not supposed to copy and paste code available in google.Its strictly restricted.But as ur requirement to take the code from the google.I took the CircleWithPrivateDataFields.java from google..If you required any changes Just intimate.I will modify it.Thank You.

____________________

planets.data (Save this file under D Drive.Then the path of the file pointing to it is D:\planets.data)

4866
12106
12742
6760
139516
116438
46940
45432
2274

CircleWithPrivateDataFields.java

public class CircleWithPrivateDataFields {

/** The radius of the circle */

private double radius = 1;

/** The number of the objects created */

private static int numberOfObjects = 0;

/** Construct a circle with radius 1 */

public CircleWithPrivateDataFields() {

numberOfObjects++;

}

/** Construct a circle with a specified radius */

public CircleWithPrivateDataFields(double newRadius) {

radius = newRadius;

numberOfObjects++;

}

/** Return radius */

public double getRadius() {

return radius;

}

/** Set a new radius */

public void setRadius(double newRadius) {

radius = (newRadius >= 0) ? newRadius : 0;

}

/** Return numberOfObjects */

public static int getNumberOfObjects() {

return numberOfObjects;

}

/** Return the area of this circle */

public double getArea() {

return radius * radius * Math.PI;

}

@Override

public String toString() {

return "CircleWithPrivateDataFields [radius=" + radius + "]";

}

}

_________________

L18.java

import java.io.File;

import java.io.FileNotFoundException;

import java.util.ArrayList;

import java.util.Scanner;

public class L18 {

/**

* Main method

*

* @throws FileNotFoundException

*/

public static void main(String[] args) throws FileNotFoundException {

//Declaring variable

int totDiameter = 0;

//Creating An arrayList which holds CircleWithPrivateDatFields class objects

ArrayList<CircleWithPrivateDataFields> myCircle = new ArrayList<CircleWithPrivateDataFields>();

//Creating a Scanner class object which opens and reads the file

Scanner sc = new Scanner(new File("D:\planets.data"));

while (sc.hasNext()) {

//Calling the method which reads the data from the file

CircleWithPrivateDataFields cwpdf = readFile(sc);

//Populate each Object into ArrayList

myCircle.add(cwpdf);

}

//Closing the Scanner class

sc.close();

System.out.println("The number of objects created is "

+ CircleWithPrivateDataFields.getNumberOfObjects());

//Calling the methods

printEntireArrayList(myCircle);

totDiameter=sumAllDiameters(myCircle);

//Displaying the total Diameter

System.out.println("Total Diameter of all the Circles is :"+totDiameter);

}

//Method which calculates the total diameter of all the circles

private static int sumAllDiameters(

ArrayList<CircleWithPrivateDataFields> myCircle) {

int totDiameter=0;

for(int i=0;i<myCircle.size();i++)

{

totDiameter+=myCircle.get(i).getRadius()*2;

}

return totDiameter;

}

//Method which display each Circle class info

private static void printEntireArrayList(

ArrayList<CircleWithPrivateDataFields> myCircle) {

for (int i = 0; i < myCircle.size(); i++) {

myCircle.get(i).toString();

}

}

//Method which reads data from the File

private static CircleWithPrivateDataFields readFile(Scanner sc) {

CircleWithPrivateDataFields cwpdf = new CircleWithPrivateDataFields();

cwpdf.setRadius(sc.nextInt() / 2);

return cwpdf;

}

}

_______________________

Output:

The number of objects created is 9
Total Diameter of all the Circles is :387074


_____________Could you rate me well.Plz .Thank You

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