|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On September 11 2016 15:19 teamamerica wrote:Show nested quote +On September 11 2016 13:21 Blisse wrote: Also you don't have to make getters and setters unless you need to control access. Just make the members public. The downside is in Java is that if you wanna change it to a method you have to change every callsite. You can argue that in the case you're refactoring a public property into a method that's not a big deal, but other languages let $object.property be either a direct instance variable lookup or a method call.
To be honest while I've heard that argument I don't really feel like this is an issue, besides ease of IDE refactoring, it's just straightforward manual work. If it's an area you already believe will change often you would have already added it as a g/setter. And if it wasn't predicted to be used like this it often requires more thought into what the actual intended usage is. I never felt this to be an annoyance irl.
The only big issue with this is when you're flipflopping between having the g/setters and not having them, which if you're planning well, just means requirements are changing a lot, and should be normal.
On September 11 2016 16:31 spinesheath wrote:Show nested quote +On September 11 2016 12:09 Hhanh00 wrote:In case you are stuck with Java, you may want to take a look at Project Lombok that uses AOP to inject the boiler plate. The java code becomes @Data public class Animal { private String type; private int age; private String size; }
and ends up being the same bytecode. I've looked into AOP but never actually used it. You probably have some actual experience with it. I've always wondered how it affects debugging - you obviously can't step through single lines of code if you never write them. How's that working out for you?
I believe that the annotations are used to compile the annotated class into some generated code before being fed to the actual Java compiler, so debugging should work as normal? I feel like I've done that before...
|
On September 11 2016 06:55 travis wrote:Sensing I needed to review and make sure I understand java basics I wrote a pointless program. I wanted to check that I knew how to write things like equals, toString, getters/setters, constructors, and use inheritance correctly. If anyone has free time could they look at my code and make sure I am not doing anything naughty? Also I have 3 questions about the code (one in particular is important) animal class + Show Spoiler + package life;
public class animal { private String type; private int age; private String size; public animal(){ this.type = "unknown"; this.age = 0; this.size = "unknown"; }
public animal(int a, String t, String s){ this.age = a; this.type = t; this.size = s; } public animal(animal oldAnimal){ this.age = oldAnimal.age; this.type = oldAnimal.type; this.size = oldAnimal.size; } public String toString(){ return ("This is a " + this.type + ", it is " + this.age + " years old, and it is " + this.size); } public boolean equals(Object other){ if(this == other){ return true; } if(!(other instanceof animal)){ return false; } animal a = (animal) other; return this.toString() == a.toString(); } public void move(){ System.out.println(this.type + " moved"); } public void eat(String f){ System.out.println(this.type + " ate " + f); } public void setType(String t){ this.type = t; } public void setAge(int a){ this.age = a; } public void setSize(String s){ this.size = s; } public String getType(){ return this.type; } public int getAge(){ return this.age; } public String getSize(){ return this.size; } }
Human Class + Show Spoiler + package life;
public class human extends animal { private String name; public human(){ super(); this.name = "unnamed"; } public human(String n, String t, String s, int a){ super(a, t, s); this.name = n; } public human(human oldHuman){ super(oldHuman); this.name = oldHuman.name; } public String toString(){ return (super.toString() + " and it's name is " + this.name); } public boolean equals(Object other){ if(this == other){ return true; } if(!(other instanceof human)){ return false; } human h = (human) other; return this.toString() == h.toString(); } public void complain(String c){ System.out.println(this.name + " complains about " + c); } public void setName(String n){ this.name = n; } public String getName(){ return this.name; }
}
"engine" + Show Spoiler + package life;
import java.util.ArrayList; import java.util.Iterator;
public class life {
public static void main(String[] args) { ArrayList<human> humanList = new ArrayList<human>(); humanList.add(new human()); humanList.add(new human("Tim", "mammal", "medium", 25)); humanList.add(new human("Burt", "mammal", "huge", 43)); humanList.add(new human(humanList.get(1))); Iterator<human> iterate = humanList.iterator(); while(iterate.hasNext()){ human thisHuman = iterate.next(); System.out.println(thisHuman.getName()); } for(human h : humanList){ System.out.println(h.toString()); } System.out.println(humanList.get(0).equals(humanList.get(1))); System.out.println(humanList.get(1).equals(humanList.get(3)));
}
}
my questions + Show Spoiler + 1.) my equals method is based on what I was taught in lecture. my question is, what is the point of casting the object type when I am already checking if it is an instance of that object type?
in the specific example in lecture the professor does call an equals method within the equals method - he uses super.equals(other), but even with that example I don't understand why the casting is necessary.
2.) when I call super(oldHuman) in my constructor - what sorcery is this. it seems like magic. is this one of those things that java can "just do" ?
3.) System.out.println(humanList.get(1).equals(humanList.get(3))); is returning false. why? shouldn't this return true?
thank you to any kind souls who help me out
In addition to all the useful advice the others have given you, l personally like took keep the order of my parameters the same. So if in your animal constructor you use (age, type, size), it is best to do so for your human class as well. Also, try to use variable names that make sense. While you can now still remember what a, t and s are, I guarantee you won't recall that when you have to extend or revise your code in a few weeks (or some other poor shmoe has to do that).
Oh, and talking about debugging, do you really need that constructor for humans? Do you ever want humans to be of type "dog" and size "microscopic"?
|
On September 11 2016 15:19 teamamerica wrote:Show nested quote +On September 11 2016 14:44 Wrath wrote:On September 11 2016 11:11 Manit0u wrote:On September 10 2016 22:59 Wrath wrote: Call me a retard but is it normal to waste full day on setting up eclipse with Symfony and run the code against apache httpd server and still not working? First of all, if you're developing with Symfony you don't even need Apache. Symfony has its own built-in server for development purposes if you need one. You can of course still use Apache, Nginx or whatever else you need (for Apache note that Symfony doesn't use .htaccess and you must have proper Require All Granted etc. set in your host settings, you can look those up in the Symfony docs). Second thing is the fact that you should not use Eclipse for that. NetBeans would be better but still shitty. Just for learning you could be using PhpStorm (with super duper mega excellent symfony plugin) in its 30-day free trial (or endless trial if you're a student). Trust me, it's miles apart from any freeware solution. I can't even look at Eclipse or NetBeans after using jetbrains products... I'm not a student and I can't guarantee that the workplace will provide me a phpstorm. That is why I'm trying to get a free IDE... If for some reason work refuses to pay for it I'd really recommend just buying it yourself. Idk if you're not in US but if you are it's pretty cheap; I did that for my first job and I didn't regret it at all.
It was the same for me. I did the 30-day trial to see if it's any good and then simply bought it for myself. The additional benefit is that if I go to work somewhere else I still have my phpstorm since it's mine and not company's. It's a good investment that earns its price back tenfold pretty soon in all the work saved and general quality of life.
And I have no idea how come it's super hard to get a good looking dark theme going on with Eclipse or NetBeans. I simply can't stand working with code on white background (NetBeans takes the cake for dumbest implementation here since you have some potential errors shown as light yellow underline which is pretty much invisible). Displaying all the whitespace characters is also a huge pain in those IDEs.
|
On September 11 2016 16:31 spinesheath wrote:Show nested quote +On September 11 2016 12:09 Hhanh00 wrote:In case you are stuck with Java, you may want to take a look at Project Lombok that uses AOP to inject the boiler plate. The java code becomes @Data public class Animal { private String type; private int age; private String size; }
and ends up being the same bytecode. I've looked into AOP but never actually used it. You probably have some actual experience with it. I've always wondered how it affects debugging - you obviously can't step through single lines of code if you never write them. How's that working out for you?
When the tool generates bytecode directly, you won't have source code but some of the IDE can decompile it for you automatically. Since it's just boilerplate code, it is best stepped over and treated like library code.
|
|
The problem sounds underspecified, but it depends a lot on the size of your arrays. If your match list is small, you can do it that way, and never really have too many permutations to handle. But the number of possible permutations grows exponentially (n! in fact), so it can get intractable pretty quickly.
Another option is to use a sliding window on your target array, and see if it contains all of your search terms. You start with windows of the same size as your search array, and if you don't find any matches, increase by 1 and repeat. Stop when you find a match (which is guaranteed to be (one of) the shortest).
You can start by sliding your window one item at a time, but can speed up the algorithm by skipping windows you know cannot possibly match.
|
Can the lists have duplicate values?
|
|
It's interesting that they're asking problems like that for you to solve this early. That's something that I would expect in a programming interview.
If you're comfortable, I believe using a dynamically-sized sliding window is the "optimal" solution, but it probably involves a few new concepts you haven't learned yet. Using a dictionary/map can help.
|
|
geeze does that really not have flaws because that solution not only sounds efficient but also pretty easy to do
can't really think of any problems with it..
|
Did you consider the possibility that some of the values to look for are duplicates? Would you have to match as many duplicates in the list?
|
Nesserev wins. Far more efficient.
|
I am actually going to edit my posts because I carefully read about academic integrity for our CS department and apparently discussing projects on forums at all is a violation. they are so vague about it
which is complete bullshit since that's basically saying you can't go learn about what you are doing
and anyone could do google searches to find algorithms to do exactly this
but w/e, better safe than sorry
next time I will discuss these concepts in a safer way
and yeah I know this is paranoid but my school is very big and I am sure there are some CS students who go to TL
|
|
it wouldn't hurt I guess
based on other things I have seen professors say this shouldn't really be a violation, but the rules are so vague that I could get screwed over if they wanted
they literally say that it is an academic integrity violation to:
"Using online forums to ask for help regarding our assignments."
which is the vaguest nonsense ever
it's kind of like saying that I can't use online forums to discuss how to program
|
Yeah, academic integrity policy is intentionally vague so that it's a lot easier on them when they provide proof. Generally it's fine as long as you're just talking about the solution and not given exact pseudo/code. All reasonable professors I've seen encourage discussion, just not discussion with code being written.
I've consulted TL for a bunch of things too.
Instead of giving the problem description, you should abstract it one step up. I know it's a bit harder to do since you're starting out, but asking, "how do you find the smallest range of numbers in a list that contains a given set of numbers?" gives essentially the same solutions, and as long as no one is writing out a program for you, it should be fine asking for help.
-----
Actually it's kind of annoying/interesting that a lot of programming questions essentially rely on tricks that you need to learn first before you can actually solve them. Using sets and dictionaries IMO don't come intuitively, but instead from me reading advice that they're generally how to best solve a problem, and then I base my thinking with that in mind. I think the extreme example is being asked to find a loop in a linked list. No way you can reason yourself to a solution.
|
Gentlemen i am inspired.
Inspired by the azarkon mute script, I've been trying to create a version for a completely different forum that accomplishes the same task.
Problem being this is a zetaboards forum and everything in it seems to be contained in endless fucking tables.
Any advice? It shouldn't be that hard if I know what i'm looking for i just don't know where to start.
|
I haven't done much with userscripts before but pretty sure they have easy access to the DOM, so you just need to find how posts are stored in the DOM and then find the element with the username you want to hide, then remove it. IDK if that's enough to go off or you need more specifics though.
E.g.
<tr id="post-8073303"> <td class="c_username"> <a href='http://s9.zetaboards.com/Ultimate3D_community/profile/44616/' class='member'>AZARKON THE GREAT</a><a name='post8073303'></a> </td>
So you just navigate the DOM for anything with id = post-SOMETHING, then within its children, check class=member, check the text for the usernames you want to hide, and if so use whatever DOM manipulation userscripts have to hide/remove the whole post tr.
|
On September 12 2016 06:52 Blisse wrote: Yeah, academic integrity policy is intentionally vague so that it's a lot easier on them when they provide proof. Generally it's fine as long as you're just talking about the solution and not given exact pseudo/code. All reasonable professors I've seen encourage discussion, just not discussion with code being written.
I've consulted TL for a bunch of things too.
Instead of giving the problem description, you should abstract it one step up. I know it's a bit harder to do since you're starting out, but asking, "how do you find the smallest range of numbers in a list that contains a given set of numbers?" gives essentially the same solutions, and as long as no one is writing out a program for you, it should be fine asking for help.
-----
Actually it's kind of annoying/interesting that a lot of programming questions essentially rely on tricks that you need to learn first before you can actually solve them. Using sets and dictionaries IMO don't come intuitively, but instead from me reading advice that they're generally how to best solve a problem, and then I base my thinking with that in mind. I think the extreme example is being asked to find a loop in a linked list. No way you can reason yourself to a solution. I mean, I'm not particularly good, but couldn't you just put the pointer values of each node in a dict when visited, and if you come to a node already in the dict, then you've got a loop?
|
|
|
|