This is my first Java program. I am teaching myself Java, and I have a pretty good book I am using, but I am getting 5 compile errors, even though I am doing this by the book. Here is the code:
Code:import javax.swing.JOptionPane; // Create "Circle" class public class Circle { // Create default constructor that sets value of radius to 1 public DefaultRadius() { defultRadius = 1; } // Create main method public static void main(String[] args) { // Declare variables Radius defaultRadius = new DefaultRadius(); double radius = setRadius(); // Output total to dialog box JOptionPane.showMessageDialog(null, "A circle with a radius of " + newRadius + " has a diameter of " + diameter + " and an area of " + area); System.exit(0); } // Create method to set the value of the radius pubic static void setRadius() { // Declare variables double radiusString, radius; // Assign values to variables radiusString = JOptionPane.showInputDialog(null, "Enter the value of the radius of the circle.", "Enter Radius", JOptionPane.INFORMATION_MESSAGE); // Convert inputs to integers and assign values to variables radius =Double.parseDouble(radiusString); System.exit(0); } // Create method to return the value of the radius pubic static double returnRadius(double radius) { double newRadius; newRadius = radius; return newRadius; } // Create method to compute and return the circle's diameter pubic static double computeDiameter(double newRadius) { double diameter; diameter = newRadius * 2; return diameter; } // Create method to compute and return the circle's area pubic static double computeDiameter(double newRadius) { double area; area = (newRadius * newRadius) *3.14; return area; } }
Here are the errors:
invalid method declaration; return type required
public DefaultRadius()
^
<identifier> expected
pubic static void setRadius()
^
<identifier> expected
pubic static double returnRadius(double radius)
^
<identifier> expected
pubic static double computeDiameter(double newRadius)
^
<identifier> expected
pubic static double computeDiameter(double newRadius)
^




Reply With Quote