Java程序辅导

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

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
COMP3200 Anonymous Questions and Answers Page (2021, 36-55) 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 55: Submission reference: IN1200 Hi sir i run my code through the test it comes up with 3 failures but one of them is called judgingtest.testvotenegative() it fails this test and outputs expected 0 but was 1 i dont know what part of code this refers to Answer 55: That is a test of the vote method in which a negative value is passed as the parameter to the method. Keywords: assign1 , method-vote Question 54: Submission reference: IN1199 Sir, you know how for the assignment we have to return Details as a string i have written code deleted but there are integers so I am stuck Answer 54: The important thing to bear in mind is that printing (using System.out.println) is not the same as returning - this is a point that I have made a couple of times in lectures. So the getDetails method should not have any System.out.println statements in it. Keywords: assign1 , method-getDetails , System-out-println Question 53: Submission reference: IN1198 How do you add a mutator in Java? Answer 53: A mutator is any method that changes the state of an object, so there is no general form for a mutator. If you mean a setter then you might like to look at my answer to Question 40 (2021) for an example from the lectures. Keywords: mutator , setter Question 52: Submission reference: IN1197 Hi sir I was trying to do Exercise 2.91 of the classwork but i am not sure as to which code to use in order to update the field by 1 each time Answer 52: There are several different ways to add 1 to a variable's current value. Here are a few: var++; var += 1; var = var + 1; Keywords: ex-2-91 Question 51: Submission reference: IN1196 Hi sir I too have the error when running the test it divides by 0 for some values the test returns ticks but for others it returns failures and particularly the first term it returns an error I understand what my code is trying to do. It is trying to do 1 divided by 0 but I don't know how to change the code without changing it for the other values in my case the code I have used is below for the positive method code deleted Answer 51: You have two alternatives you can try: You could make an explicit test of the number of judges to see if it is zero before undertaking the division, and only do the division if the number is greater than zero. Find an alternative way to work out the result that does not involve using division. Both are acceptable alternatives as long as the result is correct. Keywords: assign1 , method-positive Question 50: Submission reference: IN1195 hi sir, i am also having an issue with the getDetails part of the assignment. this is my code code deleted Answer 50: The problem is to do with the correct formatting of the details. For that you can look at the way that the printTicket method of TicketMachine formats its output and some of the exercises from the class in week 11/3 that were about formatting strings - including one of the assessed exercises. At the moment, your method will output something like: newName has 112 because you are concatenating the text "newName has " directly with the values of two integer variables. I recommend checking the required format in the assignment description and then trying to formulate that as a String concatentation using the examples I mentioned earlier to guide you. Keywords: assign1 , method-getDetails Question 49: Submission reference: IN1193 how do i submit the assignment as a zip file, thanks. Answer 49: If you don't know how to create a ZIP file then I recommend that you submit it as a JAR file and follow the instructions in the video for how to create a JAR file within BlueJ. Keywords: zip-file , jar-file Question 48: Submission reference: IN1192 sir I dont understand how to write the code for adding 1 to the current value of judges.should it be like code deleted Answer 48: Your code is correct for increasing judges by 1 but the following statement that adds the number of judges to the number of votes is incorrect. judges and votes are separate things so they should not be mixed in that way. Keywords: assign1 , method-vote Question 47: Submission reference: IN1190 Hi sir, I am having issues with the method called getDetails Answer 47: Would you be able to say what those issues are? You can also post what code you have done so far for it and I will remove it before posting my answer so that others don't see it. Keywords: assign1 , method-getDetails Question 46: Submission reference: IN1189 My system isn't letting me enter a participant name, and I've coded it correct, it keeps on saying 'error can not find symbol - variable' Answer 46: You have forgotten to put double quote characters around the name. Remember from the first class that you had to put them around the colours when calling the changeColor method: "blue". Keywords: assign1 Question 45: Submission reference: IN1188 Hello sir, how would we make a return statement that has both String and int Answer 45: You can only return a value of one type; so you would have to decide whether to return either a String or an int. Question 44: Submission reference: IN1187 Hi sir in my code when I ran the test one of the failures that was output was expected: but was: I don't see why the code here is wrong and output a failure to me the result looks the same as the expected result. Answer 44: I think you have an extra space in your output. Keywords: assign1 , method-getDetails Question 43: Submission reference: IN1186 Hi sir, I ran the test class and I received a / by zero error which I am slightly confused about. Could you please elaborate on this? Thanks! Answer 43: The diagnosis depends on which particular test failed and which of your methods was being tested. The error arises if an attempt is made to divide something by zero. So, in the expression x / y it is not permitted for y to have the value zero. Keywords: assign1 , divide-by-zero Question 42: Submission reference: IN1185 Hi sir, quick question about the assignment, is public static void main(String[] args) something we need to use? Answer 42: No it isn't. By using BlueJ we can avoid having to have a class with a main method. Which means that new programmers don't have to face its complexities simply to write their first program. Keywords: method-main , assign1 Question 41: Submission reference: IN1184 I haven't fully understood how the test classwork, are they for you try out extra methods or methods your not sure about? Answer 41: I assume you are referring to the TestJudging class that I have provided to help with the first assignment. You should only use it if you think you have finished writing the Judging class, otherwise it won't compile. If you have finished, then add that class to your project folder, compile it and right-click over TestJudging. The Test All menu will run a lot of tests to check out your implementation. If any of the tests gives an error or failure then you can click on the test and see some more details. The idea is for your code to pass all the tests. There is a demo in the lecture video for Lecture 7 near the beginning. Keywords: class-TestJudging Question 40: Submission reference: IN1183 Hi I don't know how to do this: Exercise 2.32 [Assessment: You must have this exercise signed off by your class supervisor] Write in the TicketMachine class an accessor method, getTotal, that returns the value of the total field. - I've done this ^ already. Write a setPrice method in the TicketMachine class so that it assigns the value of its parameter to the price field. However, I am finding it hard to do this above as the instructions are quite vague. I don't know what to put in the method as all it has asked me to do is write a setPrice method, and I'm quite confused. Answer 40: Note that the question does tell you what is required inside the body of the method: an assignment from the parameter to a field. In one of the lectures for Chapter 2 I provided the following example of a setter method for this field: private int discount public void setDiscount(int amount) { discount = amount; } Following the principle of observe and imitate (with appropriate adjustments) you should be able to use the setDiscount method as a 'model' for basic setter methods and, with appropriate adjustments, be able to turn it into a setPrice method. Keywords: ex-2-32 , setter Referrers: Question 53 (2021) Question 39: Submission reference: IN1182 Hi sir I have been working on this weeks class exercise 2.49b asks for me to make a min and max field do these fields require user input as I don't understand the wording is it user input to set minimum and maximum or do I set it as a fixed value in the field. Answer 39: I assume you mean ex 2.94b? The question says to set their values via parameters to the constructor. Keywords: ex-2-94b Question 38: Submission reference: IN1181 Will the testing that you mentioned today actually optional or will it be a factor to get a better grade Answer 38: Whether you choose to do it or not will not be factored into the way I grade you. However, because the test class checks the basic requirements, passing all of my tests is likely to lead to your code achieving a higher grade when it is formally assessed because it will pick up trivial errors that are easy to miss if you don't test. Keywords: assign1 , testing Question 37: Submission reference: IN1178 For exer2.37, after writing the method header, I seem to be stuck with the statements to be put in the body, when i try put in "System.out.printIn", it doesnt work or should I write please insert the correct amount?, thanks Answer 37: It looks like you have mis-spelled println - that is an 'l' not an 'I' before the final 'n'. The body of the method will look quite similar to the previous exercise. Keywords: ex-2-37 Question 36: Submission reference: IN1177 Hi sir, I don't understand how to submit the assignment through the JAR file, do we save the project as a different folder the transfer it to the Jar file? Answer 36: You don't need to create a different folder. There is a video in the Assignments sections that shows you how to create a JAR file from a BlueJ project. Save it somewhere like your Desktop and then upload it to the Assignment 1 Upload Area. This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. Last modified Sun Nov 7 09:52:01 2021 This document is maintained by David Barnes, to whom any comments and corrections should be addressed.