Total members 11889 |It is currently Fri Mar 29, 2024 11:44 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Calling overloaded methods?
I can't seem to get any of the methods to call.

Problem Part a: Create a class named Commission that includes three variables: a double sales figure, a double commission rate, and an int commission rate. Also create two overloaded methods named computeCommission(). The first method takes two double parameters from the user representing sales and rate, multiplies them, and then displays the results. The second method takes two parameters from the user: a double sales figure and an integer commission rate. This method must divide the commission rate figure by 100.0 before multiplying by the sales figure and displaying the commission. Write a main() method that tests each overloaded method. Save the file as Commission.java

Part b: Add a third overloaded method to the Commission application. The third parameter takes a single parameter representing sales. When the method is called, the commission rate is assumed to be 7.5% and the results are displayed . To test this method , add an appropriate call in the commission program's main () method . Save the file as Commission2.java

I wrote the code and the program doesn't return any errors, but for some reason the program only calls one of three methods. For example, if the user enters $4387.69 for their sales amount and then enters .27 for their commission rate the program will calculate their commission earnings to be $1184.6763, but if the user were to have entered 27 for the commission rate instead if the program calling the appropriate function to convert the that number it runs the same function again.

Can someone please tell me what I'm doing wrong? Here is my code Thanks!
________________________________________________________________
Code:

import java
.util.Scanner;
public class Commission {
    
    public static void main
(String[] args){
        Commission cs=new Commission();
        // method 1 = 2 parameters = double, double 
        cs.computeCommission(0.0-100000.0,.00-.100);
        // method 2 = 2 parameters = double, integer
        cs.computeCommission(0.0-100000.0,(0-100)/100);
        //method 3 = 1 parameter = double
        cs.computeCommission(100000.1-1000000);
                    
    
}
        
    
//creating method 1
     void computeCommission (double rate, double salesFigure)
    {
        Scanner input = new Scanner(System.in);
        System.out.println(" Enter your total sales amount ");
        salesFigure = input.nextDouble();
        System.out.println(" Enter your commission rate ");
        rate = input.nextDouble();
        double computeCommission;
        computeCommission = salesFigure * rate;
        System.out.println(" Your commission is $ " + computeCommission);
        
    
}
    
    
//creating method 2
    void computeCommission ( double salesFigure2,int commissionRate)
     
    
{
        Scanner input = new Scanner(System.in);
        System.out.println(" Enter your total sales amount ");
        salesFigure2 = input.nextDouble();
        System.out.println(" Enter your commission rate ");
         commissionRate= input.nextInt();
        double computeCommission;
        computeCommission = salesFigure2 * ( commissionRate/ 100);
        System.out.println(" Your commission is $ " + computeCommission);
        
    
}
    
      
//creating method 3
        void computeCommission (double salesFigure3)
        {

    Scanner input = new Scanner(System.in);
    System.out.println(" Enter your total sales amount ");
    salesFigure3 = input.nextDouble() * .075;
    System.out.println(" Your commission is $ " + salesFigure3);
        
    
}
     







}




Author:
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Calling Overloaded Methods
 Calling the man Command     -  
 Calling an Overridden Method in php     -  
 Calling a Private Method in jsp     -  
 Calling Functions Dynamically     -  
 Calling an Overridden Function     -  
 Calling other programs from java     -  
 CME display calling number without leading 0     -  
 Calling a local variable from a static function     -  
 Which methods is best for SEO?     -  
 calling method to form- displaying textbox data in messagbox     -  



cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com