Java程序辅导

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

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
COMP3200 Anonymous Questions and Answers Page (2021, 1115-1134) 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 1134: Submission reference: IN2485 for inheritance when you are making the superclass constructor and you want to initialise a field with a parameter how do you do it? Answer 1134: Here is an example where you want to initialise a field in the superclass and subclass at the same time: public class SuperThing { private int x; public SuperThing(int x) { this.x = x; } } public class SubThing extends SuperThing { private int y; public SubThing(int x, int y) { super(x); this.y = y; } } Question 1133: Submission reference: IN2484 What is polymorphism Answer 1133: The word literally means 'many forms' and relates to inheritance in object-oriented languages. When an object belongs to a type that is part of a 'type hierarchy' then it possesses characteristics from each type in the hierarchy. In other words, it is a polymorphic object. For instance, in Java the ArrayList type is a 'subtype' of both the 'Collection' and 'List' types, which are two of its 'supertypes'. An ArrayList object, therefore, is polymorphic and you can use one whereever an object of type ArrayList, List or Collection is required. For instance, there will be some situations where you don't care whether a particular object is an ArrayList or a LinkedList; you are just interested in its List-features. So, you could provide either an ArrayList or a LinkedList object in that context. Here is a simple example: public void printAllMatching(List list, Thing item) { for(Thing t : list) { if(item.matches(t)) { System.out.println(t.toString()); } } } Any object that has List in its type hierarchy, and is storing Thing objects, could be passed to the printAllMatching method. Keywords: polymorphism Question 1132: Submission reference: IN2483 Can we ask questions here regarding the further OOP module Answer 1132: Not about assignments, but if you have questions about Java and OOP I will try to answer them unless the load gets too heavy. Question 1131: Submission reference: IN2482 After completing this module would you say we know java at a basic or intermediate level? Answer 1131: An interesting question! It depends on your overall grade for the module and the following is not robust science but personal opinion. If you have a high mark and are comfortable with most of the material then I think you would be at an intermediate level. Marks below 55 (say) would suggest further study and practice needed to bring you up to an intermediate level. Another factor worth bearing in mind is how long it would take you to come up with a good solution to a problem. That's about fluency. Someone at intermediate level and above would be able to come up with solutions relatively quickly to similar problems to those we have covered in the course, whereas someone below that level would likely take longer and need to look up a lot of things. Much like, when speaking a second language, you have to look up things less and make fewer grammatical mistakes when conversing in situations you have met before. Question 1130: Submission reference: IN2474 Hi David, Thanks for your help last term, the anonymous question page was a great help for me and for others that I have spoken to, so I just wanted to say thank you for the endless stream of questions that we asked as a cohesive unit, even at questionable hours of the early morning. :) Answer 1130: Thanks for your 'thanks'. I think that being able to ask questions - and get answers - is an important part of everyone's learning experience (including mine!) so I am glad that you found it useful. Question 1129: Submission reference: IN2469 when will we get back the assignment marks P.s I asked some lecturers about a week ago about our unmarked assignments (2 foundations of computing I assignments) from last term but nobody has said anything about it? We have been waiting for our results since early december? What should i do? Answer 1129: Feedback is now available on the Moodle page for COMP3200 assignment 3. As the deadline for submissions was the start of this term this means I have provided it over a week ahead of schedule as we have 3 term-time weeks to provide it. As far as the other courses go, you might like to ask your course rep(s) to ask the module conveners' when you can expect to get their work back. Question 1128: Submission reference: IN2464 Hi David, I wonder if you could help me understand this question as it hasn't been phrased very well: Define a method in the class PartA that takes 2 parameters of type int and returns an ArrayList containing a given number of random integers between 1 and a given upper bound. Answer 1128: My guess is that the two parameters are the number of integers to be returned and the upper bound. So the method would generate the given number of random numbers in that range and put each in the ArrayList, which is then returned from the method. You will need to check whether the upper bound is inclusive - valid in the range - or exclusive - one larger than the maximum allowed. Question 1127: Submission reference: IN2457 Question 1126 (2021) i meant as in it prints the name that the user inputs Answer 1127: The answer will depend on the context. For instance, are you wanting a user to type in their name (e.g., via a java.util.Scanner), pass it in as an external program argument (via the args parameter of the main method), or pick it up from the runtime environment. Question 1126: Submission reference: IN2456 how do you print out the string parameter in a method header for example public method(String name) System.out.println(???) Answer 1126: Just: System.out.println(name); Referrers: Question 1127 (2021) Question 1125: Submission reference: IN2451 in the main class for our assignment there is 'string args' Answer 1125: Not quite; it is actually String[] args - the square brackets are important because they tell you that the parameter is an array of String objects. When a program is run, the array will contain any program-level arguments/parameters. For instance, if you wrote a program to compare two files, the array would likely contain the names of the two files to be compared. Question 1124: Submission reference: IN2450 what is string args Answer 1124: What is the context of the question? Question 1123: Submission reference: IN2448 How is our degree calculated Is each module worth 12.5% of the degree for year 1 and if we say get 50% of the marks for one module we achieve 6.25%? Or is it marked another way Answer 1123: You would need to check the course handbook for that info. Question 1122: Submission reference: IN2447 Can I add another method to the inventory class Answer 1122: Only if it is private, as it says in the brief. No further methods should be required. Question 1121: Submission reference: IN2446 is there marks for commenting out in assignment3 or no? Answer 1121: For commenting out? That usually means removing code by surrounding it with comment symbols, which I don't think is what you mean. All of the methods are so straightforward that there should be no need to add any further comments to the ones I provided in the starting version of the code. Question 1120: Submission reference: IN2445 Hi David, I don't understand why the presents aren't adding up, and only return the latest number that is set as present. code deleted Answer 1120: The logic of your method is very strange. You are iterating over the current values in the list and then repeatedly storing the presents parameter for the given address parameter. So, if there were 50 addresses in the Map, you would put the same value 50 times into the address entry in the Map, which makes no sense. In the process, you are also overwriting any value that was already stored there, so not adding to it. You don't need a loop for this method. The logic required is described in my answer to Question 795 (2021). Keywords: method-addToInventory Question 1119: Submission reference: IN2444 Whenever I do Inventory.presentsForPostcode I can't seem to call it? I know i'm doing something wrong I just don't know what Answer 1119: Try calling it on the invent object rather than the Inventory class. Question 1118: Submission reference: IN2443 this is my attempt at numberOfTrips, it ticks off both tests is it correct...? code deleted Answer 1118: It looks like it. Keywords: method-numberOfTrips Question 1117: Submission reference: IN2441 is this correct or along the right lines for deliveryOrder? it passes the test in the test class. code deleted Answer 1117: The fact that is passes the tests is a good sign. It look fine, if just a little profligate with lists! Keywords: method-deliveryOrder Question 1116: Submission reference: IN2440 is this correct for getting the house numbers? for deliveryOrder ? code deleted Answer 1116: Having called addressesForPostcodePrefix once and stored the result in a local variable, it isn't clear why you would call the method again in the for-each loop. The same list will be returned on both calls. Yes, that is the correct way to get the house numbers. Keywords: method-deliveryOrder Question 1115: Submission reference: IN2439 When we create the jar file should we specify the main class or not? Answer 1115: No. This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. Last modified Mon Feb 14 21:08:59 2022 This document is maintained by David Barnes, to whom any comments and corrections should be addressed.