Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
COMP3200 Anonymous Questions and Answers Page (2021, 543-562) XML COMP3200 Anonymous Questions and Answers This page lists the various questions and answers. To submit a question, use the anonymous questions page. You may find the keyword index and/or top-level index useful for locating past questions and answers. We have taken the liberty of making some minor typographical corrections to some of the questions as originally put. Although most of the questions here will have been submitted anonymously, this page also serves to answer some questions of general interest to those on the course. Question 562: Submission reference: IN1747 public void setStatus(String id, boolean positive) { for(String id : tests){ if(tests.contains(String id)){ String id = positive ; } } } What's the problem ? Answer 562: Several things, among them that when you call a method you don't include the parameter's types. You will never have seen that in any of the code examples in the course. Also, the objects in the collection should be of type InfectionTest rather than String. Keywords: method-setStatus Referrers: Question 525 (2021) Question 561: Submission reference: IN1746 Where do you want us to write comments? I am asking this as I want to know how to get the first ten marks Answer 561: Only for any additional methods that you might have written yourself - which is likely to be none, so don't worry about that part of the assignment. Question 560: Submission reference: IN1745 am i along the right lines in declaring an array list here for 6YY code deleted Answer 560: Not really. The return type of the method is not correct when you compare it with what the exercise is asking for and trying to iterate over a newly created - and therefore empty - ArrayList doesn't make sense. Keywords: ex-6-yy Question 559: Submission reference: IN1744 hi sir for 6YY why cant i use .contains here code deleted Answer 559: It doesn't make sense to ask whether an object contains itself. I think you might be trying to complete this exercise without fully understanding how to use a HashMap so it would be worth doing a bit more background reading on it and looking at the API page in the java.util package. Keywords: ex-6-yy , class-HashMap Question 558: Submission reference: IN1743 do you want us to add comments to our methods for the assignment? Answer 558: Not to the bodies of your methods; they would just clutter the code. If you have written additional methods then yes, but I had already commented the ones required so I would not expect you to have written any. Question 557: Submission reference: IN1742 Is this correct for the setStatus method? code deleted My ArrayList is: code deleted Answer 557: That looks ok so I recommend checking it with the test class. Keywords: method-setStatus Question 556: Submission reference: IN1741 Should I be concerned when I see, "not graded" in my previous assignment upload? Answer 556: Did you get feedback in the Upload area of Moodle? I you did then you will have received a mark but I have no idea whether they have been entered into Kent Vision yet. If you have no feedback then you probably won't have a mark. Keywords: assign1 Referrers: Question 572 (2021) Question 555: Submission reference: IN1740 have i set the header up correctly for 6YY code deleted Answer 555: The return type should not be void, so it would be worth re-reading the exercise to check what it should be. Keywords: ex-6-yy Question 554: Submission reference: IN1739 Kinda silly of me to say this, but when I try to create a JAR file, it asks me to specify which class, anD I can't seem to choose all Answer 554: It ask for the Main class and you don't need to select that because it isn't relevant. Keywords: jar-file Question 553: Submission reference: IN1738 hi sir, I am getting 3 failures with this code code deleted it says The test with ID t: 42 should have been returned. ==> expected: but was: The test with ID t: 97 should have been returned. ==> expected: but was: null should have been returned as there is no matching ID. ==> expected: but was: Answer 553: The equals method returns a boolean result but you aren't checking whether that is true or false before returning the (first) test. Keywords: method-findTest Question 552: Submission reference: IN1737 code deleted sir why is this not working ? Answer 552: Two reasons: You need to (re-)read the description of the isPositive method in the assessment description. You are returning the set as soon as you find the first match, instead of returning after all of them have been found. Keywords: method-getPositiveTests Question 551: Submission reference: IN1736 referring to Question 546 (2021) , what is my first call to isPositive supposed to do? and is having two independent if statements a problem or is it just not the most efficient way to do it? Answer 551: Having two if statements written in the way you have done is the reason you are getting failed tests. There should only be one call to isPositive and it must be logically connected to the call to isKnown. Question 550: Submission reference: IN1735 Hi David, for the findTest method this is what I've created: code deleted I don't understand why BlueJ is saying "incompatible types: java.lang.String cannot be converted to InfectionTest" in the brackets next to getDetails. What do I need to change? Answer 550: It is because the method is supposed to return an InfectionTest object, according to the return type in the header, but you are trying to return a String - what getDetails returns. Keywords: method-findTest Question 549: Submission reference: IN1733 code deleted is this correct? Answer 549: I assume that it doesn't even compile, which is a big clue that it isn't correct. The assignment says that you have to call the setStatus method on the matching InfectionTest object and that is one of the things you are not currently doing. Another is that this test isn't actually doing anything with an InfectionTest object so it could never match one: if(getID.contains(id)) Keywords: method-setStatus Question 548: Submission reference: IN1732 is this correct so far and what is the next thing I need to do?? code deleted thank you Answer 548: It isn't correct because you aren't actually doing anything with the InfectionTest object tests in the body of the method. I recommend that you read through the source of the InfectionTest class so that you know what methods are available for you to call for both this method and the rest of the assignment. Keywords: method-setStatus Question 547: Submission reference: IN1731 code deleted error whats wrong ? Answer 547: You seem to have changed the header of the method from what it was. It should be: public void addTest(InfectionTest test) Keywords: method-addTest Question 546: Submission reference: IN1730 hi sir i have been working on the getPositiveTests method and i have tested it using the test class and it passes the tests for the getPositiveTests except for getPositiveTestsUnknown() thats the only one that comes up with error, im not sure how to fix it. Here is my code: code deleted Answer 546: You need to think about the logic of your two if-statements which are completely independent. The first call to isPositive isn't actually doing anything. Keywords: method-getPositiveTests Referrers: Question 551 (2021) Question 545: Submission reference: IN1729 code deleted I've made my findTest() method. Is this correct? Answer 545: No, for two reasons: you are always returning null; and you are trying to compare an InfectionTest object (id2) with a String (id) which doesn't make sense. Keywords: method-findTest Question 544: Submission reference: IN1728 Evening David I have a question about the find test method Would it be ok to make an arraylist for just one element (the object you're trying to find) and then return the arraylist in the return statement? This is my code so far: code deleted The question mark would be my return list cheers Answer 544: Returning a list would not match the return type of the method, so you would have to return just one element from the list. However, the assignment says you can assume that there will only be one match so there is no point having a list for matches. The bottom line is: don't use a list in this method. Keywords: method-findTest Question 543: Submission reference: IN1727 is there a program which has a similar code to what needs to be done for 6yy Answer 543: No there isn't. You need to work out the sort of logic required, bearing in mind the methods that a HashMap has, which can be found in the API. Keywords: ex-6-yy This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. Last modified Wed Jan 12 11:47:56 2022 This document is maintained by David Barnes, to whom any comments and corrections should be addressed.