Forums Register Login

programming help

+Pie Number of slices to send: Send
I am creating a program that is like a change purse thing. I am having problems with the code so if anyone could help that would be great. When I compile it the error is in the 1st { after the public class Purse.

public class Purse

{
//Instance Fields
private static final double Dollars=1.00;
private static final double Quarters=0.25;
private static final double Dimes=0.10;
private static final double Nickles=0.05;
private static final double Pennies=0.01;

private double totalvalue

public Purse ()
{
totalvalue=0;
}

public void addDollars ( double amount)
{
double total=Dollars * amount;
doll=total;
}

public void addQuarters (double amount)
{
double total=Quarters * amount;
quar=total;
}

public void addDimes (double amount);
{
double total=Dimes * amount;
dim=total;
}

public void addNickles (double amount)
{
double total=Nickles * amount;
nick=total;
}

public void addPennies (double amount);
{
double total=Pennies * amount;
penn=total;
}

public double getTotalValue
{
double totalvalue=doll + quar + dim + nick + penn;
return totalvalue;
}



}
+Pie Number of slices to send: Send
You might want a semicolon after the line...

private double totalvalue

+Pie Number of slices to send: Send
What is the error message??
+Pie Number of slices to send: Send
ya I was missing that but it still doesnt work! Any other ideas?
+Pie Number of slices to send: Send
Purse.java:49: ';' expected
+Pie Number of slices to send: Send
It looks like you haven't defined doll,quar,dim,nick and penn variables and you are trying to assign a value to it.
+Pie Number of slices to send: Send
As someone stated, you are missing a ; on the line that says "private double totalvalue". If you fixed this and are still getting more errors, please post the first error message from the new list along with your modified code and an indication of which line is causing the error message. We will be glad to help you figure them out one at a time.

Layne

p.s. You can use UBB CODE tags to preserve the formatting in your code.
[ October 07, 2005: Message edited by: Layne Lund ]
+Pie Number of slices to send: Send
places where u went wrong


private double totalvalue //append ;
public void addDimes (double amount); //rmv ;
public void addPennies (double amount); //rmv ;
double totalvalue=doll + quar + dim + nick + penn; //declare used vars

--------------------------------------
this works fine

public class Purse

{
//Instance Fields
private static final double Dollars=1.00;
private static final double Quarters=0.25;
private static final double Dimes=0.10;
private static final double Nickles=0.05;
private static final double Pennies=0.01;

private double totalvalue;

public Purse ()
{
totalvalue=0;
}

public double addDollars ( double amount)
{
return Dollars * amount;
}

public double addQuarters (double amount)
{
return Quarters * amount;
}

public double addDimes (double amount)
{
return Dimes * amount;
}

public double addNickles (double amount)
{
return Nickles * amount;
}

public double addPennies (double amount)
{
return Pennies * amount;
}

public double getTotalValue()
{
// pass param as per ur need...........
double totalvalue= this.addDollars(1) + this.addQuarters(1) + this.addDimes(1) + this.addNickles(1) + this.addPennies(1);
return totalvalue;
}

public static void main(String[] args)
{
System.out.println( (new Purse()).getTotalValue() );

}

}
His brain is the size of a cherry pit! About the size of this ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 960 times.
Similar Threads
Problems with double and float in Compile
Calculating Change
Why can't I subract coins?
Help with these errors
double variable and place values
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 07:46:43.