java help

i am trying to write a program for class that calculates a saleman commision. it stats the sales man recieves 200.00 per week plus 9% of theri gross sales and you have enter a number 1-4 and each repersents a value of an item like 1=239.99 2=129.75,3=99.95 and 350.89 =350.89 and they can put in as many items as they want and once done it adds the toals togeather and calculated the 9% and adds the 200.00 base and give the salesman pay . I am stuck can someone help here is what i got :
[code]
// scc,java
import java.util.Scanner;

public class scc
{
private String salesName; // Sales persons name for this sales calculator


// constructor initializes salesName with String argument
public scc( String name )
{
salesName = name;

} // end constructor

public scc() {
// TODO Auto-generated constructor stub
}

//method to set the sales name
void setsalesName(String name)
{
salesName = name;

} // end constructor

// method to retrieve the sales name
public String getsalesName()
{
return salesName;
} // end method getsalesName


//display a welcome message to the GradeBook User
public void displayMessage ()
{
//
System.out.printf ( "Welcome to the Sales Book for
%s!
",
getsalesName() );
}
// this statement calls getCourseName to get the
// name of the course this GradeBook represents

public void determinesalesprofit()
{
Scanner input = new Scanner( System.in );
int salesNumber;
int sales;
double total;
double pay = 0;
double comm;

total = 0;
sales = 0;
System.out.print( "Enter Sales code or -1 to quite: " );
salesNumber = input.nextInt();

while ( salesNumber != -1 )
{
if ( salesNumber == 1)
pay = 239.99;
if ( salesNumber == 2)
pay = 129.75;
if ( salesNumber == 3)
pay = 99.95;
if ( salesNumber == 4)
pay =350.89;

total = total + pay;

System.out.print( "Enter Sales code or -1 to quite: " );
salesNumber = input.nextInt();
}
if ( sales != 0 )
{
comm = (total * 0.09 ) + 200;

System.out.printf( " Salesperson commision is :%d", comm);
}

}


}
[/code]

and
[code]
// sccTest.java
import java.util.Scanner; // program uses Scanner

public class sccTest {

// main method begins program execution
public static void main( String[] args )
{
// create Scanner to obtain input from command window
Scanner input = new Scanner( System.in );


// create a GradeBook object and assign it to myGradeBook
scc mySaleBook = new scc();


//prompt for and read course name
System.out.println( "please enter SalesPerson's name:" );
String theName = input.nextLine(); // read a line of text
mySaleBook.setsalesName( theName ); // set the name
System.out.println (); // outputs a blank line


// display Welcome message after specifying salesperson name
mySaleBook.displayMessage();
} // end main
} // end class

[/code]

Comments

  • The problem in your code lies here:

    [code]
    if ( sales != 0 )
    {
    comm = (total * 0.09 ) + 200;
    System.out.printf( " Salesperson commision is :%d", comm);
    }
    [/code]
    Your checking if sales does not equal zero but sales = 0 every time because you initialize sales to 0 but it never changes. So every time you reach the piece of code above, the commission is never calculated and is not displayed.

    I also notice that you haven't called your determinesalesprofit() function. Since that function is an important piece of your code, it should be called some where since it is the function that calculates the commission. Hope this helps.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion