• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

programming help

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;
}



}
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might want a semicolon after the line...

private double totalvalue

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the error message??
 
Corey Schuh
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ya I was missing that but it still doesnt work! Any other ideas?
 
Corey Schuh
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Purse.java:49: ';' expected
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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() );

}

}
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic