0

Why is this code not working? (Solved)

I'm kind of a noob here, and I just can't figure out what's wrong with my code, if someone could please help I'd really appreciate it (sorry if the code is way to messy). https://code.sololearn.com/cg6dvjg5cdmr/?ref=app

11th Aug 2019, 2:15 PM
David R.L.
David R.L. - avatar
6 ответов
+ 2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Employee{ public double salary = 2200; public string name = "jesse"; public int age = 50; public double taxes = 200; public Employee(){ } public Employee(double salary, string name, int age, double taxes){ this.salary = salary; this.name = name; this.age = age; this.taxes = taxes; } public void Status(){ Print.PrintStatus(this); } } class Print{ public static void PrintStatus(Employee x){ double money = x.salary - x.taxes; Console.WriteLine(
quot;{x.name} is {x.age} and his salary is {x.salary}$ and his taxes are {x.taxes}$, meaning he gains an avarage of {money}"); } } class Program{ static void Main(string[] args){ Employee josh = new Employee(); josh.Status(); } } is this what you wanted? 😅 (I don't use cs, so it probably is really bad, but it works now ... 😄)
11th Aug 2019, 3:10 PM
Anton Böhler
Anton Böhler - avatar
+ 1
It works great, thanks! But what exactly did you do to fix it? Thanks a lot 😊
11th Aug 2019, 3:25 PM
David R.L.
David R.L. - avatar
+ 1
quite some things .... the first thing was I added a construtor without any arguments/parameters, since your trying to make an Employee without any arguments given. I also restructured the code. I made the variable 'Salary' to 'salary' so that it was consistent. I made all attributes public so you could access them in the Print-class I also called the function Status of 'josh' so there would be output thats all 😅
11th Aug 2019, 4:26 PM
Anton Böhler
Anton Böhler - avatar
+ 1
I completely forgot to call the status function 😅
11th Aug 2019, 4:28 PM
David R.L.
David R.L. - avatar
+ 1
perhaps make all attributes private and use getters
11th Aug 2019, 4:30 PM
Anton Böhler
Anton Böhler - avatar
+ 1
Yeah, I added that to the fixed code
11th Aug 2019, 4:31 PM
David R.L.
David R.L. - avatar