NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Need help with a Java error:

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users
View previous topic :: View next topic  
Author Message
sasahadeo



Joined: 23 Sep 2012
Posts: 1

PostPosted: Sun Sep 23, 2012 9:38 pm    Post subject: Need help with a Java error: Reply with quote

I desperately need help in getting my program to run successfully, I keep getting the error:

Table

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - incompatible types
required: boolean
found: int
at comparisonsales.ComparisonSales.main(ComparisonSales.java:49)


MY CODE BELOW:


package comparisonsales;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Scanner;

/**
*
* @Stephanie Bowens
* Week 4 Program
* Version
*/

/**
* MAIN CLASS
*/
public class ComparisonSales {
//Input for the scanner
private static Scanner input = new Scanner(System.in);
//Array list validation
private static boolean allEqual = true;

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

//Program title
System.out.println("Table\n");

//List of SalesPerson
ArrayList<SalesPerson> employees = new ArrayList();
int highestIndex = 0;
//The salesperson with the highest compensation in comparison

double totalAnnualSales;

//Salesperson's name.
String name = "";

//counter
int counter = 0;
while (true) {
//Will need to calculate 2 sums

if (counter = 2) {
System.out.print("Enter the next? N for no.);
if (!input.nextLine().toLowerCase().equals("y")) {
break;
}
}

//Request user's input and validate
do {
System.out.'sprint("Enter Salesperson's number: ");
number = input.nextLine();
} while (number.length() < 1);

totalAnnualSales = Utility.getDoubleInput("Enter " + number + "'s total annual sales: ");

//Validtion of totalAnnualSales.
employees.add(new SalesPerson(name, totalAnnualSales));

//Calculate the highest earner
boolean Highest = true;
for (int i = 0; i < employees.size(); i++) {
if (employees.get(counter).totalFinalCompensation < employees.get(i).totalFinalCompensation) {
Highest = false;
}

if (employees.get(counter).totalFinalCompensation != employees.get(i).totalFinalCompensation) {
allEqual = false;
}
}
if (Highest) {
highestIndex = counter;
}

//increment
counter++;
}
// when (true);

//Printout the comparison table:
System.out.println("\n\nComparison Table:\n");
System.out.format("%20s\t%20s\t%20s\t%20s\n", "Number", "Total Annual Sales", "Compensation", "Highest Sales?");
for (int i = 0; i < employees.size(); i++) {

//Show results to user.
System.out.format("%20s\t%20s\t%20s\t%20s\n", employees.get(i).number,
Utility.numFormat(employees.get(i).totalFinalCompensation, "$"),
Utility.numFormat(employees.get(i).totalAnnualSales, "$"),
(i == highestIndex && allEqual == false) ? "Yes" : "");

}

//Output salespersons information
System.out.println("\nSelect the ENTER key to for the salesperson information.");
input.nextLine();

for (int i = 0; i < employees.size(); i++) {

//Local Varibles
SalesPerson highest = employees.get(highestIndex);
SalesPerson current = employees.get(i);

//print results to user.
System.out.println("\n\n" + current.name + "'s information:\n");
System.out.println("Salary: " + Utility.numFormat(current.Salary, "$"));
System.out.println("Annual Sales: " + Utility.numFormat(current.annualSales, "$"));
System.out.println("Current Commission: " + Utility.numFormat(current.curCommission, "$"));
System.out.println("Current Commission Rate: " + (current.curCommissionRate * 100) + " %");
System.out.println("Total Compensation: " + Utility.numFormat(current.totalFinalCompensation, "$"));

if (allEqual) {
System.out.println("Note: \tAll salespersons earned equal amounts.");
} else if (i == highestIndex) {
System.out.println("Note: \t" + current.number + " is the highest earner.");
} else {
System.out.println("Note: "
+ "\tTo match " + highest.number + "'s compensation, " + current.number + " needs "
+ Utility.numFormat((highest.curCommission - current.curCommission), "$"));
}
}

//Ask user to repeat action.
System.out.println("\n\nRestart? Y to reset. Anything else to quit.");
if (input.nextLine().toLowerCase().equals("y")) {
main(args);
}

}
}


class SalesPerson {

//Salary
public final double Salary = 50000;

//Fixed Commission Rate
public double curCommissionRate = 0.12;

//Sales Target
public final double salesTarget = 120000;

//Current Sales Target Rate
public final double curSalesTargetRate = 0.8;

// Sales Target
public double curSalesTarget = salesTarget * curSalesTargetRate;

//Accrued Commission
public double curCommission = 0;

//Total Compensation
public double totalCompensation = 0;

//Annual Sales
public double annualSales = 0;;

//Salesperson's Number
public String number = "";
String name;
double totalFinalCompensation;

//Constructor
//Salesperson's annual sales.

public SalesPerson(String pName, double pAnnualSales) {
name = pName; //set name
annualSales = pAnnualSales; //set object member
computetotalFinalCompensation();
}


SalesPerson() {
}

/**
* Computes total compensation, when sales reach target the higher commission rate is used. If
* commission short of target the fixed commission will be used.
*/
private void computetotalFinalCompensation() {
if (annualSales >= curSalesTarget) //Target Reached
{
if (annualSales >= curSalesTarget) { //Above sales target
curCommissionRate = 0.1325;
} else { //Below Sales Target
curCommissionRate = 0.12;
}

} else //Target NOT Reached
{
//Commission Rate
curCommissionRate = .12;
}

//Compute commission and add fixed salary
curCommission = (annualSales * curCommissionRate);
//calculate commission
totalCompensation = Salary + curCommission;
}

private void computetotalFinalCompensation() {
throw new UnsupportedOperationException("Not implemented");
}
}

class Utility {

/**
* Formats number to ##,##0.00 and adds symbol and return Formated number.
*/
public static String numFormat(double dec, String symbol) {
return new DecimalFormat(symbol + "##,##0.00").format(dec);
}

/**
* @param dec The number to format ##,##0.00 and return formated number.
*/
public static String numFormat(double dec) {
return numFormat(dec, "");
}

/**
* Request the user to repeat.
*/

public static double getDoubleInput(String message) {
double goodInput = 0;
try {

//Print message.
System.out.print(message);

//The exception will activate when non double:
goodInput = Double.parseDouble(new java.util.Scanner(System.in).nextLine());
} catch (NumberFormatException ex) {

//Inform user of error and to input numbers ONLY
System.out.println("Error: Input numbers only.");
goodInput = getDoubleInput(message);
}

//The goodInput is a double.
return goodInput;

}
}



Week 4 ComparisonSales.java
 Description:

Download
 Filename:  Week 4 ComparisonSales.java
 Filesize:  7.96 KB
 Downloaded:  154 Time(s)

Back to top
Damian Carey
Posted via mailing list.





PostPosted: Mon Sep 24, 2012 12:22 am    Post subject: Need help with a Java error: Reply with quote

Hello,

This is a forum for using Netbeans, not a forum for learning Java, so these questions will normally be ignored.


I'm not going to look very hard, but I did notice this line ..
if (counter = 2) {


Correct Jave syntax would be ...
if (counter == 2) {


Cheers,


On Mon, Sep 24, 2012 at 7:38 AM, sasahadeo <address-removed ([email]address-removed[/email])> wrote:
Quote:
I desperately need help in getting my program to run successfully, I keep getting the error:

Table

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - incompatible types
Back to top
Rick Fincher
Posted via mailing list.





PostPosted: Mon Sep 24, 2012 2:22 am    Post subject: Need help with a Java error: Reply with quote

My line numbers didn't match up with yours but I presume the error is in
this line:

if (counter = 2)

The code counter = 2 is not a comparison, it is an assignment so it
returns an int not a boolean. Use counter ==2.

This forum is for NetBeans issues, not learning Java issues.

If you have questions about how to get NetBeans to do something, this is
the place.

Otherwise, you might try JavaRanch.com . It's "a friendly place for
Java greenhorns" as they say on the site.

Hang in there. It will all fall into place soon.

Good luck!

Rick

On 9/23/2012 5:38 PM, sasahadeo wrote:
Quote:
I desperately need help in getting my program to run successfully, I keep getting the error:

Table

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - incompatible types
required: boolean
found: int
at comparisonsales.ComparisonSales.main(ComparisonSales.java:49)


MY CODE BELOW:

package comparisonsales;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Scanner;

/**
*
* @Stephanie Bowens
* Week 4 Program
* Version
*/

/**
* MAIN CLASS
*/
public class ComparisonSales {
//Input for the scanner
private static Scanner input = new Scanner(System.in);
//Array list validation
private static boolean allEqual = true;

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

//Program title
System.out.println("Table\n");

//List of SalesPerson
ArrayList<SalesPerson> employees = new ArrayList();
int highestIndex = 0;
//The salesperson with the highest compensation in comparison

double totalAnnualSales;

//Salesperson's name.
String name = "";

//counter
int counter = 0;
while (true) {
//Will need to calculate 2 sums

if (counter = 2) {
System.out.print("Enter the next? N for no.);
if (!input.nextLine().toLowerCase().equals("y")) {
break;
}
}

//Request user's input and validate
do {
System.out.'sprint("Enter Salesperson's number: ");
number = input.nextLine();
} while (number.length() < 1);

totalAnnualSales = Utility.getDoubleInput("Enter " + number + "'s total annual sales: ");

//Validtion of totalAnnualSales.
employees.add(new SalesPerson(name, totalAnnualSales));

//Calculate the highest earner
boolean Highest = true;
for (int i = 0; i < employees.size(); i++) {
if (employees.get(counter).totalFinalCompensation < employees.get(i).totalFinalCompensation) {
Highest = false;
}

if (employees.get(counter).totalFinalCompensation != employees.get(i).totalFinalCompensation) {
allEqual = false;
}
}
if (Highest) {
highestIndex = counter;
}

//increment
counter++;
}
// when (true);

//Printout the comparison table:
System.out.println("\n\nComparison Table:\n");
System.out.format("%20s\t%20s\t%20s\t%20s\n", "Number", "Total Annual Sales", "Compensation", "Highest Sales?");
for (int i = 0; i < employees.size(); i++) {

//Show results to user.
System.out.format("%20s\t%20s\t%20s\t%20s\n", employees.get(i).number,
Utility.numFormat(employees.get(i).totalFinalCompensation, "$"),
Utility.numFormat(employees.get(i).totalAnnualSales, "$"),
(i == highestIndex && allEqual == false) ? "Yes" : "");

}

//Output salespersons information
System.out.println("\nSelect the ENTER key to for the salesperson information.");
input.nextLine();

for (int i = 0; i < employees.size(); i++) {

//Local Varibles
SalesPerson highest = employees.get(highestIndex);
SalesPerson current = employees.get(i);

//print results to user.
System.out.println("\n\n" + current.name + "'s information:\n");
System.out.println("Salary: " + Utility.numFormat(current.Salary, "$"));
System.out.println("Annual Sales: " + Utility.numFormat(current.annualSales, "$"));
System.out.println("Current Commission: " + Utility.numFormat(current.curCommission, "$"));
System.out.println("Current Commission Rate: " + (current.curCommissionRate * 100) + " %");
System.out.println("Total Compensation: " + Utility.numFormat(current.totalFinalCompensation, "$"));

if (allEqual) {
System.out.println("Note: \tAll salespersons earned equal amounts.");
} else if (i == highestIndex) {
System.out.println("Note: \t" + current.number + " is the highest earner.");
} else {
System.out.println("Note: "
+ "\tTo match " + highest.number + "'s compensation, " + current.number + " needs "
+ Utility.numFormat((highest.curCommission - current.curCommission), "$"));
}
}

//Ask user to repeat action.
System.out.println("\n\nRestart? Y to reset. Anything else to quit.");
if (input.nextLine().toLowerCase().equals("y")) {
main(args);
}

}
}


class SalesPerson {

//Salary
public final double Salary = 50000;

//Fixed Commission Rate
public double curCommissionRate = 0.12;

//Sales Target
public final double salesTarget = 120000;

//Current Sales Target Rate
public final double curSalesTargetRate = 0.8;

// Sales Target
public double curSalesTarget = salesTarget * curSalesTargetRate;

//Accrued Commission
public double curCommission = 0;

//Total Compensation
public double totalCompensation = 0;

//Annual Sales
public double annualSales = 0;;

//Salesperson's Number
public String number = "";
String name;
double totalFinalCompensation;

//Constructor
//Salesperson's annual sales.

public SalesPerson(String pName, double pAnnualSales) {
name = pName; //set name
annualSales = pAnnualSales; //set object member
computetotalFinalCompensation();
}


SalesPerson() {
}

/**
* Computes total compensation, when sales reach target the higher commission rate is used. If
* commission short of target the fixed commission will be used.
*/
private void computetotalFinalCompensation() {
if (annualSales >= curSalesTarget) //Target Reached
{
if (annualSales >= curSalesTarget) { //Above sales target
curCommissionRate = 0.1325;
} else { //Below Sales Target
curCommissionRate = 0.12;
}

} else //Target NOT Reached
{
//Commission Rate
curCommissionRate = .12;
}

//Compute commission and add fixed salary
curCommission = (annualSales * curCommissionRate);
//calculate commission
totalCompensation = Salary + curCommission;
}

private void computetotalFinalCompensation() {
throw new UnsupportedOperationException("Not implemented");
}
}

class Utility {

/**
* Formats number to ##,##0.00 and adds symbol and return Formated number.
*/
public static String numFormat(double dec, String symbol) {
return new DecimalFormat(symbol + "##,##0.00").format(dec);
}

/**
* @param dec The number to format ##,##0.00 and return formated number.
*/
public static String numFormat(double dec) {
return numFormat(dec, "");
}

/**
* Request the user to repeat.
*/

public static double getDoubleInput(String message) {
double goodInput = 0;
try {

//Print message.
System.out.print(message);

//The exception will activate when non double:
goodInput = Double.parseDouble(new java.util.Scanner(System.in).nextLine());
} catch (NumberFormatException ex) {

//Inform user of error and to input numbers ONLY
System.out.println("Error: Input numbers only.");
goodInput = getDoubleInput(message);
}

//The goodInput is a double.
return goodInput;

}
}




Attachments:
http://forums.netbeans.org//files/week_4_comparisonsales_880.java
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo