# Thread: Can't figure out what's wrong with my assignment. Help please

1. Member
Join Date
Jan 2012
Posts
3
Rep Power
0

## Can't figure out what's wrong with my assignment. Help please

Working on an assignment for school where I have to write a Java applet that displays the number of full dozens of eggs, the cost of eggs and the remaining eggs after dozens are counted.
I need to:
pass the number of eggs (118) through a parameter tag value
Declare and intitialize one int literal constant: eggs in a dozen 12
Display the total number of eggs in the basket
Display the number of even dozens
Display the number of leftover eggs
Display the cost of the eggs

call the methods "FullDozen" "LeftOver" and "Cost" from this method

FullDozen - accepts the number of eggs in the basket and eggs in a dozen
from the number of eggs received calculate the number of even dozens
return the calculated number of even dozens

LeftOver - Accepts a number of eggs in the basket and eggs in a dozen
From the number of eggs received calculate the number of eggs left over
Return the number of eggs left over

Cost - Accepts number of eggs in the basket and eggs in a dozen
method calculates the cost of eggs in the basket (1.57 per dozen passed by a param tag value)
return the cost back to the calling statement

getting frustrated trying to figure this out. any help would be greatly appreciated. Thanks!

Here is my Java code:

// Basic Applet.java

import javax.swing.*;
import java.awt.*;
import java.util.*;

/*
// Params won't work with the JApplet Viewer
*/

public class Param_eg extends JApplet
{

public void paint(Graphics gObj)
{
//Create a superpaint out of graphics object
super.paint(gObj);

//Load sData1 from param in HTML basics
String sData1 = getParameter("Data1");
String sData2 = getParameter("Data2");

//Set final variables
final int Eggs = Integer.parseInt(sData1);
final double Price = Double.parseDouble(sData2);

fullDozen(Eggs, gObj);
leftOver(Eggs, Price, gObj);
cost(Eggs, gObj);

//Show available string data using graphics object
gObj.drawString("Total number of eggs = " + Eggs, 75,70);

}
private void fullDozen(int Eggs)
{
int dozens = 0;

dozens = intEggs/12;

gObj.drawString("Total Dozens = " + dozens, 75,95);

}
private void leftOver(int Eggs)
{
int leftOver = 0;

leftOver = intEggs - ((intEggs/12)*12);

gObj.drawString("Total left over = " + leftOver, 75,120);

}
private void cost(int intEggs, double Price)
{
double Total = 0;

Total = intEggs * dblPrice;

String stringVar = "";

//Use formatter for double string outcome
Formatter formatterObject = new Formatter();
formatterObject.format("%,d", Total);
stringVar = formatterObject.toString();

gObj.drawString("Total cost = \$" + stringVar, 75, 145);

}
}//end of class

here is the errors that I am getting:

Error: /Users/timothymadison/Desktop/School/Java/Week 2/Param_eg.java:28: fullDozen(int) in Param_eg cannot be applied to (int,java.awt.Graphics)
Error: /Users/timothymadison/Desktop/School/Java/Week 2/Param_eg.java:29: leftOver(int) in Param_eg cannot be applied to (int,double,java.awt.Graphics)
Error: /Users/timothymadison/Desktop/School/Java/Week 2/Param_eg.java:30: cost(int,double) in Param_eg cannot be applied to (int,java.awt.Graphics)
Error: /Users/timothymadison/Desktop/School/Java/Week 2/Param_eg.java:45: cannot find symbol
symbol : variable intEggs
location: class Param_eg
Error: /Users/timothymadison/Desktop/School/Java/Week 2/Param_eg.java:47: cannot find symbol
symbol : variable gObj
location: class Param_eg
Error: /Users/timothymadison/Desktop/School/Java/Week 2/Param_eg.java:55: cannot find symbol
symbol : variable intEggs
location: class Param_eg
Error: /Users/timothymadison/Desktop/School/Java/Week 2/Param_eg.java:55: cannot find symbol
symbol : variable intEggs
location: class Param_eg
Error: /Users/timothymadison/Desktop/School/Java/Week 2/Param_eg.java:57: cannot find symbol
symbol : variable gObj
location: class Param_eg
Error: /Users/timothymadison/Desktop/School/Java/Week 2/Param_eg.java:64: cannot find symbol
symbol : variable dblPrice
location: class Param_eg
Error: /Users/timothymadison/Desktop/School/Java/Week 2/Param_eg.java:73: cannot find symbol
symbol : variable gObj
location: class Param_eg

and here is my html code

html>

<title>Welcome to Java Applet Program</title>

<body bgcolor="lightgreen">

<Applet code="BasicApplet.class" width=300 height=200 align="center" vspace="100">

<param name="Data1" value="118" />
<param name="Data2" value="1.57" />

</Applet>

</body>

</html>

any help is appreciated.

2. Moderator
Join Date
Jul 2010
Location
California
Posts
1,642
Rep Power
6

## Re: Can't figure out what's wrong with my assignment. Help please

First, off using the code tags makes your code readable. Second, take one error at a time, each of which is quite descriptive. Take the first,
Error: /Users/timothymadison/Desktop/School/Java/Week 2/Param_eg.java:28: fullDozen(int) in Param_eg cannot be applied to (int,java.awt.Graphics)
So take a look at line 28...you are trying to call a method defined with a single int parameter with a different number of parameters. If you wish to pass The Graphics object as a parameter, then define the method as such
Java Code:
```private void fullDozen(int Eggs, Graphics g)
...```

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•