Need Help on school Project

homework
java

#1

Write a console based, non-GUI (not a Graphical User Interface application) Java program using NetBeans (or similar) Integrated Development Environment (IDE) a that calculates the total annual compensation of a salesperson. Consider the following factors:

A salesperson will earn a fixed salary of exactly $30,000.
A salesperson will also receive a commission as a sales incentive. Commission is a percentage of the salesperson’s annual sales. The current commission is 8% of total sales.
The total annual compensation is the fixed salary plus the commission earned.
The Java application should meet these technical requirements:

The application should have at least one class, in addition to the application’s controlling class (a controlling class is where the main function resides). This means you must write and use at least two classes to meet the requirements. Simply using a second class that somebody else wrote does not meet the requirement (see the student material within the Week 2 Supporting Activity “Discussion of a Three Class Example” to understand how to write multiple classes).
There should be proper documentation in the source code including any references used (references used should be in a “References” section of comments at the end of your file).
The application should ask the user to enter annual sales, and it should display the total annual compensation.

This is the project and this is what I have so far that isnt running correctly.

  • A salesperson will earn a
    fixed salary of $30,000.

A salesperson will also
receive a commission as a sales incentive. Commission is a percentage of the
salesperson’s annual sales. The current commission is 8% of total sales.

The total annual compensation
is the fixed salary plus the commission earned.

@author jgilchrist
*/

package salesperson.commission;

import java.util.Scanner;

public class SalespersonCommission {

    //fixed salary of $30,000.
    final private double salary = 30000;
    //the current commission is 8% of total sales.
    final private double commission = 0.08;
    public static void main(String[] args) {
        // TODO code application logic here
   
    
    }
           
}

This above build runs successfully, The one below does not? What am I doing wrong here?

package driver;

import java.util.Scanner;
public class Driver {
    public static void main (String [] args) {
        //for user input
        Scanner input = new Scanner(System.in);
        System.out.print("Enter sale amount: ");
        double sales = input.nextDouble();
        //creating object
        Salesperson sp = new Salesperson(sales);
        System.out.println("Annual compensation: "+sp.getAnnualCompensation())
;                }
                    
    }

#2

here:

Salesperson sp = new Salesperson(sales);

Salesperson isn’t defined anywhere, so there must be more code? Please provide us with something in which we can replicate the problem. To ensure the problem is the same, also include your error message


#3

That’s all the code I have so far, I am just learning Java this is my first class on this so I am pretty lost as to what to do, I have those two sections of code I posted which I am pretty sure somehow need to go together in one file instead of seperate. But I not sure where to put the missing section of code


#4

You can put the different classes in different files, i would recommend that. Just ensure that the scope is right, given its one program, make the different classes part of the same package


#5
/*
 * * A salesperson will earn a 
fixed salary of $30,000.
 
A salesperson will also 
receive a commission as a sales incentive. Commission is a percentage of the
salesperson's annual sales. The current commission is 8% of total sales.

The total annual compensation
is the fixed salary plus the commission earned.

This program will calculate the total annual compensation of a salesperson.
@author Jeffrey Gilchrist
 */
package salescommcalc1;

import java.util.Scanner;

public class SalesCommCalc1 {

    
    public static void main(String[] args) {
        
                        
        double annualSalary;
        annualSalary = 30000;
                         
        System.out.println("The Salesperson earns a fixed annual salary of $"
        + annualSalary + ".");
        
        int commission;
        commission = 8;
        
        System.out.println("The Salesperson will receive a commission of "
        + commission + "%");
        
        **SalesPerson SalesPersonObject = new SalesPerson();**
**        SalesPersonObject.salesmanName();**        
                       
        Scanner input = new Scanner(System.in);
                       
        double annualSales;
        
        System.out.print("Enter annual sales ");
        annualSales = input.nextDouble();
        
        double commissionCalc;
        commissionCalc = annualSales * .08;
        
        System.out.println("The annual commission of the salesperson is $"
                + commissionCalc + " using 8% commission");
        
        double totalAnnualSum;
        totalAnnualSum = annualSalary + commissionCalc;
        
        System.out.println("The total annual compensation of the salesperson"
                           + " is: $" + totalAnnualSum + ".");
        }
    
}
    
}

Okay I reworked the code and have this now which runs successfully. I just reread my assignment. I figured out how to add a second class. When I run the code it pops up with Enter Salesman Name which is what I wanted but it wont let me enter a name, How do I write the code after the emphasized part above to allow me to enter any name and then my annual sales to finish the calculation. Thanks in advance this is the last part I need.


#6

you should be able to achieve this with scanner and system.in


#7

I tried that and it didn’t work, I may be putting it in the wrong spot but I tried and kept getting an error message


#8

i can’t run the code, given new salesperson would throw an error, can you make the code run on repl.it? It allows multiple files, or give a clear overview of everything you have, so i can copy the project locally


#9

#10

I shared it and it is showing errors codes in here where it wasnt showing any errors in Netbeans which is the ide we were told to use for class.


#11

here:

SalesPerson SalesPersonObject = new SalesPerson();

there is no SalesPerson class, like i have been telling you. So you can’t create an object of a class you do not have. You must define SalesPerson class within the same package, but in a file names SalesPerson.java


#12

I am a total beginner with this stuff. I have another tab in netbeans that
is named SalesPerson.java and I though that is what that little section of
code was referencing was that. I am going to have a ■■■■ of a time with
this class because the next two weeks just get much more complicated and I
can’t even figure out how to get a second class in my program just so I can
type a name in. Thanks for your help so far I will have to try again
tonight and turn in whatever I can figure out or not figure out.


#13

is the part of the same salescommcalc1 package? I need that file as well in order to help you, repl.it allows for multiple files, i asked you to set this up in repl as well, or give me all the files (through whatever means you prefer), then i can replicate it locally

i can’t help you, if you are not forthcoming with the information needed (like the content of the salesperson.java file) and maybe other files within the package?


#14


Here is the link to the Salesperson.java and it does look to me like I have it in the same package.


#15

you could just add multiple files within a single repl?

Anyway, i replicated your project locally in my netbeans IDE, and this is what i got:

Screenshot_2018-01-29_14-22-46

now that i can finally successfully run your program, what is your question?

yea, SalesPerson has no scanner and input, you should do this within salesmanName method.


#16

Under enter salesman I want to be able to type a name which should fufill
my second class requirement and I can’t figure out how to get the program
to let me type a name in the run screen


#17

you have done this successfully here:

Scanner input = new Scanner(System.in);
annualSales = input.nextDouble();

but now we need a string, so we need to get the next line the user will input (nextLine), because this time we don’t want a double (nextDouble is for float numbers)

although you didn’t close the input at the end, but that might be confusing for new programmers


#18

Where do I put (nextLine) in the code and would it be salesmanName = input.nextLine();


#19

if you have defined salesmanName somewhere, if not, you should say its a String. Java is static typed language, declaring variables requires a datatype


#20

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.