File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

programming help

 
Corey Schuh
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;
}



}
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want a semicolon after the line...

private double totalvalue

 
muhsin sabeer
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the error message??
 
Corey Schuh
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya I was missing that but it still doesnt work! Any other ideas?
 
Corey Schuh
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Purse.java:49: ';' expected
 
Sudhakar Janarthanan
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like you haven't defined doll,quar,dim,nick and penn variables and you are trying to assign a value to it.
 
Layne Lund
Ranch Hand
Posts: 3061
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
S Thanigaivel
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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() );

}

}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic