Flash Games

 FAQ   Search   Members   Groups   Register  User Control Panel      Login 

Your time now:
Sat Nov 21, 2009 4:52 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ]  Bookmark and Share
Author Message
 Post subject: Overloading methods
PostPosted: Wed Sep 24, 2008 4:06 pm 
Offline

Joined: Wed Sep 24, 2008 2:58 pm
Posts: 0
Hi, I'm new to this forum and need help with an assignment. Any help would be appreciated!!!! This is my assignment:
Modify the methods of the Lunch class you created in the Chapter 2 case projects. Specifically, overload the constructor to take the numbers of apples, the amount of cheese, and number of loaves as parameters. Also, use parameters in the mutator method to set new amounts. Finally, return a value from the calculation method that represents the total price of the items. Add a display method that calls the calculation method and displays the total. Test your program by modifying the main() method.

This is my code:
Code:
import java.io.*;
import java.text.*;

public class ParameterValue {
   DecimalFormat df = new DecimalFormat("$,###.00");   
   private double x, y, z, sum;
   private String s1;
   private String s2;
   private String s3;
   
   public static void main (String[] args){
   ParameterValue pv = new ParameterValue();
   pv.showValues();
   try{
   pv.getValues();
   }
   catch (IOException e){
   System.out.println("IO error");
   }
   pv.calculateTotal();
   }
   
    public void showValues()
     {
        //Display prices of items
        System.out.println("Apples cost $.50 each " +
                "\n Cheese cost $2.05 per pound " +
                "\n Bread cost $1.00 per loaf");
    }
   
    public void getValues(String s1, String s2, String s3, double x, double y, double z) throws IOException {
        //set input stream
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        //get numbers from user input
        System.out.print("How many apples do you want? ");
        s1 = br.readLine();
        x = Double.parseDouble(s1) * .50f;
       
        //asks user for 2nd number       
        System.out.print("How many pounds of cheese do you want? ");
        s2 = br.readLine();
        y = Double.parseDouble(s2) * 2.49;
       
        //asks user for 3rd number
        System.out.print("How many loaves of bread do you want? ");
        s3 = br.readLine();
        z = Double.parseDouble(s3) * 1.28f;
    }
   
    public void calculateTotal(double x, double y, double z, double sum) {       
       
        //add x,y,z
        sum = (x + y + z);
        return sum;
        //Display sum of x, y, z
        System.out.println("Your total is $" + df.format(sum));
    }
}


I get the errors:
ParameterValue.java:21: getValues(java.lang.String,java.lang.String,java.lang.String,double,double,double) in ParameterValue cannot be applied to ()
pv.getValues();
^
ParameterValue.java:26: calculateTotal(double,double,double,double) in ParameterValue cannot be applied to ()
pv.calculateTotal();
^
ParameterValue.java:61: cannot return a value from method whose result type is void
return sum;
^
3 errors

----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group - Flash Games - TNX Invitation Code - TNX Review


Webmaster - Excruciating - Johnathan - Kotik - Ash - Tomi - rangana - Phate - dflynn - Medley