Week 2 Assignment: Are The Requirements Write A Java

Week 2 Assignmentfollowing Are The Requirementswritea Java

Week 2 Assignmentfollowing Are The Requirementswritea Java

Write a Java™ application using NetBeans™ Integrated Development Environment (IDE) that calculates the total annual compensation of a salesperson. Consider the following factors: A salesperson will earn a fixed salary of $100,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 5% 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). There should be proper documentation in the source code. The application should ask the user to enter annual sales, and it should display the total annual compensation.

Paper For Above instruction

Calculating the total annual compensation of a salesperson is an essential task that combines basic programming concepts such as user input, arithmetic calculations, and output display. This Java™ application, developed in NetBeans™, provides a straightforward solution to this problem by leveraging object-oriented principles and good coding practices to ensure clarity, maintainability, and correctness.

Introduction

The primary goal of this application is to compute the total annual compensation for a salesperson based on a fixed salary and a commission calculated as a percentage of annual sales. The fixed salary is set at $100,000, and the commission rate is 5%. The program prompts the user to input their total annual sales figure, then calculates and displays the total compensation. Implementing this program not only reinforces fundamental Java programming skills—such as using variables, input/output, and conditional logic—but also emphasizes good coding practices including proper documentation, descriptive naming conventions, and clear logic flow.

Design and Implementation

The application is designed with a main class, which contains the main method, and an auxiliary class responsible for performing the calculation. This separation adheres to object-oriented principles, promoting modularity and potential scalability. Proper inline documentation comments are included to clarify the purpose of variables and logic blocks, enhancing readability.

Class Structure

The main class, named SalesCommissionCalculator, handles user interaction—prompting for input and displaying output. The auxiliary class, named SalesData, encapsulates the sales data and provides a method to calculate the total compensation based on the input sales amount.

Implementation Details

The program begins by importing the necessary java.util.Scanner class to handle user input. In the main method, an object of SalesData is instantiated, and the user is prompted to input their annual sales. The program then sets the sales data within the object, computes the total compensation using a dedicated method, and outputs the result.

Sample Code

/**

* Program: SalesCommissionCalculator

* Description: Calculates total annual compensation for a salesperson based on fixed salary and commission

* Programmer: [Your Name]

* Date: [Current Date]

* Version: 1.0

*/

import java.util.Scanner;

/**

* Class to encapsulate sales data and compensation calculation

*/

class SalesData {

private double annualSales;

private static final double FIXED_SALARY = 100000.0;

private static final double COMMISSION_RATE = 0.05;

/**

* Sets the annual sales amount

* @param sales - the total sales for the year

*/

public void setAnnualSales(double sales) {

this.annualSales = sales;

}

/**

* Calculates total compensation = fixed salary + commission

* @return total annual compensation

*/

public double calculateTotalCompensation() {

double commission = annualSales * COMMISSION_RATE;

return FIXED_SALARY + commission;

}

}

public class SalesCommissionCalculator {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

SalesData salesData = new SalesData();

// Prompt user for annual sales

System.out.print("Enter annual sales: ");

double sales = input.nextDouble();

// Set sales data

salesData.setAnnualSales(sales);

// Calculate total compensation

double totalCompensation = salesData.calculateTotalCompensation();

// Display the result

System.out.printf("Total Annual Compensation: $%.2f%n", totalCompensation);

input.close();

}

}

Conclusion

This Java application demonstrates the application of core programming constructs—variables, input/output, classes, methods—and adheres to good coding standards. By modularizing the calculation logic within a dedicated class and providing comprehensive inline documentation, the program achieves clarity and ease of maintenance. Future enhancements may include adding user input validation, handling different commission rates, or extending the application to include multiple salespersons.

References

  • Deitel, P. J., & Deitel, H. M. (2017). Java: How to Program (10th Edition). Pearson.
  • Horstmann, C., & Cornell, G. (2018). Core Java Volume I--Fundamentals (11th Edition). Pearson.
  • Lippman, R., Lajoie, J., & Moo, W. (2012). C++ Primer (5th Edition). Addison-Wesley. (for general programming principles applicable to Java)
  • Oracle. (2023). Java Tutorials. https://docs.oracle.com/javase/tutorial/
  • NetBeans IDE Documentation. (2023). https://netbeans.apache.org/kb/docs/
  • Fowler, M. (1999). Refactoring: Improving the Design of Existing Code. Addison-Wesley.
  • Gamma, E., Helm, R., Johnson, R., & Vlissides, J. (1994). Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley.
  • Bloch, J. (2008). Effective Java (2nd Edition). Addison-Wesley.
  • Baeldung. (2023). Java Tutorial - Learn Java Programming. https://www.baeldung.com/java
  • Stack Overflow. (2023). Java questions and community support. https://stackoverflow.com/