# if, else if, else statement

• 11-06-2012, 05:26 AM
aragornfin
if, else if, else statement
so I needed to insert this or something similar into the code below it.. can someone help me figure out what I am doing wrong?
{
if (sales => 100,000)
{
then sales * 0.08
}
else If (sales > 120,000)
{
then sales * 0.08 * 1.25
}
else (sales < 100,000)
{
then sales * 0.00
}

/*need to insert into this code
Revised coding part 1
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package totalcompensationw3;

import java.util.Scanner;
/**
*
* @author Aragorn
*/
public class TotalCompensationW3
{
private double fixedSalary;
private double calculatedCommission;

/**
* @param args the command line arguments
*/
public void main(String[] args)
{
{
fixedSalary = 0;
calculatedCommission = 0;
}
}
public void Compensation(double base, double comm)
{
fixedSalary = base;
calculatedCommission = comm;
}
public void setSalary(double salary)
{
fixedSalary = salary;
}
public void setCommission(double commission)
{
calculatedCommission = commission;
}
public double getSalary()
{
return fixedSalary;
}
public double getCommission()
{
return calculatedCommission;
}
public double calculateWeek2Commission(double sales)
{
return (sales * 0.08);
}
public double getTotalCompensation()
{
return (fixedSalary + calculatedCommission);
}
}

Revised coding part 2
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package totalcompensationw3;

import java.util.Scanner;

/**
*
* @author Aragorn
*/
public class compensationCalculation
{
/**
* @param args the command line arguments
*/
public static void main ( String[] args)
{
TotalCompensationW3 myComp = new TotalCompensationW3(); // Instantiate the compensation class
double sales = 0; // initialize the sales revenue value
Scanner keyboard = new Scanner(System.in);
try
{
System.out.println("Enter the Sales Revenue: ");
sales = keyboard.nextInt(); // Ask user for Sales Revenue
myComp.setSalary(30000); // Set the base salary to \$30,000
myComp.setCommission(myComp.calculateWeek2Commissi on(sales)); // Calculate the compensation
System.out.println("The Sales Revenue is: " + sales); // Output Sales Revenue
System.out.println("The Base Salary is: " + myComp.getSalary()); // Output the Base Salary
System.out.println("The Commission is: " + myComp.getCommission()); // Output the Commission
System.out.println("The Total Annual Compensation is: " + myComp.getTotalCompensation()); // Output the Total Annual Compensation
} catch (Exception e)
{
System.out.println(e.toString()); // In case an error occurs, send error message to screen
}
}
}
• 11-06-2012, 06:15 AM
Junky
Re: if, else if, else statement
Code:

```if(condition) { } else if (condition) { } else { }```
Can you see what is wrong with your code?
• 11-06-2012, 11:31 AM
Tolls
Re: if, else if, else statement
Please use [code] tags [/code] when posting code.
Unformatted code is hard to follow.
• 11-07-2012, 05:04 AM
aragornfin
Re: if, else if, else statement
Junky,
I do see the difference between the code. which levees me scratching my head, but how would I incorporate or insert the code into the main program? would I creates a new program using a variable for the 0.08 commission in the original program?
• 11-07-2012, 10:11 AM
Kagiso
Re: if, else if, else statement
you can't say if...then within a java code(is this a pseudocode ?) perhaps you wanted to say:
{
if (sales => 100,000)
{
sales *= 0.08;
}
else if (sales > 120,000)
{
sales *=( 0.08 * 1.25); // I would use parenthesis to avoid confusion
}
else (sales < 100,000)
{
sales *= 0.00; // which gives you a zero.... is this what you want?.... to assign a zero to this variable
}

• 11-11-2012, 01:57 AM
aragornfin
Re: if, else if, else statement
so I am no closer to getting the code to run than when I started. what changes do I need to make to the original code and what should the new code be?