Java Problems (Really Need Help!)

  • Thread starter jacobfreakingharris
  • Start date

J

jacobfreakingharris

I keep getting errors in java and I don't know what to do. Everything looks fine. Could someone please help? Here's the applet I'm working on and below it are the error messages.
/**
* File: PetRockApplet.java
* Author: Jacob Harris (regular bonus, trying for honors, and
1 honors bonus)
* Programming: 1st Hour
* Last Modified: January 26, 2014
* Description: This applet creates, draws, finds the area, flips, and
* changes the color of pet rocks (oval & 2 rectangles
* with names).
*/


import java.awt.*; // get the java "standard graphic" classes
import java.applet.Applet; // get the java "standard applet" classes
import java.awt.event.*; // get the java "standard event" classes

public class PetRockApplet extends Applet implements ActionListener
{
private int majorAxis; // length of oval rock
private int minorAxis; // width of oval rock
private int length1; // length of rectangular rock 1
private int width1; // width of rectangular rock 1
private int length2; // length of rectangular rock 2
private int width2; // width of rectangular rock 2
private String name1; // name of rock 1
private String name2; // name of rock 2
private String name3; // name of rock 3
private Button flipButton1; // declare flipButton1 (don't fill)
private Button flipButton2; // declare flipButton2 (don't fill)
private Button flipButton3; // declare flipButton3 (don't fill)
private Button colorButton1; // declare colorButton1 (don't fill)
private Button colorButton2; // declare colorButton2 (don't fill)
private Button colorButton3; // declare colorButton3 (don't fill)
private Color color1; // declare color 1 (red)
private Color color2; // declare color 2 (blue)
private Color color3; // declare color 3 (green)
private Color color4; // declare color 4 (yellow)
private Color color5; // declare color 5 (pink)
private Color color6; // declare color 6 (black)

/**
* The init() method initializes/starts/creates the rocks
*/
public void init()
{
// declare an empty PetRockApplet class called "myPetRock1"
PetRockApplet myPetRock1;

// make (instantiate) the new PetRock1
myPetRock1 = new petRockApplet1();

flipButton1 = new Button("Flip"); // make flipButton1
add(flipButton1); // draw flipButton1
flipButton1.addActionListener(this); // listen for mouse
colorButton1 = new Button("Change Color"); // make colorButton1
add(colorButton1); // draw colorButton1
colorButton1.addActionListener(this); // listen for mouse

// declare an empty PetRockApplet class called "myPetRock2"
PetRockApplet myPetRock2;

// make (instantiate) the new PetRock2
myPetRock2 = new petRockApplet2();

flipButton2 = new Button("Flip"); // make flipButton2
add(flipButton2); // draw flipButton2
flipButton2.addActionListener(this); // listen for mouse
colorButton2 = new Button("Change Color"); // make colorButton2
add(colorButton2); // draw colorButton2
colorButton2.addActionListener(this); // listen for mouse

// declare an empty PetRockApplet class called "myPetRock3"
PetRockApplet myPetRock3;

// make (instantiate) the new PetRock3
myPetRock3 = new petRockApplet3();

flipButton3 = new Button("Flip"); // make flipButton3
add(flipButton3); // draw flipButton3
flipButton3.addActionListener(this); // listen for mouse
colorButton3 = new Button("Change Color"); // make colorButton3
add(colorButton3); // draw colorButton3
colorButton3.addActionListener(this); // listen for mouse
paint1(); // draw rock 1
paint2(); // draw rock 2
paint3(); // draw rock 3
} // end of init() method

/**
* The petRockApplet1() method constructs pet rock 1 with a given
* major axis, minor axis, and name. It also defines colors 1 & 2.
*/
public void petRockApplet1()
{
name1 = "Jacob Harris' Pet Rock 1";
majorAxis = 30;
minorAxis = 70;
color1 = Color.red;
color2 = Color.blue;
} // end of petRockApplet1() method

/**
* The petRockApplet2() method constructs pet rock 2 with a given
* length, width, and name. It also defines colors 3 & 4.
*/
public void petRockApplet2()
{
name2 = "Jacob Harris' Pet Rock 2";
length1 = 30;
width1 = 70;
color3 = Color.green;
color4 = Color.yellow;
} // end of petRockApplet2() method

/**
* The petRockApplet3() method constructs pet rock 3 with a given
* length, width, and name. It also defines colors 5 & 6.
*/
public void petRockApplet3()
{
name3 = "Jacob Harris' Pet Rock 3";
length2 = 30;
width2 = 70;
color5 = Color.pink;
color6 = Color.black;
} // end of petRockApplet3() method


/**
* The calculateArea1() method calculates and returns the area of the
* (oval) rock.
*/
public double calculateArea1()
{
double area;
return area = (majorAxis/2) * (minorAxis/2) * 3.14;
} // end of calculateArea1() method

/**
* The calculateArea2() method calculates and returns the area of the
* (rectangular) rock.
*/
public double calculateArea2()
{
double area;
return area = length1 * width1;
} // end of calculateArea2() method

/**
* The calculateArea3() method calculates and returns the area of the
* (2nd rectangular) rock.
*/
public double calculateArea3()
{
double area;
return area = length2 * width2;
} // end of calculateArea3() method

/**
* The flip1() method switches the major axis and minor axis of rock 1
* then redraws the picture.
*/
public void flip1()
{
int temp1; // need int temp1 only in this method
temp1 = minorAxis;
minorAxis = majorAxis;
majorAxis = temp1;
} // end of flip1() method

/**
* The flip2() method switches the length and width of rock 2 then
* redraws the picture.
*/
public void flip2()
{
int temp2; // need int temp2 only in this method
temp2 = length1;
length1 = width1;
width1 = temp2;
} // end of flip2() method

/**
* The flip3() method switches the length and width of rock 3 then
* redraws the picture.
*/
public void flip3()
{
int temp3; // need int temp3 only in this method
temp3 = length2;
length2 = width2;
width2 = temp3;
} // end of flip3() method

/**
* The changeColor1() method switches the color of rock 1 then redraws
* the picture.
*/
public void changeColor1()
{
Color temp1; // need Color temp1 only in this method
temp1 = color1;
color1 = color2;
color2 = temp1;
} // end of changeColor1() method

/**
* The changeColor2() method switches the color of rock 2 then redraws
* the picture.
*/
public void changeColor2()
{
Color temp2; // need Color temp2 only in this method
temp2 = color3;
color3 = color4;
color4 = temp2;
} // end of changeColor2() method

/**
* The changeColor3() method switches the color of rock 3 then redraws
* the picture.
*/
public void changeColor3()
{
Color temp3; // need Color temp3 only in this method
temp3 = color5;
color5 = color6;
color6 = temp3;
} // end of changeColor3() method

/**
* The paint1() method draws rock 1 (oval) as well as the name of the
* rock then computes and prints the area of the rock using the
* calculateArea1() method.
*/
public void paint1(Graphics g) // create predefined graphics object
{
// draws name1 at 50 over and 70 down
g.drawString(name1,50,70);

// sets the rock's color to red
g.setColor(color1);

// draws the oval Rock
g.fillOval(100,160,minorAxis,majorAxis);

// draws the major axis
g.drawString("The major axis: "+majorAxis,50,85);

// draws the minor axis
g.drawString("The minor axis: "+minorAxis,50,100);

// draws the area
g.drawString("The area: "+calculateArea1(),50,115);
} // end of paint1() method

/**
* The paint2() method draws rock 2 (rectangle) as well as the name of
* the rock then computes and prints the area of the rock using the
* calculateArea2() method.
*/
public void paint2(Graphics g) // create predefined graphics object
{
// draws name2 at 70 over and 70 down
g.drawString(name2,70,70);

// sets the rock's color to green
g.setColor(color3);

// draws the rectangular rock
g.fillRect(120,160,length1,width1);

// draws the length
g.drawString("The length: "+length1,70,85);

// draws the width
g.drawString("The width: "+width1,70,100);

// draws the area
g.drawString("The area: "+calculateArea2(),70,115);
} // end of paint2() method

/**
* The paint3() method draws rock 3 (2nd rectangle) as well as the name
* of the rock then computes and prints the area of the rock using the
* calculateArea3() method.
*/
public void paint3(Graphics g) // create predefined graphics object
{
// draws name3 at 90 over and 70 down
g.drawString(name3,90,70);

// sets the rock's color to pink
g.setColor(color5);

// draws the rectangular rock
g.fillRect(140,160,length2,width2);

// draws the length
g.drawString("The length: "+length2,90,85);

// draws the width
g.drawString("The width: "+width2,90,100);

// draws the area
g.drawString("The area: "+calculateArea3(),90,115);
} // end of paint3() method

/**
* The actionPerformed() method is automatically called whenever a
* flip button or color button is clicked.
*/
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == flipButton1) // see if flipButton1 clicked
{
flip1(); // flip major & minor axes
}
if (e.getSource() == colorButton1) // see if colorButton1 clicked
{
changeColor1(); // change the color
}
if (e.getSource() == flipButton2) // see if flipButton2 clicked
{
flip2(); // flip length1 and width1
}
if (e.getSource() == colorButton2) // see if colorButton2 clicked
{
changeColor2(); // change the color
}
if (e.getSource() == flipButton3) // see if flipButton3 clicked
{
flip3(); // flip length2 and width2
}
if (e.getSource() == colorButton3) // see if colorButton3 clicked
{
changeColor3(); // change the color
}
paint1(); // redraw rock 1
paint2(); // redraw rock 2
paint3(); // redraw rock 3
} // end of actionPerformed() method
} // end of petRockApplet

F:\PetRockApplet.java:50: error: cannot find symbol
myPetRock1 = new petRockApplet1();
^
symbol: class petRockApplet1
location: class PetRockApplet
F:\PetRockApplet.java:63: error: cannot find symbol
myPetRock2 = new petRockApplet2();
^
symbol: class petRockApplet2
location: class PetRockApplet
F:\PetRockApplet.java:76: error: cannot find symbol
myPetRock3 = new petRockApplet3();
^
symbol: class petRockApplet3
location: class PetRockApplet
F:\PetRockApplet.java:84: error: method paint1 in class PetRockApplet cannot be applied to given types;
paint1(); // draw rock 1
^
required: Graphics
found: no arguments
reason: actual and formal argument lists differ in length
F:\PetRockApplet.java:85: error: method paint2 in class PetRockApplet cannot be applied to given types;
paint2(); // draw rock 2
^
required: Graphics
found: no arguments
reason: actual and formal argument lists differ in length
F:\PetRockApplet.java:86: error: method paint3 in class PetRockApplet cannot be applied to given types;
paint3(); // draw rock 3
^
required: Graphics
found: no arguments
reason: actual and formal argument lists differ in length
F:\PetRockApplet.java:339: error: method paint1 in class PetRockApplet cannot be applied to given types;
paint1(); // redraw rock 1
^
required: Graphics
found: no arguments
reason: actual and formal argument lists differ in length
F:\PetRockApplet.java:340: error: method paint2 in class PetRockApplet cannot be applied to given types;
paint2(); // redraw rock 2
^
required: Graphics
found: no arguments
reason: actual and formal argument lists differ in length
F:\PetRockApplet.java:341: error: method paint3 in class PetRockApplet cannot be applied to given types;
paint3(); // redraw rock 3
^
required: Graphics
found: no arguments
reason: actual and formal argument lists differ in length
9 errors

Tool completed with exit code 1
 
Ad

Advertisements

S

Stefan Ram

import java.awt.*; // get the java "standard graphic" classes
import java.applet.Applet; // get the java "standard applet" classes
import java.awt.event.*; // get the java "standard event" classes

You're teacher seems to like to teach dated topics.
Applets and AWT are used rarely today, although this
still might make sense in special environments.
private Color color1; // declare color 1 (red)
private Color color2; // declare color 2 (blue)
private Color color3; // declare color 3 (green)
private Color color4; // declare color 4 (yellow)
private Color color5; // declare color 5 (pink)

The many fields might be a possible smell (called »the God
class«) of a lack of structuring of this class. Also, the
names of the fields possibly still can be improved.
// make (instantiate) the new PetRock1
myPetRock1 = new petRockApplet1();

The above comment looks redundant, as many other comments.
/**
* The petRockApplet1() method constructs pet rock 1 with a given
* major axis, minor axis, and name. It also defines colors 1 & 2.
*/
public void petRockApplet1()
{
name1 = "Jacob Harris' Pet Rock 1";
majorAxis = 30;

Here, the comment contradicts the implementation. The major
axis is not »given« (as in a parameter), but is 30.
public void petRockApplet2()
{
name2 = "Jacob Harris' Pet Rock 2";
length1 = 30;

The code has several repetitions (redundancies).
F:\PetRockApplet.java:50: error: cannot find symbol
myPetRock1 = new petRockApplet1();
^
symbol: class petRockApplet1
location: class PetRockApplet

You need to learn the basics first:

- What unqualified names can be used in a scope?
(local variables of enclosing blocks, fields of
enclosing classes and statically imported names
come to my mind right now.)

- What is the correspondance between the parameters
used in a method documentation or declaration and
the arguments used in a method invocation?
 
Ad

Advertisements

R

Roedy Green

I keep getting errors in java and I don't know what to do. Everything looks fine. Could someone please help?
Here's the applet I'm working on and below it are the error messages.

see http://mindprod.com/jgloss/compileerrormessages.html
for additional hints one what the messages mean.
In this case, they are pretty obvious.
Your objects are of one type and there are no matching instance
methods for that type.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top