Results 1 to 2 of 2
- 02-20-2012, 01:34 AM #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:
File: /Users/timothymadison/Desktop/School/Java/Week 2/Param_eg.java [line: 28]
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)
File: /Users/timothymadison/Desktop/School/Java/Week 2/Param_eg.java [line: 29]
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)
File: /Users/timothymadison/Desktop/School/Java/Week 2/Param_eg.java [line: 30]
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)
File: /Users/timothymadison/Desktop/School/Java/Week 2/Param_eg.java [line: 45]
Error: /Users/timothymadison/Desktop/School/Java/Week 2/Param_eg.java:45: cannot find symbol
symbol : variable intEggs
location: class Param_eg
File: /Users/timothymadison/Desktop/School/Java/Week 2/Param_eg.java [line: 47]
Error: /Users/timothymadison/Desktop/School/Java/Week 2/Param_eg.java:47: cannot find symbol
symbol : variable gObj
location: class Param_eg
File: /Users/timothymadison/Desktop/School/Java/Week 2/Param_eg.java [line: 55]
Error: /Users/timothymadison/Desktop/School/Java/Week 2/Param_eg.java:55: cannot find symbol
symbol : variable intEggs
location: class Param_eg
File: /Users/timothymadison/Desktop/School/Java/Week 2/Param_eg.java [line: 55]
Error: /Users/timothymadison/Desktop/School/Java/Week 2/Param_eg.java:55: cannot find symbol
symbol : variable intEggs
location: class Param_eg
File: /Users/timothymadison/Desktop/School/Java/Week 2/Param_eg.java [line: 57]
Error: /Users/timothymadison/Desktop/School/Java/Week 2/Param_eg.java:57: cannot find symbol
symbol : variable gObj
location: class Param_eg
File: /Users/timothymadison/Desktop/School/Java/Week 2/Param_eg.java [line: 64]
Error: /Users/timothymadison/Desktop/School/Java/Week 2/Param_eg.java:64: cannot find symbol
symbol : variable dblPrice
location: class Param_eg
File: /Users/timothymadison/Desktop/School/Java/Week 2/Param_eg.java [line: 73]
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>
<head>
<title>Welcome to Java Applet Program</title>
</head>
<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.
- 02-21-2012, 07:49 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,619
- Rep Power
- 5
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,
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 suchError: /Users/timothymadison/Desktop/School/Java/Week 2/Param_eg.java:28: fullDozen(int) in Param_eg cannot be applied to (int,java.awt.Graphics)
Java Code:private void fullDozen(int Eggs, Graphics g) ...
Similar Threads
-
Need Ideas to Figure Out Wording on Assignment!
By GFE in forum New To JavaReplies: 5Last Post: 11-24-2011, 04:52 AM -
Can't figure out what's wrong, help please.
By Taszk in forum New To JavaReplies: 30Last Post: 05-24-2011, 11:30 AM -
Cant figure out where went wrong.
By leviathan in forum New To JavaReplies: 15Last Post: 06-06-2010, 06:55 PM -
Please Help, can't figure out what I'm doing wrong.
By tamik0 in forum New To JavaReplies: 2Last Post: 07-11-2008, 09:41 AM -
Java assignment - couple methods don't know how to figure out
By Snowboardmylife in forum New To JavaReplies: 1Last Post: 04-16-2008, 10:52 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks