Question
Why can't I compiled this Java program in Jgrasp? import java.util.*; public class TotalArea { /** Main method */ public static void main(String[] args) {
Why can't I compiled this Java program in Jgrasp?
import java.util.*; public class TotalArea { /** Main method */ public static void main(String[] args) { // Declare circleArray CircleWithPrivateDataFields[] circleArray; // Create circleArray circleArray = createCircleArray(); // Print circleArray and total areas of the circles printCircleArray(circleArray); }
/** Create an array of Circle objects */
public static CircleWithPrivateDataFields[] createCircleArray() { CircleWithPrivateDataFields[] circleArray = new CircleWithPrivateDataFields[5]; for (int i = 0; i < circleArray.length; i++) { circleArray[i] = new CircleWithPrivateDataFields(Math.random() * 100); } // Return Circle array return circleArray; }
/** Print an array of circles and their total area */ public static void printCircleArray(CircleWithPrivateDataFields[] circleArray) { System.out.printf("%-30s%-15s ", "Radius", "Area"); for (int i = 0; i < circleArray.length; i++) { System.out.printf("%-30f%-15f ", circleArray[i].getRadius(), circleArray[i].getArea()); } System.out.println("-"); // Compute and display the result System.out.printf("%-30s%-15f ", "The total area of circles is", sum(circleArray) ); }
/** Add circle areas */ public static double sum(CircleWithPrivateDataFields[] circleArray) { // Initialize sum double sum = 0; // Add areas to sum for (int i = 0; i < circleArray.length; i++) sum += circleArray[i].getArea(); return sum; } }
The error is:
----jGRASP exec: javac -g TotalArea.java
TotalArea.java:25: error: cannot find symbol public static CircleWithPrivateDataFields[] createCircleArray() ^ symbol: class CircleWithPrivateDataFields location: class TotalArea TotalArea.java:40: error: cannot find symbol public static void printCircleArray(CircleWithPrivateDataFields[] circleArray) ^ symbol: class CircleWithPrivateDataFields location: class TotalArea TotalArea.java:57: error: cannot find symbol public static double sum(CircleWithPrivateDataFields[] circleArray) ^ symbol: class CircleWithPrivateDataFields location: class TotalArea TotalArea.java:14: error: cannot find symbol CircleWithPrivateDataFields[] circleArray; ^ symbol: class CircleWithPrivateDataFields location: class TotalArea TotalArea.java:27: error: cannot find symbol CircleWithPrivateDataFields[] circleArray = ^ symbol: class CircleWithPrivateDataFields location: class TotalArea TotalArea.java:28: error: cannot find symbol new CircleWithPrivateDataFields[5]; ^ symbol: class CircleWithPrivateDataFields location: class TotalArea TotalArea.java:32: error: cannot find symbol circleArray[i] = new CircleWithPrivateDataFields(Math.random() * 100); ^ symbol: class CircleWithPrivateDataFields location: class TotalArea 7 errors
----jGRASP wedge2: exit code for process is 1. ----jGRASP: operation complete.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started