#Can someone cheak if I did "netPay" caculations right before I printed it
1 messages ยท Page 1 of 1 (latest)
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
i think 111.672 is how much is taxed
meaning 18% taken off of gross is your net pay
no
it should be 82% (100% - 18%) of your gross pay
yes
yes but the tax isnt 82%. your net pay is 82%
do you understand why?
so can you tell me what your tax should be
cool you got it. can you rewrite your code so that it reflects what you've told me?
whatever you feel comfortable with. the output of the application should still be a dollar amount however
you have to subtract the tax to get net pay
closer
right now your gross pay and tax numbers are different units. gross pay being dollar amount and tax being a percentage. how would you get the total amount of tax you pay?
so net pay is gross pay - total amount of tax
right now tax is just a percentage point
do you know what 10% of 100 is?
no the total tax is 18% of your gross pay
how do you know 10 is 10% of 100
ok so how would you get 18% of your gross pay
not exactly, the would be true if gross pay was 100 but it's not. what did you get for your gross pay?
right so how would you find 18% of your gross pay?
i dont think that would be relevant to the question. remember how you found 10% of 100. 100 isnt a percentaage in this example
suppose u have 10 pieces of cake and ur friends want to eat 20% cake. how much percent cake is left for u and how many pieces are that?
right!
10 pieces are ur gross cake.
20% is the tax deduction
and 8 pieces are ur net cake
so what math do u do to 10 pieces of cake to get to the 8 pieces?
(by involving ur 20% tax rate somehow)
that gives u 2. not 8
what else did ur brain do to get 8?
what concrete math formula/steps did ur brain apply when it was told "10 pieces net, 20% tax"
to get to the conclusion that it's 8 pieces gross
cmon ur so close. finish it off
so can u write down a concrete formula?
what if i say x pieces and y% tax
can u write it down instead of just explaining it with text?
give me math
but when i write 100 - 20 i get 80
and not 8
give me a concrete math formula
that involves x and y
% is not sth u can write in a concrete formula
and its also still incorrect
okay. let's step back and do another example
and this time take a close look at how ur brain does it
lets say u earned 300$ gross and the tax deduction is 25%. what's ur remaining net pay?
tell me the concrete dollar number
yes
so. now put it together into a single formula
write it out
that's still not something ur computer could understand
not yet
but I'm trying to walk u there. but somehow u try to resist it
see, i told ur brain the numbers 300 and 25
and it spit out 225
i want a single formula where i see the numbers 300 and 20
which results in 225
so all the math ur brain did, concrete in a single formula
without buzzwords. concrete
i dont see 300 and 20 in that message
gimme a formula that contains 300, 20 and = 225
yeah sorry
for example 300 * 25 = 225. but thats wrong
or 300 * (100 + 20) = 225 but thats also wrong
i want to see sth like that
but the correct one
put it into a single formula please. not two
use brackets (...)
i dont see 25 in that line
and no (...), which u will need as well
300 * (... 25...) = 225
try it more like this
we are getting closer though
awesome. now, technically i said 25 and not 0.25
yeah
well, u can't write %
but u could still write (100 / 25)
which gives u 0.25
300 * (1 - (100 / 25)) = 225
sooo. now we can make it dynamic
replace 300 by x and 25 by y
and u have the formula
and that's sth u can actually put in code now
sth that ur java actually understands
netPay = grossPay * (... taxRate...)
sth along those lines
try it out with our example
300 and 0.25
if its 225 its right. if not, it's not
don't just randomly code something. u always have to grab a concrete example and first play it through on paper or in ur head. only then u can compare ur code against it and debug effectively
๐
it says 75
but the correct net pay would be 225
so ur code is incorrect still
execute ur code by hand
plug in the values
u will immediately see where it's wrong
like, take ur line 18 and plug in all the values. it will jump in ur face once u do
ur probably not entering the paranthesis correct in ur calculator
that said, thats not what ur code does anyway
ur missing a closing )
and it's 25 / 100
not 100 / 25
do the math by hand. one gives 4. the other 0.25
indeed
no haha. I'm sitting here in my bed, falling asleep
happens. but u have to learn how to debug small mistakes like that by just running through the example step by step
take ur code and plug in the values
netPay = grossPay * (totalPercent - (tax / totalPercent))
now put in the values
netPay = 300 * (1 - (0.25 / 1))
u might note that / 1 is absolutely obsolete
yeah. but u can remove that / 1
well. u wrote / 1
something divided by 1 doesnt change it
that division was only necessary if we work with 25 and 100 and not with 0.25
aaay u got it ๐
now restore ur grossPay computation with the hours and ur done ๐
looks good 
lol no worries. it always takes a bit when doing sth new
did you get it?
what do you mean a "duplicate" of a class? like a subclass of it?
or create another instance of the class?
maybe if you say what you're trying to achieve i can help you better
do you mean literally just copy and paste the source code of the class?
would copying and pasting the file itself be fine? cuz then you can just change the file name and change the name of the class accordingly
but i'm not sure why you'd need to make a duplicate of the source code itself
technically you could also copy the entire class and paste it in the same file and just change the name of the copied class and remove the "public" modifier and it wuld work just fine
though having two top-level classes in the same file is generally frowned up unless you have a good reason to do it as far as i know
but may i ask why you need to duplicate the source code?
i feel like you could just extend the class, no?
the bonus?
you could do that in the same class
is it a requirement from the course that you must have two classes?
one specifically for the bonus?
well technically theres not stopping you from doing that but it kinda of defeats the purpose of using an object oriented language
you can do everything inside the same class just fine
if you really want to compartmentalize the logic you should extend the first class, not copy the source code
are you familiar with inheritance?
subclassing
basically it lets you create a class that can do everything the first class and then build more things on top of it
in my opinion yes, the code isn't that complicated that you'd need to make multiple classes for it
plus if you haven't learned about subclassing yet it might not be very productive to do it
though you wouldn't even necessarily need to subclass the first one, just dealing with two classes at once would increase the complexity since it seems you're not familiar with managing the flow of information between multiple classes
well you already found a way to calculate the netpay right?
it doesnt have to
the bonus says each bubble teas adds to her total netpay, right?
so think about it, lets say you worked at a place and they paid your salary, then you paid your taxes and were left with your net salary
but you also sold some candy on your free time
since you dont have to pay taxes on the income from the candies, how would that income affect your total earnins for the month?
well its fine to do that if you just want to have the first version for backup
just do like i said, copy the class and paste it then change the name and remove "public" modifier
or create another file
but you changed the logic of the calculations
its no longer calculating her netpay from her job
and its calculating the price of the bubble tea as 15.51
then adding 3 dollars to the final amount
i think the bonus wanted you to keep the netpay amount she had received, and then calculated how much money the bubble tea sale would add
not exactly
you should scrap those changes and start again with the last class before the bonus
since you changed the logic way too much and you'd have to undo all the changes you made anyway
ok
so try again but this time dont mix the logic of calculating the netpay from her job and calculating the amount she earned from bubble tea sales
no
you will need to calculate her netpay from the job no matter what
and you are already doing that correctly
so no reason to do it again
the no tax is specifically for the bubble tea sales
her salary still gets taxed
not really
the salary gets taxed, the bubble tea sales dont
try this: just ask how many bubble teas she sold, then calculate how much money she'd make from the sales
dont do anything to the salary calculation
you do
you don't need to include any tax when calculating the income from bubble tea sales
yes sales from bubble tea are added to the netpay you ALREADY calculated
the netpay is already done, already taxed
now they want to know how much more she'll make from the bubble tea sales
and those sales arent taxed
try doing what i suggested, ask her how many bubble teas she sold then calculate how much she would make
from the sales
to make it easier, dont touch the first part of the code at all
just add more code do these things at the bottom
yes
go to the two closing curly brackets and just above them add more lines
then start coding the logic of the bonus calculation]
ALMOST
you're close but you arent calculating the total income from the bubble tea sales
you're just adding 3 dollars
well what do u need to calculate? total income
what is the formula for te total income of something?
if i sell X amount of bubble teas, and each bubble tea costs Y dollars, how do i calculate the amount i make
x * y
does that answer your question?
try the code now
yes
thats not it
you aren't calculating the income from the bubble tea
notice the teaSold variable was never used
very close
just needs some final adjustments
you calculated the income from bubble tea right?
now you need to add that income to the netpay you calculated from the salary
but right now you're replacing the original netpay with the income from bubble tea
so you're replacing one with the other
so if you do it the way you did you cant add them anymore
unless you calculate netpay again or change the order of the operations
can you find a way to calculate the income from the bubble tea sales without deleting the value of the netpay from the job?
well what do you do when you want to store the value of a calculation?
yes
but right now you're using the variable of netpay so you replace the calculation from the salary
so you cant add them together anymore
well you need to assign a variable but you cant use netpay, so what do you do?
yes
well you could call it anything you want but i'd pick something more specific
like salesIncome
yes but now you can calculate the total amount from her salary (netpay) and the bubble tea sales income
can you add them together?
yes
yes
the result is perfect
but you should probl give it another variable for the final result
totalIncome would be fine
yes
well you could change the texts to reflect what is being displayed
but yeah the code is correct
no
the text "net pay of bubble teas sold"
the value being displayed is something else so change the text to reflect that
no
the value being displayed is the total income for entire month
including all sources of money for that person
hr salary and bubble teas sale
yes