If you haven't done so already, i suggest reading my last blog post, and get antiquated with an editor of your choice to start learning how to code, as well and practicing and exploring the program. I choose to install and use Eclipse, which my other post includes links, and step by step instructions to help with the install as well.
I always start with importing the java utilities that will help me, as well as adding my name, name of the assignment I am working on and so forth, as these are requirements for my class, and also help identify my work.
The program I worked that shows a great example of data structures and algorithmic design is a pay program for my current class. Many objects needed to be addressed to complete this program. The objects I have added to my program are the various Taxes which are going to be taken out of the employees pay, the employee name (first and last), their rate of pay, overtime pay, hours worked at regular and overtime. This program also includes the The employees gross pay and their take home pay, or net pay. They were added as followed:
public static void main(String[] args) { Scanner reader = new Scanner(System.in) ; // Add variables for later calculations double RegPay; double PayPerHour; int HoursPerWeek; double GrossPay; double OverTimeHours; double OverTimePay; double FedTax; double StateTax; double MedTax; double SSTax; double NetPay; double UnempIns; double FedTaxAm; double StateTaxAm; double MedTaxAm; double SSTaxAm; double UnempInsAm; double TotalDeduct;
//The user will now enter employee specific data //First name Scanner UserInput = new Scanner(System.in); String EmpNameFirst; System.out.print("Enter Employees First Name: "); EmpNameFirst = UserInput.next(); //Last name String EmpNameLast; System.out.print("Enter Employees Last Name: "); EmpNameLast = UserInput.next(); //add user input of first and last name String EmpName = EmpNameFirst + " " + EmpNameLast;
//This is where the user will enter the rate of pay, hours worked per week, Overtime work System.out.print("Enter The Pay Per Hour: "); PayPerHour = reader.nextDouble(); System.out.print("Enter the Regualr Hours Worked: "); HoursPerWeek = reader.nextInt(); System.out.print("Enter the Over Time hours Worked: "); OverTimeHours = reader.nextDouble();
The algorithm for the pay calculations were then added:
//Pay Calculatons RegPay = PayPerHour * HoursPerWeek; OverTimePay = OverTimeHours * 1.5 * PayPerHour; GrossPay = OverTimePay + RegPay; //Tax system input for calculations, hard codded, user will not manually enter FedTax = 0.15; StateTax = 0.0307; MedTax = 0.0145; SSTax = 0.062; UnempIns = .0007;
Also added were the tax calculations, which I hard coded into the program, so that the user did not need to be prompted to enter this information manually. Only employee specific information will ultimately be prompted for, such as name, rate of pay and hours worked.
//Tax Calculations
FedTaxAm = FedTax * GrossPay; StateTaxAm = StateTax * GrossPay; MedTaxAm = MedTax * GrossPay; SSTaxAm = SSTax * GrossPay; UnempInsAm = UnempIns * GrossPay; TotalDeduct = FedTaxAm + StateTaxAm + MedTaxAm + SSTaxAm + UnempInsAm; NetPay = GrossPay - TotalDeduct;
I enjoyed writing this program, as there were a lot of variables or objects I needed to make sure I addressed, before I could complete the calculations. I started with simple calculations are first, which only included rate of pay, hours worked, overtime hours, and the total pay. This ensured I was able to create another working program, based on input and calculations. I then added the rest of the required variables and went line by line, making sure the code was correct.
The final lines of my code are what I needed the program to calculate and print out for the user.
//System output for Pay with Calculations System.out.println("Employee Name: " +EmpName); System.out.println("Your Hourly Rate of Pay is: " +PayPerHour); System.out.println("The Total hours worked at Regular Time are: " +HoursPerWeek); System.out.println("Total Hours of Over Time worked this week are: " +OverTimeHours); System.out.println("Your Gross Pay for the Week will be $ " +GrossPay); System.out.println("Your Total Deductions this week are $ " +TotalDeduct); System.out.println("Your Net Pay for the week is $ " +NetPay); } }
Here are some great links to tutorials, helpful treads, articles, and books that I found helpful for me while learning. I also use a lot of YouTube, which helps also understand as if someone is there talking to me.
References:
Complexity analysis. (n.d.). Retrieved from http://www.cs.utexas.edu/users/djimenez/utsa/cs1723/lecture2.html
Kromkamp, B. A. (2016). Java tree implementation Retrieved December 16, 2018, from http://www.quesucede.com/page/show/id/java-tree-implementation
Lysecky, R., Vahid, F., Lysecky, S., & Givargis, T. (2015). Data structures essentials. Retrieved from https://zybooks.zyante.com/#/zybook/DataStructuresEssentialsR25/chapter/1/section/3
Oracle. (n.d.). Java SE at a glance. Retrieved from http://www.oracle.com/technetwork/java/javase/overview/index.html
Oracle. (2015). The Java tutorials (Links to an external site. Retrieved from http://docs.oracle.com/javase/tutorial/index.html
Oracle. (2015). Lesson: Object-oriented programming concepts. Retrieved from http://docs.oracle.com/javase/tutorial/java/concepts/index.html
Shaffer, C. A. (2013). Data structures and algorithm analysis (Edition 3.2). Retrieved from http://people.cs.vt.edu/~shaffer/Book/JAVA3elatest.pdf
Raymond lewallen. (2005, July 19). 4 major principles of object-oriented programming. Retrieved from http://codebetter.com/raymondlewallen/2005/07/19/4-major-principles-of-object-oriented-programming/
Investopedia. (2016). Return on investment - ROI. Retrieved from http://www.investopedia.com/terms/r/returnoninvestment.asp
Parlante, N. (2016). Recursion-1. Retrieved January 2, 2019, from http://codingbat.com/java/Recursion-1
Queue Interface In Java. (2018, September 07). Retrieved December 12, 2018, from https://www.geeksforgeeks.org/queue-interface-java/
Tutorials Point. (2016). Data structure- recursion basics. Retrieved December 12, 2018, from https://www.tutorialspoint.com/data_structures_algorithms/recursion_basics.htm
No comments:
Post a Comment