nus-cs2030 / 2223-s1 Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Regarding audit issues as such, will checkstyle help solve the issue? If not, would I have to solve these manually?
Starting audit...
[WARN] /tmp/home/Arrive.java:4: 'CTOR_DEF' should be separated from previous statement. [EmptyLineSeparator]
[WARN] /tmp/home/Arrive.java:4:12: '(' is preceded with whitespace. [MethodParamPad]
[WARN] /tmp/home/Arrive.java:8: 'METHOD_DEF' should be separated from previous statement. [EmptyLineSeparator]
[WARN] /tmp/home/Arrive.java:8:50: WhitespaceAround: '{' is not preceded with whitespace. [WhitespaceAround]
[WARN] /tmp/home/Arrive.java:10:30: '(' is preceded with whitespace. [MethodParamPad]
[WARN] /tmp/home/Arrive.java:12:30: '(' is preceded with whitespace. [MethodParamPad]
[WARN] /tmp/home/Arrive.java:15: 'METHOD_DEF' should be separated from previous statement. [EmptyLineSeparator]
[WARN] /tmp/home/Arrive.java:15:29: WhitespaceAround: '{' is not preceded with whitespace. [WhitespaceAround]
[WARN] /tmp/home/Customer.java:5: 'CTOR_DEF' should be separated from previous statement. [EmptyLineSeparator]
[WARN] /tmp/home/Customer.java:5:14: '(' is preceded with whitespace. [MethodParamPad]
[WARN] /tmp/home/Customer.java:5:67: WhitespaceAround: '{' is not preceded with whitespace. [WhitespaceAround]
[WARN] /tmp/home/Customer.java:10: 'METHOD_DEF' should be separated from previous statement. [EmptyLineSeparator]
[WARN] /tmp/home/Customer.java:10: Line is longer than 100 characters (found 123). [LineLength]
[WARN] /tmp/home/Customer.java:10:28: WhitespaceAround: '{' is not preceded with whitespace. [WhitespaceAround]
[WARN] /tmp/home/Customer.java:13: 'METHOD_DEF' should be separated from previous statement. [EmptyLineSeparator]
[WARN] /tmp/home/Customer.java:16: 'METHOD_DEF' should be separated from previous statement. [EmptyLineSeparator]
[WARN] /tmp/home/Events.java:2:22: '(' is preceded with whitespace. [MethodParamPad]
[WARN] /tmp/home/Leave.java:4: 'CTOR_DEF' should be separated from previous statement. [EmptyLineSeparator]
[WARN] /tmp/home/Leave.java:4:11: '(' is preceded with whitespace. [MethodParamPad]
[WARN] /tmp/home/Leave.java:8: 'METHOD_DEF' should be separated from previous statement. [EmptyLineSeparator]
[WARN] /tmp/home/Leave.java:8:50: WhitespaceAround: '{' is not preceded with whitespace. [WhitespaceAround]
[WARN] /tmp/home/Leave.java:11: 'METHOD_DEF' should be separated from previous statement. [EmptyLineSeparator]
[WARN] /tmp/home/Leave.java:11:29: WhitespaceAround: '{' is not preceded with whitespace. [WhitespaceAround]
[WARN] /tmp/home/Main.java:3:11: WhitespaceAround: '{' is not preceded with whitespace. [WhitespaceAround]
[WARN] /tmp/home/Main.java:9:35: WhitespaceAround: '{' is not preceded with whitespace. [WhitespaceAround]
[WARN] /tmp/home/Main.java:12:39: '(' is preceded with whitespace. [MethodParamPad]
[WARN] /tmp/home/Main.java:13:42: '(' is preceded with whitespace. [MethodParamPad]
[WARN] /tmp/home/Main.java:16:32: '(' is preceded with whitespace. [MethodParamPad]
[WARN] /tmp/home/Main.java:17:34: WhitespaceAround: '{' is not preceded with whitespace. [WhitespaceAround]
[WARN] /tmp/home/Main.java:18:59: WhitespaceAround: '+' is not preceded with whitespace. [WhitespaceAround]
[WARN] /tmp/home/Main.java:18:60: WhitespaceAround: '+' is not followed by whitespace. Empty blocks may only be represented as {} when not part of a multi-block statement (4.1.3) [WhitespaceAround]
[WARN] /tmp/home/Serve.java:4: 'CTOR_DEF' should be separated from previous statement. [EmptyLineSeparator]
[WARN] /tmp/home/Serve.java:4:11: '(' is preceded with whitespace. [MethodParamPad]
[WARN] /tmp/home/Serve.java:8: 'METHOD_DEF' should be separated from previous statement. [EmptyLineSeparator]
[WARN] /tmp/home/Serve.java:8:50: WhitespaceAround: '{' is not preceded with whitespace. [WhitespaceAround]
[WARN] /tmp/home/Serve.java:11: 'METHOD_DEF' should be separated from previous statement. [EmptyLineSeparator]
[WARN] /tmp/home/Serve.java:11:29: WhitespaceAround: '{' is not preceded with whitespace. [WhitespaceAround]
[WARN] /tmp/home/Server.java:1:13: WhitespaceAround: '{' is not preceded with whitespace. [WhitespaceAround]
[WARN] /tmp/home/Server.java:5:12: '(' is preceded with whitespace. [MethodParamPad]
[WARN] /tmp/home/Server.java:10:36: WhitespaceAround: '{' is not preceded with whitespace. [WhitespaceAround]
[WARN] /tmp/home/Server.java:13: 'METHOD_DEF' should be separated from previous statement. [EmptyLineSeparator]
[WARN] /tmp/home/Server.java:14:27: '(' is preceded with whitespace. [MethodParamPad]
[WARN] /tmp/home/Server.java:16: 'METHOD_DEF' should be separated from previous statement. [EmptyLineSeparator]
Audit done.
Grading terminated.
Are we expected to keep to using proper access modifiers (public/private) for all variables and methods in the .java files submitted?
How about the .jsh file?
Hi, what is the difference between the exercises uploaded on CodeCrunch and lab sessions? Do we submit the exercises during lab? (Sorry, don’t have much experience with computing modules!)
CodeCrunch requires final
keyword for all class properties including static
ones.
Since we should only have System.out.println()
in our main class, so in part of my solution for main
class:
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String serverName = sc.nextLine();
int customerIndex = 1;
while (sc.hasNextDouble()) {
double arrivalTime = sc.nextDouble();
double serviceTime = sc.nextDouble();
ServiceRequest serviceRequest = new ServiceRequest(arrivalTime, serviceTime);
ArrivedEvent event = new ArrivedEvent(serverName, customerIndex, serviceRequest);
System.out.println(event.toString());
System.out.println(event.nextEvent().toString());
customerIndex++;
}
sc.close();
}
However, in my Event
class implementation, I have to make one property called serverNextAvailableTime
accessible and modifiable to all class instances, so that they can know when the server is available and make decisions.
So in my old Event
class:
class Event {
...
protected static double serverNextAvailableTime = 0.0;
...
// Constructor without updating serverNextAvailableTime.
Event(...) {
...
}
Event(..., double serverNextAvailableTime) {
...
this.serverNextAvailableTime = serverNextAvailableTime;
}
private boolean serverIsAvailableToServeCustomer() {
// It uses serverNextAvailableTime to make a judgement.
...
}
public Event nextEvent() {
// It gets updates serverNextAvailableTime.
...
}
...
}
But CodeCrunch strictly does not allow a variable to be declared as protected static
. Instead, it must be declared as protected static final
, but in this case I could not update serverNextAvailableTime
. I also tried using ArrayList
instead of double
, but CodeCrunch does not allow such APIs.
Hence, are there any other side ways to make a property accessible and modifiable at class level? Or any suggestions about changing the Event
class implementation? Thanks!
Can I add additional methods in PQ.class?
Hello! after submitting the lab, are we able to edit it for re submit?
[Guidelines adapted from CS2030 AY20/21 Semester 2 Forum Guidelines by Russell]
We will be using Github Issues for CS2030 Q&A instead of the LumiNUS Forum!
Please take note of the following etiquette. Let's make this a pleasant place for online interaction and peer learning!
If you have a new question, create a new post instead of posting it as a reply on someone else's unrelated question.
Think carefully about what you are posting and write a succinct summary (or post title) that describe the question. E.g., the title "Java" is too generic. "Unable to install Java?" is better. "Installing Java on Windows 10 gives the error 'permission denied'" is even better.
Avoid posting questions that have been asked before (read through what others have posted before posting yourself) or have been answered in the notes and handouts (read through carefully what we released to the class)
Github Issues supports powerful formatting. If your post or reply contains code, use proper formatting to make your post readable. Markdown is powerful in allowing you to write inline code (which is by adding triple backticks (```
) before and after). For example:
public void sayHello() {
System.out.println("Hello World!");
}
Even better, you can give colors to the inline codes by adding the language after the first triple backticks. For example, doing
```java
public void sayHello() {
System.out.println("Hello World!");
}
```
will give you this.
public void sayHello() {
System.out.println("Hello World!");
}
On that note, please post only short snippets of what your issues are about. Do not post entire solutions of labs, project, or PA to github as it will be seen as it will be seen as a breach of academic integrity.
Hopefully, you have a wonderful time taking this module and learning Java!
Docker encountered exception error upon being launched
I have checked that my Windows laptop fulfills all the prerequisites of using Docker, such as turning on the Virtual setting at BIOS and OS versions. However, I noticed that it might be the problem of installing 'Linux kernel update package' (which Docker prompted me to install upon the first launch). My laptop does not show any successful installations of such distributions in PowerShell by using wsl --list
command, even after I manually installed the update package through an exe. file. On another machine, once the update package was installed through the exe. file, Docker can run, and I can see the installed distributions on its PowerShell.
====
System.InvalidOperationException:
Failed to set version to docker-desktop: exit code: -1
stdout: The attempted operation is not supported for the type of object referenced.
stderr:
at Docker.ApiServices.WSL2.WslShortLivedCommandResult.LogAndThrowIfUnexpectedExitCode(String prefix, ILogger log, Int32 expectedExitCode) in C:\workspaces\main-merges\src[github.com](http://github.com/)\docker\pinata\win\src\Docker.ApiServices\WSL2\WslCommand.cs:line 160
at Docker.Engines.WSL2.WSL2Provisioning.d__8.MoveNext() in C:\workspaces\main-merges\src[github.com](http://github.com/)\docker\pinata\win\src\Docker.Engines\WSL2\WSL2Provisioning.cs:line 81
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Docker.Engines.WSL2.LinuxWSL2Engine.d__28.MoveNext() in C:\workspaces\main-merges\src[github.com](http://github.com/)\docker\pinata\win\src\Docker.Engines\WSL2\LinuxWSL2Engine.cs:line 177
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Docker.ApiServices.StateMachines.TaskExtensions.d__0.MoveNext() in C:\workspaces\main-merges\src[github.com](http://github.com/)\docker\pinata\win\src\Docker.ApiServices\StateMachines\TaskExtensions.cs:line 29
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Docker.ApiServices.StateMachines.StartTransition.d__5.MoveNext() in C:\workspaces\main-merges\src[github.com](http://github.com/)\docker\pinata\win\src\Docker.ApiServices\StateMachines\StartTransition.cs:line 67
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Docker.ApiServices.StateMachines.StartTransition.d__5.MoveNext() in C:\workspaces\main-merges\src[github.com](http://github.com/)\docker\pinata\win\src\Docker.ApiServices\StateMachines\StartTransition.cs:line 92
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Docker.ApiServices.StateMachines.EngineStateMachine.d__14.MoveNext() in C:\workspaces\main-merges\src[github.com](http://github.com/)\docker\pinata\win\src\Docker.ApiServices\StateMachines\EngineStateMachine.cs:line 69
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Docker.Engines.Engines.d__22.MoveNext() in C:\workspaces\main-merges\src[github.com](http://github.com/)\docker\pinata\win\src\Docker.Engines\Engines.cs:line 108
How can I fix the exception error problem?
This is the error I got. How can I remove it?
| at java.base/java.util.Scanner.throwFor(Scanner.java:941)
| at java.base/java.util.Scanner.next(Scanner.java:1598)
| at java.base/java.util.Scanner.nextDouble(Scanner.java:2569)
| at Main.main(Main.java:12)
Attach code snippets (if any)
Screenshots (if any)
Does anyone know what this error message means?
BigCruise.java:7: error: variable cruiseLength might not have been initialized
}
^
1 error
I definitely checked for the closing of brackets, and initialisation of the cruiseLength
variable.. It also seems to run fine on my local machine
Hi prof, is it necessary for us to set up Docker for Labs? What's the benefit of setting up if we can just use code editor and run in cmd?
Hello all! I am looking to improve my programming skills/computational thinking specifically relevant to this module's topics. Given that my only computing experience is CS1010 from a year ago, and suppose that I am willing to dedicate 1-2 hours of extra time per week to self-practice in addition to the module exercises/labs, how best should I go about this?
I was thinking of following a practice problems book (as compact as possible 🤣), though I do not know where to find such a book, but I am open to any other recommended resources as well. Looking forward to any suggestions for resources and/or tips! Thank you!
I am struggling while using the .jsh file. I successfully opened the main.jsh file but it does not allow me to use the methods inside. how should i use it?
Clarifications or details with respect to the issue you are facing
Attach code snippets (if any)
Screenshots (if any)
Attempting self exercise, code compiles fine, but when trying to call the class via jshell, this happens:
Unsure what this error message means. Class has no other modifiers, x and y coordinates are set to private final. Have opened Point.java, Circle.java, and main.jsh already (using /open function).
Within the main.jsh file, it contains functions that directly call upon the Point and Circle classes' variables. Are we allowed to delete these functions?
Under Level 5 of the requirements, we were told to modify the method findMaxDiscCoverage, in this case, does the modification r meant ensure the conformity of the function to encapsulation and Tell-Don't-Ask principles?
Hi there,
I'm trying to do Exercise 2, and I thought having a queue would be rather useful. Are we banned from doing so since queues are mutable?
Thanks in advance!
What is the rounding behavior of the serveCruise() function we should model? As can be seen from the test cases the function rounds arrival time of 1359 to service time of 1400, what cases should this rounding take place? Should it also occur from 29 to 30, 14 to 15 etc.? and what if a loader becomes available at 1203, should it then serve at 1203 or not before 1215?
Nothing is specified about this behavior in the problem statement.
Thank you in advance.
i ran into this compilation error:
Detected serve event not following specifications.
Grading terminated.
have already ensured to upload all files, have getter functions and toString() methods for all classes already. Why am I still encountering such an error?
to import methods like Math.atan, what is the preferred way of importing in cs2030? i understand there are many restrictions on style in this course and couldnt find this in the coding style guide.
should we import java.lang.Math and use Math.atan,
or import static,
or import the specific method only?
hello! How can I make a vim file to .java, .c , .cpp, .h, .jsh, and .py files to upload into the codecrunch?
My code can generate the correct output and i fixed all the codestyle stuff too. Now there’s this error:
“Detected arrival event not following specifications.”
What could this mean?
my EventArrival class has print statements in a method and takes in customer and server classes as inputs.
Hello there,
I have encountered a myriad of warnings from CodeCrunch's style checking,
two of the most frequently repeated ones are:
[WARN] /tmp/home/Circle.java:2: 'member def modifier' has incorrect indentation level 8, expected level should be 4. [Indentation]
[WARN] /tmp/home/Circle.java:2:1: Line contains a tab character. [FileTabCharacter]
I tried to configure the .vimrc file by using: "set shiftwidth=4" or "set shiftwidth=2" or "set autoindent" or "set shiftwidth=4" ...
but none of them work, the warnings either remained the same or became worse.
Has anybody else encountered similar situations?
We are now ready to construct a unit circle whose perimeter passes through two given points. By using the mid-point and angle of line pq, move the mid-point to the centre of the circle of radius r whose perimeter coincides with points p and q. You will need to work out the respective angle and distance values.
This is what is written in the problem. I do not get what does that mean: I do not get how the new circle is formed
Especially, what does the: circle of radius r whose perimeter coincides with points p and q
How can the perimeter same with the points? Does that mean the parimeter is same with the distance between the points p and q?
Hello, I'm encountering this error, but I'm not sure how to interpret it. My understanding is that this means that my class constructors for SolidSphere
and SolidCuboid
do not exist but, I mean, that can't be the case.
Writing these lines in my own jshell seems to work just fine. I've tried uploading my files in order of inheritance too, in case there was some issue in that regard, but that didn't fix anything.
Any help would be greatly appreciated! Thanks :D
From my understanding, the public declaration vs no declaration is meant for defining whether a method is accessible by other packages. Since we are not yet dealing with packages, would current convention be to have no declaration or to have a public declaration for the methods?
I am trying to return a pair of event and customer and assign them to other variables. However, i get a cannot find symbol error for getKey() and getValue() method. How can I resolve that?
my code is as follow:
Pair<Event, Server> pair = new Pair<Event, Server>(new LeaveEvent(this.customer), server);
Event event = pair.getKey();
Server server = pair.getValue();
In excercise 2 level 4, the return type of the method is void. However, the output seems to return a string values. How Can I code it? What should be my return type?
In level 6 of exercise 3, it says that 'Within SolidCuboid, delegate the computation of mass to a SolidImpl property in the class'. What does this mean?
If we submit onto codecrunch, are we allowed to resubmit or are we limited to only 1 submission?
Will Codecrunch run our classes against test cases?
Do we need to submit the jsh file as well?
When I submit my code on CodeCrunch, I am getting a symbol not found error. I understand what the error means, but I am not getting this error on my own laptop, so I'm not sure why it is happening on code crunch. This method is a public method I defined myself within the PQ class to get the size of the priority queue.
public int length() {
return this.pq.size();
}
I am stuck with this problem . I do not now how to design the toString() and nextLoader() method. shall I make a arraylist and print the loaders in order? Shall I just make the string value com out? how can I design it like that? Stuck with the algorithms Can someone give me a hint?
Hi would like to seek clarification on a test case output in Level 5 of the exercise!
Particularly for the 3rd line of output after running serveCruises(cruises, 3)
, I thought that after the BigCruise is loaded in 2 of the 3 loaders, the SmallCruise arriving at 1359 would be able to load in the final remaining loader at 1359 instead, so would like to clarify if the output serviceTime of 1400 is supposed to be an intentional output from the serveCruises
function, or is there a misinterpretation on my part about how Loaders are supposed to work, thank you!
I imported import java.util.ArrayList; to use the .get(int index)
but, when I compile, the error occurs. How should I solve this problem?
Clarifications or details with respect to the issue y
ou are facing
Attach code snippets (if any)
Screenshots (if any)
Submitting current code on CodeCrunch returns
Design specifications violated.
Grading terminated.
Is it possible for me to get a copy of the code/binary that determines whether or not the files violate design specs, so I can get a more verbose output?
My code is split between a few files:
.
├── Event.java Event interface
├── Arrive.java Arrive class that implements Event
├── Leave.java Leave class that implements Event
├── Serve.java Serve class that implements Event
├── Customer.java
├── Server.java
└── Main.java
Some methods from Server
take a Customer
as a parameter, but none from Customer
takes a Server
as a parameter.
N/A
How do I access the value of a private variable from another class without using getter methods?
Using an example:
Customer.java has a variable, private final int customerNumber.
If we are not supposed to use a public getter method for customerNumber and Customer.customerNumber would not work because of the private access modifier, How do I access this variable from another class?
Previously, to bypass this, I created a customerNumber directly in the other class (Server.java) to count the customerNumber. But currently, what if 2 classes needs to access this customerNumber variable?
One solution I can think of is creating a customerNumber counter in each of the class, however this leads to duplicate codes.
Hence, it makes sense to put the customerNumber directly in the Customer.java file to reduce duplication. Thus, how would I be able to access this customerNumber variable?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.