Hi I am New To Go Code Could You Please Help Me To Get This Done ?
1)Consider the json file containing employee id,name and salary and write a program to calculate the total salary paid to the employee.(display on webpage)
2)Consider Above Scenario and. Write a program to display the employee details containing the salary more than 5000(on webpage)
It looks like somebody (your teacher?) gave you an assignment to solve. It also looks like you have been given some code that implements JSON parsing and writing a HTTP response.
Now it is your task to implement the rest, we are not going to do it for you. What have you tried to
calculate the total salary paid to the employee,
display the total salary by writing it to w,
find the employee details containing the salary more than 5000
i Just Coded Above But I am unable to implement that logic with json so i posted here.i am learning go these are just to test my codingand i thought you guys will help not to judge the situation right.
This is quite easy. You already have emp and emp.Salary. Now define an int outsinde the for loop to sum the salaries. Inside the loop add the salary to this sum. Outside the loop write the sum to w. That would be enough to implement the first part of your assignment. Try it!
Sure. But I already know how this works. You learn by trying yourself, making mistakes, fixing errors. You do not learn by watching me solving your problem.
Therefore we try to give you some hints to get the code written yourself.
Basically, what I asked you to write, is the first step top properly summing up your JSONs salaries. Its just changing the type of s and how you access it.
When you have that sum ready, converting it to a string and writing and back to a stream becomes trivial.
Filtering a slice for step 2 is about as trivial as summing it up in the first place after one has understood how to properly work with slices.
And again, converting it to a string and writing this to a stream is trivial.
If though you have special design considerations for your web page, you need to ask in another forum that is more into web design.
Programm is not about just solving problems. It is about breaking bigger problems into smaller ones and solving them piece wise.
The problems you have to solve in order:
Sum a slice of numbers
Sum a slice of structs with a given field you want the sum of
Convert a number to a string
Write a string to a Writer
Filter a slice of numbers
Filter a slice of structs
Convert a slice of structs to a string
See 4.
If though you still insist on other people writing yyour code, I think #jobs is the place to go, but you will probably not learn much that way.
Just for your information, Google found an answer to summing up the slice of numbers in less time that I’d need to actually copy and paste that solution into a post and format it.
Of course you need to know what to search for, but I’ve given away the necessary buzzwords not only in this post but through the whole thread.
Remember we are all doing this in our spare and free time, and we have been were you are as well, and believe me, I were not where I’m now, getting paid a full-time salary for a halftime job, if I only copy pasted solutions without ever thinking about it.