Welcome to the home repository for CS2030! 😃
To find out more about how to contribute, click here!
CS2030 repository and wiki for AY 2021/2022 Sem 2
License: MIT License
Welcome to the home repository for CS2030! 😃
To find out more about how to contribute, click here!
In the announcement, it stated to submit our work incrementally. Does it mean we submit the work after every level?
For Level 6, assuming loaders is a list of Loaders and RecycledLoaders, I used the below for loop:
for (Loader loader : loaders)
However, when I reach a loader that happens to be a RecycledLoader, the methods executed are taken from the Loader class instead of the RecycledLoader class. Is anybody able to explain why this happens as I thought it was covered during Lecture that writing "Loader" before it only checks whether the methods exist when compiling, and that the actual method run will be from the RecycledLoader class? Thank you!
Writing in these scripts means it is much harder for me to check and debug.
I can only /open the script in jshell and trust that it works which isn't very ideal.
Is there a way to "compile" them using a compiler?
I happened to have java 17 installed on my MacBook and when I open it in terminal after following the setting up instructions it shows version 17.0.1. Is it ok? Do I need to uninstall java 17 and install java 11 instead? I tried to uninstall java 17 but I failed to do it.
I use Windows 10 to set up Ubuntu and Java. During the set up of Vim, I followed the guide closely, but encountered a series of issues.
(1) The guide said that Windows users can set up Vim in your Ubuntu environment, OR install it locally. However, no guide is provided about “how to set up Vim in your Ubuntu environment”. Furthermore, I am also deeply confused about how both choices will this affect our usage of Vim. How should I use Vim if I install it locally, and how if in Ubuntu environment?
(2) Since I cannot find the guide to set up Vim in Ubuntu environment, I proceeded to download it locally. However, it shows “vim is not recognised as an internal or external command” when I type "vim -version" in the Command Prompt. I saw in GitHub that I should add vim to PATH, but how should I add it, and what should I type?
(3) I saw at the start of Vim local installation guide that we are supposed to get the .vimrc file. But when I clicked the link, it is a GitHub page. Searching online, I tried to click “raw” then right click on the webpage shown to download the file. However, the saved file become a txt, and no longer .vimrc file. May I know how this can be resolved?
(4) The wiki page about "set up checkstyle" gives the instruction that after downloading 2 files, we should "Make sure you place these 2 files in the same directory as your java files". But where should we place the java files? Do we need to copy and paste these 2 files every time we copy our java files to a new place?
I have submitted my solution for lab 4 which included a service class that was a parent class for the various cab services provided. The service class did not have any constructors and upon submission did I then realize that actually I could have submitted an abstract class instead, which in this case would have seemed to be more appropriate. I was just wondering if there are any particular conditions for us to look out for as to when to implement an abstract class?
Does anyone know how to /open all files in jshell? I know that to open multiple files we can do /open file1.java file2.java and so on but how do we open all the files, probably something like /open *.java
I am able to clear all the test cases/checks on code crunch but I came across this warning (uncheked method invocation) when attempting lab01.
From google, this error seems to be due to not declearing the type for the List. But i used List "Point"in my method. Do anyone have any idea what this is about?
Thank you.
class ImList<T> {
private final ArrayList<T> elems;
public ImList<T>() {
elems = new ArrayList<T>();
}
public ImList<T>(List<T> list) {
elems = new ArrayList<T>(list);
}
}
Why does adding in the constructor throw these errors:
ImList.java:7: error: <identifier> expected
public ImList<T>() {
^
ImList.java:11: error: <identifier> expected
public ImList<T>(List<T> list) {
^
2 errors
Specific Topics this question is related to (If Any)
Screenshots (if any)
Hi, I have faced this error when trying to clear level 5.
My code currently works for the test cases in level 5, but fails in codecrunch. I used a nested for loop within a for loop, with a while loop inside. Please advise if its a problem of algorithmic inefficiency or other errors I may not have foreseen.
What is the difference between the "Pure" and "Impure" interfaces, and what are they? This is mentioned in the footnote of slide 7 in lecture 5. Thank you!
Interface
Hi prof,
will we be going through more about List.
Seems like question 2c) of Problem set requires us to know the methods of List.
Or are we supposed to read up on our own?
Hi Prof @hwkchia
Will we be briefed on how PE1 will be like?
What format will it be?
What restrictions do we have?
Any past year questions?
im using windows 11 and i have trouble downloading the vimrc file. has anyone with windows figured out how to do that?
Describe the problem and how one can replicate this problem
Insert Images here if necessary
Does anyone know why I am unable to loop through the setting of my RecycledLoader?
From what I understand from the test output, it appears that my code seems to always forgo the if condition and go straight to the else condition. When I print out the list of loaders to check, the existing RecycledLoaders dont seem to be modified while everything else is fine. I have faced no issues with the generating of new RecycledLoaders if required. Is there anything I am missing out on? Does it have to do with the way my RecycledLoader class is implemented?
A snippet of my code is as follows, the only difference between this and level 5 is the addition of an if condition to decide whether to set a new RecycledLoader or Loader:
Has anyone using macOS properly configured their vimrc file yet? I can't seem to locate it. Thanks!
When I run ubuntu or wsl, nothing happens.
I am facing an issue with the installation of Unix when I followed this guide: https://github.com/nus-cs2030/2122-s1/wiki/Setting-Up-Unix-For-Windows
I managed to finished up to step 5 of Running Powershell to install Ubuntu. However, I was not able to continue to the “launching wsl” step. This is because nothing happens when I run Ubuntu and I have also tried the alternate option of running wsl but similarly, wsl does not open.
I have tried following the other guides as well: https://github.com/nus-cs2030/2122-s2/wiki/Setting-Up-Unix-For-Windows#launching-wsl and https://github.com/nus-cs2030/2021-s2/wiki/Setting-Up-Unix-For-Windows but I also had problems with these.
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!");
}
If you post about a problem you faced, please provide all the information (what you have done, what error message you faced) to help the readers of this forum help you. E.g., "My program cannot compile. Can you please help?" is not a meaningful post.
[Guidelines adapted from CS2030 AY20/21 Semester 2 Forum Guidelines]
Hopefully, you have a wonderful time taking this module and learning Java!
Best regards,
Russell
Your lovely CS2030 alumni 😊
JDT not activating despite creating a file called 'HelloWorld.java'
I use mac and on my terminal, I managed to create a file using 'vim HelloWorld.java' as what is shown in the Luminus 'Intro to Java' video. However, in the video, right after creating the HelloWorld file, the JDT started loading and activating but this is not the case for me. Instead, the supposed 'Java' file acted more like a regular txt file (see image attached) and I'm assuming it's because my JDT does not activate automatically. Is anyone else a mac user and also experiencing such a problem? Does anyone know how to fix this? Any input would greatly help. Thank you!
Hi Prof is immutability just having a setter method that returns a new object? Shouldn't the client create a new object instead of relying on the setter method of an existing object?
Specific Topics this question is related to (If Any)
Screenshots (if any)
`
Lab04 require "BookingStub" class but this is not mentioned in task.txt.
I fail at this question where it has implicit requirement on this class "BookingStub" and variable "list", but this requirement is not mentioned in the task.txt. I have my own implementation that can pass the sample test cases but failed at codecrunch. My worries is that in the PE where we only have one time to submit the code, how can we know the class names and variable names required by the grader which is not explicitly mentioned in task.txt?
Attach code snippets (if any)
Screenshots (if any)
I created a RecycledLoader class which has a method cruise.getServiceCompletionTime(), but cannot access it since the cruise has private access in Loader. I tried changing it to protected, which works, but is not accepted on codecrunch. Does anyone know how to solve this? Thank you!
I face a problem that whenever i want to copy the command line from the task.txt to the jshell, it will not be able to run it????
task.txt says that
You should aim to make the Booking class general such that it does not
need to check for any invalid pairing
Thus, I baked the services each driver provides into the methods within each driver class (i.e. NormalCab and PrivateCar). Is this considered hardcoding?
NormalCab.java
...
public Service bestService(Request req) {
Service ser1 = new JustRide();
Service ser2 = new TakeACab();
...
Would it be better to implement something like
NormalCab.java
class NormalCab implements Driver {
private static final ImList<Service> SERVICES
= new ImList<Service>(List.of(new JustRide(), new TakeACab()));
private final String id;
private final int waitTime;
...
It seems less hardcoded as information about services are retrieved from a single property, and is also more scalable if each driver decides that it can take on more than 2 services. However, it makes the code much more complex. Am I overengineering?
@OverRide throws an error when a class implements a method from an interface.
When I code my interface in a separate file and then implement that interface from a class then @OverRide throws me an error. But when I write my interface in the same .java file as the class, @OverRide works. Why is that the case? Does that mean we shouldn't use @OverRide when a class implements a method of an interface?
If I get A for CodeCrunch, does it mean I am coding correctly?
I created a new class SingleServiceBooking, that takes in a service, request and driver. It is similar to Booking class, but it only takes in service.
I used it to make SingleServiceBooking for each services a driver can have.
For example, the test case,
findBestBooking(new Request(20, 3, 1000), List.of(new NormalCab("SHA1234", 5), new PrivateCar("SMA7890", 10)))
I will make 4 SingleServiceBooking objects, that will compare among themselves and sort based on lowest fare and time.
I would like to know if making extra classes when the question does not ask for it is allowed, and if it is the right way of coming up with the code for the question, since I am not using Booking class in level 5.
Hi prof, just to clarify line 7 & 8 in the constructor does nothing right since you get a new ImList when you add()
And even if you want to assign it coord you can't do it since line 6 is already an assignment and coord is a final variable.
Specific Topics this question is related to (If Any)
I'm not to sure how to go about tackling level 5 for lab 2.
I have trouble thinking of how to complete the check and move if the number given for method move(int num) is able to cause a change in the puzzle.
Attach code snippets (if any)
Screenshots (if any)
Hi everyone!
I have been reading up on Static and Dynamic binding and I might have made a couple of misconceptions. Would it be appropriate to say that method overriding is essentially dynamic binding taking place because you are giving the method a new definition while running the programme? In that regard, would method overloading thus be an aspect of static binding? If that is the case how would new function definitions be stored in byte code for the same method name? It just doesn't seem to make sense how a function can take on so many abilities..?
Thanks for the help!
Polymorphism
I was doing Lab 4 and I couldn't decide if I should use an abstract class or Interface to represent Services/ Drivers. I was wondering if there was a way to better determine which is more suitable to use
I'm quite confused about LSP and overriding. It seems to me that as long as you override you're violating LSP since you're changing the implementation and behavior of a method in the superclass.
Edit: Additionally, isn't the definition very subjective.
eg if the customers were very picky then the third son would violate LSP. So Only the son who brews beverages exactly like the father satisfy LSP (no overriding)
LSP & Overriding
Screenshots (if any)
I am a windows 10 user. Today I managed to configure the recommended .vimrc for my vim in ubuntu, as instructed in the lesson wiki page. However, ever since that, each time when I press :w or :wq to save my file, an error message will pop out -- Vim error E510: Can't make backup file (add ! to override). So now I can only press :w! or :wq! to save my file.
Later I found that this probably has something to do with the instructions to create backup files in the configured .vimrc file. I checked some Stackoverflow, but still not clear what exactly to do. Anyone can help?
I downloaded vim 8.2 and when i check vim -version on powershell it shows version 8.2. However when on Ubuntu it shows 8.0.
Also, im not able to launch WSL as the wiki explained i.e. "windows logo + R" , type "Ubuntu". It says theres no such name so i have to open ubuntu by opening it. Lastly, the working with .vimrc step, im not able to find the path as theres only the ext4 in my localstate. i followed the steps properly so im not sure what is wrong.
Describe the problem and how one can replicate this problem
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.