• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Homework help

 
Marshal
Posts: 80867
505
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hadn't noticed you had marked the fields public; that is usually a serious mistake and they should be private.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Dylan Stout wrote: . . .

For better to give the sales person class a proper toString method then you can simply write
System.out.println(grab);
What a strange name to use, grab.



How do you go about in doing this?
 
Campbell Ritchie
Marshal
Posts: 80867
505
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Same way you write a toString method for anything elseThat is one way to create the String; there are lots of others. Look at the documentation for the Object class.
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay I am stuck again with pulling the table to the main. Not that I haven't asked for a ton of help already, but I would be very thankful if someone could explain how to do this.



I have to have the table then use an array or array list comparing the 2 salespeople. I am fairly certain the calculations in the table are correct, but please let me know if they are not.
 
Campbell Ritchie
Marshal
Posts: 80867
505
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remove all that code from the main method. It belongs somewhere else.
What table? Do you mean the List which you posted about earlier? Which class is that in? Do you have a SalesDepartment class or Company or Salesforce or anything? If not, why not?

Did you try testing code similar to what I posted? What happened? Did it show your salesperson class working?
Have another look at your salesperson class. It has some stylistic problems. The variable names and field names are not at all clear. Don't write money which is really vague, and money2 is even worse. Remove the keyword public from every field. All private. One empty line between successive methods please.

Never never use floating‑point numbers in loop headers. If you want to find out why tell me how often this loop will run. Hint: the value of the double representing 0.1 is very slightly greater than one‑tenth.Why does your salesperson class not have an overridden toString method? When you sort out all those things in the salesperson class you will be able to write a sales department or similar class with the List in. An object of that class would create and print any tables.
 
Mona Stout
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the main (with nothing in it)


Here is the person and calculator classes.


All the code has been taken out of the main. Nothing runs and there are a ton of errors. I keep trying to tell myself that I was introduced to Java less than a month ago and that I will get it, but right now with everything I do being wrong, I am not so sure.
 
Campbell Ritchie
Marshal
Posts: 80867
505
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where did you put the code which used to be in the main method? You should simply have deleted it, not put it elsewhere. You can always retrieve it from this thread is you need it later. Line 52‑58 should not be there. Similarly 85‑90, 101‑106 etc. Because you have that code in {} you have converted it to instance initialisers which will run whenever you try to instantiate that class.
You will never get the main method to compile with a ; you have to write {}. And what should go in the main method? Well, start with the testing code which I posted about a million years ago. You can always delete it later when you work out what should be in the main method. Hint: it will look like this:-All fields need private access. You have two Strings which aren't private.
You have not improved the names of your fields. Things like name2 are confusing.
Don't double‑space your code.
Do put one blank line each between successive methods.
Put your different classes in different files, unless you have some reason to make them nested classes.

Revert your Person class to what it was when it compiled; I think the code you have added to it has added the compiler errors. Then make the corrections I suggested. Put that testing code in the main method.

Work out how to design a Commission class.
 
Mona Stout
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) Is this better on naming the fields? I also changed everything to private.
2) Lines 22 - 36 (private double incentive) I am not sure if this belongs here as it is more of a check to see if the SalesPerson made more than the required 120000 and if they did they get an additional 1.25%.



3) Is this correct as the percent and targetsales will not change?
 
Campbell Ritchie
Marshal
Posts: 80867
505
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, and no.
It is now obvious what your mistake is, which I could not tell earlier. You appear to have a person class, but you are trying to get the details of two people into the same object. Don't. Remove all suggestion of a second person from that class. That does not fit object‑orientation. If you want two people you create two instances of the same class. Those will go into your List/array which you mentioned earlier.

If you think the percentages will not change, make them constants. Only make them public if you think they will be required as constants outwith your class. This is an example of a public constant because its value might be required anywhere. The following will probably be private:-
public/private static final int MAXIMUM_MARK = 100;
 
Mona Stout
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) I have taken out the second person.


2) I am on information overload as it is with ya'll teaching me things that have not been covered in my book yet so I will leave the percent and targetsales as is for now. (if that is okay)
 
Sheriff
Posts: 9021
656
Mac OS X Spring VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mona Stout wrote:I will leave the percent and targetsales as is for now. (if that is okay)

1. There is no reason to leave them as they are at the moment. You need to fix them.
Usually these "set" methods takes some passed arguments in. It does not appear in your case.
Example how they should look like:
2. Also it seems you didn't follow Campbell's suggestion yet about the empty line in between successive methods, so the code would be more readable.
3. Your variables are quite poorly named, I think Campbell Ritchie mentioned that too. Variables like: percent, inputString, EmpName, EmpSalary (last two suppose to start with lower case).
 
Mona Stout
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is now the error I am getting since I changed to the below example; Error "cannot find symbol, symbol: variable empName" this error is the same on all of the names now.

How do I fix this error?

This is the code with the spaces. At least I think I have it right now.


Also,

... I will leave the percent and targetsales as is for now. (if that is okay)


I said this because

I am on information overload as it is with ya'll teaching me things that have not been covered in my book


All total meaning that if the program will work with it the way that it is then I would like to leave it as learning something new right now would put me further behind. It is not that I do not care, it is that this is a beginners class and ya'll are sooo much more knowledgeable and trying to pass that information along is wonderful and a bit overwhelming :-)
 
Campbell Ritchie
Marshal
Posts: 80867
505
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for overloading you. Particularly if you have to cook dinner for that Dylan Stout chappie while reading the forum. But the sooner you get into good habits, the better.
 
Mona Stout
Greenhorn
Posts: 29
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That was a low blow. I work 60-70 hours a week, have a family to take care of, and I am going to school. I have been learning since 8/11/15 and you have been doing this for a minimum of 10 years. Yes, I agree that good habits should start at the beginning.

A friendly place for programming greenhorns!

is the motto here. I have taken everything that you have told me and tried to understand stayed up until 12:30 -1 am when I have to get up at 4:30am to go to work and you make fun of me for saying that it is a bit overwhelming. Instead of doing that it would have been nice if you would have taken line at a time and explained what was wrong, why it was wrong, and how to improve it. I have read dozens of articles trying to understand your higher level knowledge base and was just trying to ask you to keep it on a simpler level. Thank you
 
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mona Stout wrote:This is now the error I am getting since I changed to the below example; Error "cannot find symbol, symbol: variable empName" this error is the same on all of the names now.

How do I fix this error?



Basically, the compiler is complaining that you are trying to use a variable named "empName", but the compiler can't find it declared anywhere. Looking at the SalesPerson class source code, in the same post, which I did not quote for brevity, the compiler is correct. You did not declare that variable anywhere.

Henry
 
Mona Stout
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, after I added

that took away the error. I had it originally, but must have deleted it.
 
Henry Wong
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mona Stout wrote:Thank you, after I added

[CODE DELETED]

that took away the error. I had it originally, but must have deleted it.




To be honest, I don't see how that change would fix the error. You obviously did more than add lines to that constructor.

Henry
 
Mona Stout
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Henry, honestly I may not have opened and corrected the right file I have so many now.
I have been working on another that was converted from JOptionpane to Scanner and I know it probably has really poor coding but it works with the exception of the final requirements.
"The application will now compare the total annual compensation of at least two salespersons.
It will calculate the additional amount of sales that each salesperson must achieve to match or exceed the higher of the two earners. In the array"

This is the main.


This is the class that everything is in (sorry it is all crammed into one)


Again I know it should be broken into more than one class, but it should have been turned in on Saturday and I got an extension until 8pm. Please do you have any suggestions?
 
Henry Wong
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mona Stout wrote:Please do you have any suggestions?



This latest code is completely different than for the code that I was answering for. So, I do not have any context regarding the error/issue that you are encountering. Do you have a question related to this set of code?

Henry
 
Mona Stout
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It works and has no errors, but I do not know how to work in the final requirements which are;

"The application will now compare the total annual compensation of at least two salespersons.
It will calculate the additional amount of sales that each salesperson must achieve to match or exceed the higher of the two earners. In the array"

 
Henry Wong
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mona Stout wrote:It works and has no errors, but I do not know how to work in the final requirements which are;

"The application will now compare the total annual compensation of at least two salespersons.
It will calculate the additional amount of sales that each salesperson must achieve to match or exceed the higher of the two earners. In the array"



Unfortunately, we are not allowed to do your homework. It is against the rules of the ranch. See... https://coderanch.com/how-to/java/DoYourOwnHomework

You will need to actually do it yourself. And if/when you run into an issue, we can help address the issue. And even then, it has to be in the form of hints to help you on your path.

So, back to this question. What have you tried? Or what confusion are you running into while trying to figuring out how to get to the requirements?

Henry
 
Mona Stout
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not looking for someone to do it for me.

Something along the lines of look into: if-then-else, boolean, or while-loop would be the best option here. Oh btw you should insert that before/after .... for the best working option.

That was basically what I was looking for.

I am sorry if this comes across as ungrateful I am just very frustrated with not being able to do anything right.

Oh sorry I did not answer your question I have tried the boolean above mentioned with what is described in my school book. ie boolean arrayEqual = true which did not work so I just deleted it. Now I am trying to find a better option.
 
Mona Stout
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I tried the following before System exit.


but that compares the last compensation of each person from the table, which is not the right thing to do.
 
Liutauras Vilda
Sheriff
Posts: 9021
656
Mac OS X Spring VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mona, it's been a long thread, I'll be honest with you - you should concentrate a bit more, read some theory, might go again through all module slides, might read the book again, otherwise I don't see the chance for you to understand the topic and pass the module.
 
Mona Stout
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The module was over with this last portion.

Thank you for all the information you gave me to look up and work on.
 
Campbell Ritchie
Marshal
Posts: 80867
505
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am very sorry to have caused offence, which I did not mean to.
 
Mona Stout
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Campbell Ritchie - Thank you. The information that you and Liutauras Vilda gave me was very helpful though at this time I may not understand all of it. I am working on it and will be practicing. One thing I have noticed is that everyone codes differently and I think that you would be terrified at how it is being taught in some classes such as mine. I truly appreciate all the time and effort you spent helping me try and learn a better form of coding. I will keep you posted. I will to ask more questions, post new code, and get frustrated all over again. I am not giving up. Thank you very much.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mona Stout wrote:Campbell Ritchie - Thank you. The information that you and Liutauras Vilda gave me was very helpful though at this time I may not understand all of it. I am working on it and will be practicing. One thing I have noticed is that everyone codes differently and I think that you would be terrified at how it is being taught in some classes such as mine. I truly appreciate all the time and effort you spent helping me try and learn a better form of coding. I will keep you posted. I will to ask more questions, post new code, and get frustrated all over again. I am not giving up.


Good. And you're very welcome; this is what we're here for.

My only worry about your current situation is that you said in a previous post that you work 60-70 hours a week AND have a family to take care of - which presumably means that you're doing a programming course ON TOP of all this. And that doesn't sound to me like a good mix.

Programming is NOT simple. It just isn't. Not even for intelligent people who do it as their only course; let alone with the extra workload you seem to have.

So my advice is: don't expect too much of yourself, and StopCoding (←click) - in fact, don't even START coding until you understand the problem you're trying to solve.

For most of us "experts", coding is the LAST thing we do, and we only do it when we know we have a handle on the problem, and all we need to sort out is the best way to translate it into Java (or C/C++ or Python or Ruby).
If I can't tell you what a prime number IS in English (or your native language), I will never be able to write a decent program to generate/find/get the next one.

Even if it doesn't always sound like it, most of us have been through the frustration you are (in my day it was called FFS - Flat Forehead Syndrome - but that was back when terminals had glass screens), and I hate to say, but it ain't going to get any better. The only difference will be the level you get it at.
And the only satisfaction you can expect is when you get it RIGHT - the "Wahoo" or "Eureka" moment - and for me, that's still enough to keep me going; even though I have maybe two friends left that I can share it with.

For more info, read this article. It'll either daunt you or motivate you - hopefully the latter.

Winston
 
Campbell Ritchie
Marshal
Posts: 80867
505
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We see Eureka moments here regularly. Not so much in ourselves as in the learners. And they are always worthwhile
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic