Java程序辅导

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

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
COMP3200 Anonymous Questions and Answers Page (2021, 693-712) 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 712: Submission reference: IN1925 for advent of code, do you recommend sticking to blue j or another ide? Answer 712: It is nice to hear that you are participating in AoC. The first two challenges have been fairly straightforward and should be accessible to anyone currently on the course. Which IDE to use depends on how you want to use AoC. If you are keen to compete on the leaderboard and get the tasks done as quickly as possible, you should use the IDE that you are most comfortable with and will help you to code quickly. In that case, I would move away from BlueJ and use a more professional IDE with code completion and better error indications. However, if you are just using AoC for coding practice then either should be fine. Using BlueJ means you can focus on the coding aspects and not have to think about navigating a new environment. On the other hand, you could use AoC as a vehicle both for more practice coding and learning a new IDE. Keywords: advent-of-code Question 711: Submission reference: IN1924 This is my code in the AlienList class: code deleted I keep getting syntax errors with "aliens" and "isHumanoid" and ".getDetails" could you please explain what errors im making? Answer 711: You are trying to call methods on the class - Alien - not the object - alien. Question 710: Submission reference: IN1923 I have started the mock test and i am stuck with the first part as i am not sure what "The one constructor must have three parameters to initialise all of these fields." means. Could you explain in a bit more detail please. Answer 710: This is about material you can find in Chapter 2. A constructor is the place that a new object is created and initialised. So the idea is that when a new Alien object is created, it receives the values for its 3 fields via the parameters of the constructor. The body of the constructor then uses those parameters in assignment statements to the fields. Question 709: Submission reference: IN1921 Hi David I'm practicing the mock Alien questions and am a little stuck on the printHumanoids function for the AlienList code deleted This is my code so far and have noticed that commenting out the if loops and doing System.out.println(ishumanoid) where the asterix is, it correctly prints out the boolean values of the aliens (true and false) However this specific code (without the asterix) the output is always TRUE for every alien (no matter the actual boolean value). So the fault is in the logic of the if statement but I'm not sure why this is? (having an else statement instead of another if makes no difference as that was my first attempt) Answer 709: Remember what I said we don't call '=' at the start of the course :) That is the error you are making. Try == instead of = in the conditions of the if-statements. Question 708: Submission reference: IN1920 When would you use public static void main(String[] args)? I do not really understand the purpose of it. Answer 708: In pretty-well every Java program you would write. When not using BlueJ it is the starting point for all Java programs. I will cover it in the lectures in week 19/11. Keywords: method-main , main-method Question 707: Submission reference: IN1919 Hi sir, is this correct for question 3 of the mock? code deleted Answer 707: Not quite. If you run this code with a reasonable amount of data you will find that it fails. I would appreciate it if you would test your code before asking me whether it is correct or not, and remember that you won't have me to ask during the real thing ;) Question 706: Submission reference: IN1918 Hi sir, is this better for question 2 of the mock? code deleted Answer 706: Not quite because it doesn't actually print. If you test the code you will find that is the case. Aim to run the code you write. Question 705: Submission reference: IN1917 Can we retake the test? Answer 705: No, sorry. Question 704: Submission reference: IN1916 Exer6yy (Question 703 (2021)) Something like this? I'm not quite sure how to match, is there a code I could refer to? code deleted Answer 704: As well as understanding what the method is trying to achieve, you need to understand how a for-each loop works and think logically about what the code you have written is doing. In your loop header you have a variable called name that will be set, on successive iterations, to each key in the map. However, in the body of the loop you have then made an assignment to that variable, which means the variable's value set by the loop is pointless. Then the parameter passed in - which is meant to be one of the possible values in the map you are using as a key. So, aside from the loop header, the loop doesn't make any logical sense with respect to what the method is meant to be doing. If the loop variable is providing you with a key then you should use that variable with the map's get method to retrieve the associated value. And then do something with that value that is appropriate to the purpose of the method. I recommend that you re-read the exercise to be sure that you fully understand what the method is trying to achieve, and then think about how to achieve that within the body of the for-each loop. Keywords: ex-6-yy Question 703: Submission reference: IN1915 Question 695 (2021), sorry I don't fully understand what you said as I am a little confused about this topic but I tried this; should i put the "contacts.containsValue..." in an if statement? or there is no need of it? code deleted Answer 703: I recommend trying a completely different approach: iterate over the keys rather than the values and test whether the value in each key:value pair matches the number you are looking for. If it does then add its key to the string you are building to be returned at the end of the method. Referrers: Question 704 (2021) Question 702: Submission reference: IN1914 For the auction class (chapter 4) , one of the exercises (4.51) asks to edit the getLot method so it doesn't rely on a lot with a particular number being stored at index (number-1) I would just like to know what would I replace it with and how/why? Answer 702: You would have to perform a search through the list for the matching lot number because there could be 'gaps' in the sequence. Keywords: ex-4-51 Question 701: Submission reference: IN1913 Hi David, referring to Question 693 (2021), is this correct now? code deleted Answer 701: No, because the method is meant to print rather than return. It also illustrates an error I mentioned in Tuesday's lecture this week in the solution to assignment 2: a loop that will finish as soon as the condition is true rather than iterating over the whole collection. Question 700: Submission reference: IN1912 why is this failing when i try to add an alien object to the list code deleted Answer 700: Question 700! It is because you have included a void return type for the constructor, which means it isn't a constructor. Therefore the Vector is not being created and you are probably getting a NullPointerException. Delete the word 'void' from the 'constructor'. Question 699: Submission reference: IN1911 For the timed assessment on Wednesday morning, my ILP allows me to have 25% extra time. I'm assuming this means I have an hour and 40 mins, rather than the hour and 20 mins? And will I be able to hand in the JAR file at the end of the 100 mins without it being considered as a late hand-in giving me zero marks? thank you. Answer 699: That is correct. There is a separate hand in area for people with ILPs. Question 698: Submission reference: IN1910 Can we share code for the mock? Answer 698: If you wish. However, the people you share it with will derive more benefit from having a go themselves rather than just reading what you have written. Question 697: Submission reference: IN1909 Hello sir, could you check my code for AlienList code deleted Answer 697: It looks good. Hopefully you have also tested it to give yourself additional confidence in it. Question 696: Submission reference: IN1907 does being able to get through the mock questions with ease mean you should be okay for the actual timed assessment? Answer 696: Yes, you should be ok in that case. Question 695: Submission reference: IN1906 hi sir, do you mind telling me whats wrong here, for exer6yy code deleted Answer 695: You are not using the parameter as you are overwriting it with the values in the Map. You are then using the values in the map as if they were keys, which they aren't. Keywords: ex-6-yy Referrers: Question 703 (2021) Question 694: Submission reference: IN1905 i have just completed the mock questions for the timed assessment and i have two things to ask, 1) is being able to do all the mock questions an indicator that i will be fine and am prepared for the timed assessment 2) and also does this code look right for the last method, the getNonHumanoids() method: code deleted Thank you. Answer 694: Completing the mock within the alloted time should give you a lot of confidence that you are ready for the real thing, so well done with that. Yes, that code looks fine. Hopefully, you also tested it to check for yourself. Question 693: Submission reference: IN1904 Is this so far alright for question 2 on the mock exam? I don't understand the rest. (Details of each Alien must be printed on a separate line. The print out must use exactly the format shown in part 1 of the question and must not include the index of each Alien in the list.) code deleted Answer 693: It would be worth coding this in BlueJ to expose the most obvious issue which is that your method has a non-void return type but doesn't return anything. If you were to run it you would also see that the wrong text is printed and everything is printed on the same line. The solution to assignment 2 that I coded in today's lecture does something similar. Referrers: Question 701 (2021) This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. Last modified Mon Jan 10 22:13:02 2022 This document is maintained by David Barnes, to whom any comments and corrections should be addressed.