Featured Post

Post #5 – Computers in the Workplace

"In Post #5, you will describe the functions of computers in your chosen industry, based on your current understanding of IT, your exp...

Thursday, January 10, 2019

How to apply algorithmic design and data structure techniques in developing structured programs - for Noobs.

For our final interactive assignment, we were asked to create a second blog post. Similar to our first one, we once again are writing a blog as a “newbie” JAVA programmer, for a “newbie” JAVA programmer. Included in this blog are several algorithms and data structures to assist a new programmer with developing a structured program. I have chooses a few key points which I found very helpful, as well as snippets of code and helpful screen shots. This way, in addition to an explanations, anyone reading my blog will also have visual help, and if they so choose, the ability to take a portion of the code to post into an editor and rework for themselves to use. 

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;



after adding my scanner and objects, it was then time to enter the code which will allow the user to enter data. I choose to use a scanner, as this allowed me to easily ask the user to enter data, as well as keep my strings for calculations. the code for user prompted data is as follows:

//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); } }



I simply used my own information so you can see what the user entered, above in green, and the rest is all the output of the program we put together. You can change the information, as you like. If you know all the employees are working 40 hours and you just need to ask the user for the over time hours, you can hard code the 40 in there, and only prompt for the hours worked over 40 at time and a half. if a holiday occurred you can also add the lines in to ask about holiday pay, and enter the code to calculate holiday pay, for instance double time on the holiday and time and a half the day before. 

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