The Big Programming Thread - Page 815
Forum Index > General Forum |
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. | ||
![]()
tofucake
Hyrule18968 Posts
| ||
Yurie
11680 Posts
On December 13 2016 23:02 tofucake wrote: Usually homework programs like that have a UI supplied by the professor/TAs exactly so that automated tests can be written, and the assignment is to make all of the programmatic logic. Our previous phonebook had a defined UI with exact menu options and buttons we should add. The Sudoku one or calculator we are doing now does not. It has pretty loose requirements as well things like it could be textfields on tilepanes. The only requirements is that there should be a solve button, clear button, it should work, it should show a sudoku board and should tell the user if it isn't possible to solve. Testcases are pretty clear, is why I could include the two that took longest to enter as buttons to get it done faster. After that there are like 20 things they should consider when reading the code and grade on (which I did not read). Test cases (roughly translated and shortened) + Show Spoiler + 1. Hit solve on empty board, see that a correct sudoku shows up. 2. Test three cases and that it can't solve when it shouldn't. Two 5's on first two places in first row. Two 5's on first two places in first column. Two 5's in the first 3x3 grid. 3. First grid 123 456 Second grid 000 000 007 Should not solve, remove 7, should solve. 4. Two 5's in first row, not in first grid. Should not solve. Clear. Should solve empty board. 5. Board in my previous code resulting in correct solution. 6. Wrong inputs, -1, a, 10, 0 I think me using and showing 0 as empty cell value is incorrect but the only thing that says that is the mock up pictures not the text. I assume that is easy to fix if they complain using .clear() on textfields and an if that sends a 0 to the solver if the textfield is blank or 0 instead of always keeping it 0 as now. | ||
phar
United States1080 Posts
| ||
enigmaticcam
United States280 Posts
| ||
Blisse
Canada3710 Posts
On December 14 2016 07:42 enigmaticcam wrote: .NET question. I have a client program that copies a file to a server via windows UNC, e.g. \\servername\directory. Sometimes the file is very large. I'd like to be able to zip it first, send to server, and unzip on server. Is there any way to do this? I can't see that it can be done without having some type of service on the server to do it. I figured you can't, that any zipping/unzipping function would have to be performed on the client, but thought I'd ask just in case. .NET has a compression library System.IO.Compression if that's what you're looking for. Idk how you're doing the file transfer and reception but a good transfer library should support compression in its options. | ||
Yurie
11680 Posts
On December 14 2016 02:32 phar wrote: Was there a given lower level non GUI interface that you had to implement? Or does your prof just hate your TAs? Hate the TAs. The previous 6 were all well defined like you asked for, classes we had to complete, GUI for done classes and things like that. JUnit tests were even supplied for 4 of them beforehand. Since this is the last one they wanted us to do it from scratch. Their method for grading is peer review into a quick go through with the TA. There is a 2h block where we are supposed to turn it in with up to 11 people/groups so they know it takes time to do. Mine is only 7 people since it is the last group with the spill over and there usually are 2 TAs at them, so shouldn't be too bad for them. | ||
3FFA
United States3931 Posts
On December 13 2016 16:48 3FFA wrote: What are some good I MEANT to say IRC, not Discord! Lol whoops! | ||
Isualin
Turkey1903 Posts
| ||
Deleted User 101379
4849 Posts
| ||
Manit0u
Poland17187 Posts
On December 15 2016 04:32 Morfildur wrote: On the topic of Java. Does anyone have experience with any HMVC web frameworks? I really dislike MVC since I've learned how HMVC works, but all the web frameworks in java seem to be purely MVC based or do HMVC terribly. I've adapted Spring to do HMVC with a few ugly workarounds and replacing it's whole routing, so at least that works, but I'd rather have something that does it out of the box. There's Scope but it hasn't been updated in 3 years... | ||
Deleted User 3420
24492 Posts
And therefore I flood the forum with review questions. Let's start with this one. (all questions pertain to java if they require code) "What technique is used (instead of looping) to create a server that can efficiently handle numerous clients?" I have no idea. sockets? threads? | ||
Birdie
New Zealand4438 Posts
On December 15 2016 09:42 travis wrote: It's that time. That time where my final exam is tomorrow. And therefore I flood the forum with review questions. Let's start with this one. (all questions pertain to java if they require code) "What technique is used (instead of looping) to create a server that can efficiently handle numerous clients?" I have no idea. sockets? threads? Sounds to me like it's asking for threads, looping means everyone basically just joins a queue and you loop through their requests one by one which is horrible compared to threads. If a server has a thread for each client it is far more efficient than any loop-based method. | ||
RoomOfMush
1296 Posts
On December 15 2016 09:47 Birdie wrote: Sounds to me like it's asking for threads, looping means everyone basically just joins a queue and you loop through their requests one by one which is horrible compared to threads. If a server has a thread for each client it is far more efficient than any loop-based method. Well, depends. I bet with an average of like 3 clients the loop would be far more efficient. Context switching is expensive. | ||
teamamerica
United States958 Posts
On December 15 2016 09:42 travis wrote: It's that time. That time where my final exam is tomorrow. And therefore I flood the forum with review questions. Let's start with this one. (all questions pertain to java if they require code) "What technique is used (instead of looping) to create a server that can efficiently handle numerous clients?" I have no idea. sockets? threads? Sounds like callbacks/event driven programming. Example epoll/kqueue vs select. Select takes linearly more time per client as more to go through in select loop - epoll/kqueue are O(1) growth. Weird kinda question to have depending on what the class was like. You can read some example such as https://docs.oracle.com/javaee/7/tutorial/servlets012.htm to understand why this asynchronous style might be more scaleable in a Java context. You can also read for well known example http://www.kegel.com/c10k.html. On December 15 2016 09:47 Birdie wrote: Sounds to me like it's asking for threads, looping means everyone basically just joins a queue and you loop through their requests one by one which is horrible compared to threads. If a server has a thread for each client it is far more efficient than any loop-based method. Event driven programming is explicitly to avoid thread/client although threads are pretty cheap, it's obviously cheaper to have M threads for N>M clients rather than N threads per N clients. | ||
Deleted User 3420
24492 Posts
here is a few i missed on my first exam "when does a non-static initialiation block run" I answered: before anything else, including the main method I got this wrong. When I do a google search on this, I find many different answers. So what is accurate? Okay now let's go over typecasting. I had so much trouble on this on the first exam, it confuses me so badly. Let's look at it's example, where Fish extends Lifeform, and that Plant also extends Lifeform.
So what do you call each part of this line Is it "Type variablename = new object from class" ? Ok anyways let's move onto the questions. Each one you have to answer "won't compile", "throws exception" or "works fine" 1. Plant a = x; //x is a fish, no relation to plants, I say this won't compile 2. Plant b = (Plant) x; //x is a fish, I put it won't compile on the exam and missed it. correct answer is it throws exception because It compiles because of the cast to plant? 3. Lifeform c = fish; //I put this works fine on exam and got it. So, you can downcast fine when instantiating? 4. Fish d = (Fish) life; //I put throws exception.. I got that right. This doesn't work? then what is the point of casting? 5. Fish e = (Fish) x; // Oh I guess this is the point of casting. For when the object was typed as the super but an instantiation of the subclass. so this works? 6. Plant p = (Plant) fish //I think this doesn't compile because fish is of type fish which is unrelated to plant Now it says "assume there is a methhod called move in the Lifeform class that has been overridden in the Plant class."
Which version of the move will run. Lifeform version, or Plant version I put lifeform version and missed it. So the rule is what? That the version of the method that is ran is based on the object that was instantiated and not the type it was cast to? But that's the opposite for when you want to look at it's field values, right? Now it has the question
Which of these could you pass in as a parameter 1.) Fish 2.) Plant 3.) Lifeform 4.) Object I put 1, 2, 3 and got it right. So you can only pass in the class and subclasses? What if I tried to put in a subclass of Fish as a parameter. Would it work? Okay now it says we have an arraylist "list" of type LifeForm. Fish have a method called swim. using a for each loop, call the swim method on all the fish. Do I do this(i missed this on the exam so I am unsure):
so yeah I missed this. They tell me to do "instanceof cast". Where am I doing an instanceof cast? Also they crossed out my "Fish" after the for. What is the correct structure for this? Is it
thanks... that's all my questions from exam 1 | ||
Nesserev
Belgium2760 Posts
| ||
Deleted User 3420
24492 Posts
so the answer is "when the class is first loaded" But... what does that actually mean? When are classes loaded? | ||
Deleted User 3420
24492 Posts
Calculate the maximum number of edges possible in a directed graph with n vertices (no edges lead from a vertex to itself) Each vertices leads to (n-1) other vertices. But for each new vertices we can use 1 less of those edges. (n-1) + (n-2) + (n-3) .... + (1) + (0) 5 vertices this is 4+3+2+1 = 10 6 vertices this is 5+4+3+2+1 = 15 Is the answer N(n-1) / 2 ? I put n(n+1)/2 on the exam and missed it ![]() oh wait no I did this wrong didn't I. Each node connects to n-1 other nodes it's n(n -1) ... no over 2 is n(n-1) correct? This probably doesn't matter I don't know why I am distracting myself | ||
Blitzkrieg0
United States13132 Posts
On December 15 2016 23:46 travis wrote: "when does a non-static initialiation block run" A non static initialization block should run when the constructor is called On December 15 2016 23:46 travis wrote: Okay now let's go over typecasting. I had so much trouble on this on the first exam, it confuses me so badly. Let's look at it's example, where Fish extends Lifeform, and that Plant also extends Lifeform.
So what do you call each part of this line Is it "Type variablename = new object from class" ? Ok anyways let's move onto the questions. Each one you have to answer "won't compile", "throws exception" or "works fine" 1. Plant a = x; //x is a fish, no relation to plants, I say this won't compile 2. Plant b = (Plant) x; //x is a fish, I put it won't compile on the exam and missed it. correct answer is it throws exception because It compiles because of the cast to plant? 3. Lifeform c = fish; //I put this works fine on exam and got it. So, you can downcast fine when instantiating? 4. Fish d = (Fish) life; //I put throws exception.. I got that right. This doesn't work? then what is the point of casting? 5. Fish e = (Fish) x; // Oh I guess this is the point of casting. For when the object was typed as the super but an instantiation of the subclass. so this works? 6. Plant p = (Plant) fish //I think this doesn't compile because fish is of type fish which is unrelated to plant If it's a valid typing then the code will compile. For something like Plant b = (Plant) fish, it will compile because the code itself has matching types, but then a ClassCastException is thrown when the code actually runs because you can't cast a fish to a plant. Others should follow similar logic; feel free to ask more questions. On December 15 2016 23:46 travis wrote: Now it says "assume there is a methhod called move in the Lifeform class that has been overridden in the Plant class."
Which version of the move will run. Lifeform version, or Plant version I put lifeform version and missed it. So the rule is what? That the version of the method that is ran is based on the object that was instantiated and not the type it was cast to? But that's the opposite for when you want to look at it's field values, right? Think back to when you were doing the Tree assignment. The concept is called Polymorphism if you want to read up on how it works. On December 15 2016 23:46 travis wrote: Now it has the question
Which of these could you pass in as a parameter 1.) Fish 2.) Plant 3.) Lifeform 4.) Object I put 1, 2, 3 and got it right. So you can only pass in the class and subclasses? What if I tried to put in a subclass of Fish as a parameter. Would it work? A subclass of Fish would work because it is a Fish and a Fish is a Lifeform. On December 15 2016 23:46 travis wrote: Okay now it says we have an arraylist "list" of type LifeForm. Fish have a method called swim. using a for each loop, call the swim method on all the fish. Do I do this(i missed this on the exam so I am unsure):
so yeah I missed this. They tell me to do "instanceof cast". Where am I doing an instanceof cast? Also they crossed out my "Fish" after the for. What is the correct structure for this? Is it
You have an ArrayList of Lifeform. For each lifeform, check if its a fish. If it is then you want it to swim. This ArrayList could also contain plants which don't have a swim method so you can't just call swim on everything.
On December 16 2016 00:09 travis wrote: sorry, I meant when are static initialization blocks ran so the answer is "when the class is first loaded" But... what does that actually mean? When are classes loaded? When the code is compiled makes more sense to me. | ||
Acrofales
Spain17833 Posts
On December 15 2016 23:46 travis wrote: ok its the morning of. time for question flood here is a few i missed on my first exam "when does a non-static initialiation block run" I answered: before anything else, including the main method I got this wrong. When I do a google search on this, I find many different answers. So what is accurate? A non-static initialization block is part of the class. It is therefore run upon initializing an object of that class. Because it is not explicitly in the constructor, but separate, it is run BEFORE the constructor is run. E.g.
After initialization an object of type Foo will have bar = 3. However, being non-static, bar is part of the object. It is thus only initialized when an object is initialized. There is no such thing as a static Foo.bar. Okay now let's go over typecasting. I had so much trouble on this on the first exam, it confuses me so badly. Let's look at it's example, where Fish extends Lifeform, and that Plant also extends Lifeform.
So what do you call each part of this line Is it "Type variablename = new object from class" ? Not quite sure what you mean, but in your example: fish is a variable of type Fish. life and x are variables of type Lifeform. life is assigned an object of type Lifeform. x is assigned an object of type Fish. So in those lines there are the following operations: 1. Variable declarations (with their type) 2. Assignments (the = symbol) 3. Object initialization If I were to write it completely out in text, I'd say something like The variable fish is declared of type Fish. Additionally, a Fish object is initialized and assigned to the fish variable. Same for the other lines. But that might be more verbose than your prof wants from you. Ok anyways let's move onto the questions. Each one you have to answer "won't compile", "throws exception" or "works fine" 1. Plant a = x; //x is a fish, no relation to plants, I say this won't compile 2. Plant b = (Plant) x; //x is a fish, I put it won't compile on the exam and missed it. correct answer is it throws exception because It compiles because of the cast to plant? It'll compile, because the compiler isn't clever enough to know that x cannot possibly be cast to a Plant. Not sure, but I don't even think your lint checker will give you a warning. It'll start running, try to cast an object of type Fish to type Plant, realize that cannot be done and throw a ClassCastException. 3. Lifeform c = fish; //I put this works fine on exam and got it. So, you can downcast fine when instantiating? Yup, you can abstract away when assigning variables without explicitly casting (you just did so in the example above where you assigned a new object of type Fish to variable x (of type Lifeform)). 4. Fish d = (Fish) life; //I put throws exception.. I got that right. This doesn't work? then what is the point of casting? 5. Fish e = (Fish) x; // Oh I guess this is the point of casting. For when the object was typed as the super but an instantiation of the subclass. so this works? You figured it out. 6. Plant p = (Plant) fish //I think this doesn't compile because fish is of type fish which is unrelated to plant Correct. Here the compiler is smart enough to figure it out. Now it says "assume there is a methhod called move in the Lifeform class that has been overridden in the Plant class."
Which version of the move will run. Lifeform version, or Plant version I put lifeform version and missed it. So the rule is what? That the version of the method that is ran is based on the object that was instantiated and not the type it was cast to? But that's the opposite for when you want to look at it's field values, right? You should probably do a bit more reading on polymorphism. You have a variable of type Lifeform. That means you can only ask it about things that Lifeform has. E.g. you cannot ask it how many leaves it has, despite knowing that objects of type Plant have a public variable numleaves. Nevertheless, the object that is assigned to that variable is of type Plant. Therefore any time you call upon the lifeform to do something, it will do it like a plant would do things. I'm probably not the best at explaining this, which is why I suggested you read up a bit more on this ![]() Now it has the question
Which of these could you pass in as a parameter 1.) Fish 2.) Plant 3.) Lifeform 4.) Object I put 1, 2, 3 and got it right. So you can only pass in the class and subclasses? What if I tried to put in a subclass of Fish as a parameter. Would it work? Yes. Any object of type Shark, for instance, would also be a Fish, and thus also be a Lifeform. That's why, if you make your method:
you can literally pass it any object of any type you like in Java. Okay now it says we have an arraylist "list" of type LifeForm. Fish have a method called swim. using a for each loop, call the swim method on all the fish. Do I do this(i missed this on the exam so I am unsure):
so yeah I missed this. They tell me to do "instanceof cast". Where am I doing an instanceof cast? Also they crossed out my "Fish" after the for. What is the correct structure for this? Is it
Kinda, you got a bunch of syntax errors there, so that won't pass the compiler. instanceof is a binary operator, not a unary method. Moreover, you forgot that lifeforms can't swim. You thus use it as follows:
thanks... that's all my questions from exam 1 You're welcome | ||
| ||