Giter Site home page Giter Site logo

2021-s1's People

Contributors

seanlowjk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

2021-s1's Issues

Use of static constants in Java

I'm not sure why private static final isn't accepted for my earlier lab submissions for lab2. Personally, I prefer this:

class SmallCruise extends Cruise {
    //Constants
    private static final int SMALL_CRUISE_NUM_LOADERS = 1;
    private static final int SMALL_CRUISE_SERVICE_TIME = 30;

    public SmallCruise(String id, int arrTime) {
        super(id, arrTime, SMALL_CRUISE_NUM_LOADERS, SMALL_CRUISE_SERVICE_TIME); 
    }
}

to this, since it's more convenient to recognise and change the constant values in the code if the constant were used again:

class SmallCruise extends Cruise {
    public SmallCruise(String id, int arrTime) {
        super(id, arrTime, 1, 30); //1 being number of loaders required, 30 being service time.
    }
}

But I'd get this on CodeCrunch:

SmallCruise.java: SMALL_CRUISE_NUM_LOADERS not declared private final
SmallCruise.java: SMALL_CRUISE_SERVICE_TIME not declared private final

Final variables in methods

Description

In Lab 1 & 2, the concept of using the final keyword for a class's attributes was brought up as a way of ensuring an object's immutability. However, the methods in the code provided in this module don't seem to use the final keyword for their variables. What's the usual practice adopted in CS2030S for variables in methods?

(See https://stackoverflow.com/questions/8306313/final-variable-in-methods-in-java for a Stack Overflow answer on final variables in methods. Other languages such as JavaScript and C also have constructs to create constants.)

Topic:

Coding practices

Screenshots (if any):

NA

Unable to call Ubuntu from Command Prompt

Summary

I have installed Ubuntu successfully and was able to start it by clicking its icon, but when I used Win+R and input "Ubuntu", the computer could not find the software.

Description

Is there sth I can do with the setting maybe?

Screenshots (if any):

image
Ubuntu Icon
image
When I click Ubuntu
image

Do computation before super() in the constructor (BigCruise)

May I please know what should I do if I want to do some calculations or conditional judgments on a and b before I call super? Thank you!

class A extends B {
    public A(int a, int b) {
        // do some calculations or conditional judgments
        super(a, b);
    }
}

class B {
    public B(int a, int b) {

    }
}

".vimrc" E212: Can't open file for writing

I've downloaded and copied the .vimrc file into my directory as shown in the screenshots in https://github.com/nus-cs2030/2021-s1/wiki/Setting-Up-Vim

However, I am unable to open the file for writing as I think it's not even in the directory despite following the instructions and copying the file into it.

It says [New File] when doing the command vim ~/.vimrc

problem2

problem1

Is there suppose to be the formatting text when I open .vimrc using vim? Or must I manually create .vimrc instead and copy all the text formatting and paste it in vim?

Unable to backup file

Description

After adding the .virmc code to my home directory, I am unable to use :wq to save my file and quit. The system shows that it is unable to make a backup file.

Screenshots (if any):

Screenshot 2020-08-14 at 10 01 34 PM

How do I scroll on the Ubuntu terminal when I'm not in vim mode?

I'm currently having trouble scrolling through the Ubuntu terminal. I'm trying to run a file and the terminal printed out a list of errors. However, I can't fully see the error list because I don't know how to scroll on the terminal and thus, am having trouble debugging my code. I searched up online telling me to click Ctrl + page up, however, it is not working for me. I also read up there's an option for setting the limit of lines I can scroll, but I cannot find the option anywhere on my terminal.

Does anyone know how I can scroll on the terminal of Ubuntu when I am not in Vim mode?

Errors were encountered while processing: ca-certificates-java

While I was installing openjdk-11-jdk on WSL for the first time, the progress (after all the unpacking) got stuck at 99%.

I closed Ubuntu LTS, reopened it and tried sudo apt openjdk-11-jdk again and this is what I got:

InstallationError

On another note, javac works fine but the code doesn't execute after java:

InstallationError2

I tried the entire process again by running as administrator and got the same results as above.

Running chromium on WSL

Not sure if this is crucial to the mod but I'm trying to view the javadocs using chromium as shown in Video 7-API as shown at timestamp 13:19.

I am using Windows Subsystem Linux (WSL) Ubuntu 18.04, not sure what other specifications are required so do prompt me on what else would be need and I'll share them here.

I have tried multiple proposed online solutions as shown below but it still doesn't work.

Failed attempts:
Attempted to use google-chrome as shown on WSL/issues
Attempted to use chromium-browser through sudo apt install --assume-yes chromium-browser as shown on ubuntu guide

Alternatively, I could cp the files to my local drive then open normally but it's tedious.

Lecture 3: Liskov's Substitutability Principle

Hi, I have a question about Lecture 3 materials, in particular on Liskov's Substitutability Principle.

I would like to ask what is the intended outcome of the method scaleBy?

  1. If UnitCircle uc = new UnitCircle(p), is uc.scaleBy(2) supposed to return back a UnitCircle with the same properties (no change in radius), return a Circle (but not UnitCircle) with radius 1, or return a Circle with radius 2?
  • In Slide 6, in the comment of the 3rd jshell // uc remains :), it suggests that returning a UnitCircle is correct.
  • In Slide 7, in the comment of the 2nd jshell // Still valid?, it suggests that returning a UnitCircle is wrong, by the virtue of the ?.
  • In the lecture recording from 53:20 to 54:35, the lecturer says that we should return back a UnitCircle if the factor is 1, and return back a Circle with the radius changed if the factor is not 1. So he is suggesting that returning a Circle with radius 2 is correct.
  1. If Circle c = new UnitCircle(p), is c.scaleBy(2) supposed to return back a UnitCircle with the same properties (no change in radius), return a Circle (but not UnitCircle) with radius 1, or return a Circle with radius 2?
    It is a similar question to Q1, but I am wondering what is the intended outcome. Only after understanding what the intended outcome is then we can consider how the code should be written.

'vim' not recognized

Command prompt shows ''vim' is not recognized as an internal or external command,
operable program or batch file.' when i type vim -version

Also where do I put/how to use the .vimrc thing?

Vim not sourcing vimrc

Summary

My vim does not apply the vimrc settings no matter where I put the vimrc file. Settings such as tabstop is set to 8 instead of the 4 in vimrc.

Description

I have tried to put the vimrc in different folders within Ubuntu. However, no matter where I put the vimrc file. Vim does not apply the settings within .vimrc at all in vim. For example, the tabstop=4 setting in vimrc is not applied, but instead the default setting of tabstop=8 is applied

Screenshots (if any):

Slide1
Slide2
Slide3

Compiler Quirks

Hey guys,
Just a point of clarification regarding superclasses and subclasses.
So if I had

class A { int x; A(int x) { this.x = x; } A method() { return new A(x); } double git(int j){ return j + 2.20; } }

and

class B extends A { private int y; B(int x, int y) { super(x); this.y = y; } B method() { return new B(x, y); } double git(int j, int i) { return j + i + 2.20; } }

A a = new B(2,3) would compile, but subsequently a.git(2, 3) would fail as this exact method is only defined in the subclass and not the superclass. So to confirm, even if a subclass object has a superclass reference, the subclass constructor method can still be "seen" by the object, but every other method that is not defined in the superclass cannot?

How does the mechanism behind this work?

Another question is, if I have a parent class implementing. an interface, and a subclass extending the parent class, is it taken automatically that I am implementing the interface that is implemented by the parent class?

Github Account Info Survey

Summary

Hi I would just like to check for the Github Account Info Survey on Luminus, Q2 asks us to enter our NUSNET ID, but it also says it's the number starting with A. From my knowledge, NUSNET ID is the one starting with E, while the number starting with A is our Matric Number, so I would just like to clarify which number are we supposed to input. Thanks!

Description

NIL

Screenshots (if any):

NIL

Vim Error E510: Can't make backup file (add ! to override)

Hello,

I copied the .vimrc content provided here into my own .vimrc file, but then I started to encounter this error whenever I try to save (:w) or save and exit (:wq) my java file.

Screenshot 2020-09-07 at 4 10 33 AM

The only way for me to overcome this currently is to include the "!' symbol after :w or :wq.

I'm not really sure how to solve this.
Would appreciate the help, thanks! :)

Lab2 Level 6

It seems that the lab in codecrunch has an additional level (level 6: Recycled Loaders). Where do we get the test files related to this?

Also, do we create a new class RecycledLoaders.java ?

Lab2

Hi, I was trying to perform this:
image

But i get this error. What should I do?
image

Error encountered when installing java

Hi! I'm running on macOS Sierra 10.12 and the JDK version i'm using is 11.0.8 as per instructed. I have followed the steps accordingly but have been stuck at Setting Up Java part for a few days. Particularly these two commands

sudo apt update
sudo apt install openjdk-11-jdk

when ran will throw this error:
Unable to locate an executable at "/Library/Java/JavaVirtualMachines/jdk-11.0.8.jdk/Contents/Home/bin/apt" (-1)

I have looked at many forums and stackexchange posts and tried exporting the JAVA_HOME file to different locations as suggested (not too sure if this is the real root cause?) but all to no avail.. Some forums also mentioned macOS does not support apt so I'm also confused. Apologies if this is not the correct place to raise questions or I have used the wrong format...

Lab 1 maxDiscCoverage

Description

I managed to pass the testcases given but not on the codecrunch. What's wrong?

Topic:

public int findMaxDiscCoverage(Point[] points){
int maxDiscCoverage = 0;

for(int i = 0; i < points.length - 1; i++){
	for (int j = i + 1; j <  points.length; j++){
		int counter = 0;
		if(distb(points[i],points[j]) <= 2){
			Circle c = createUnitCircle(points[i],points[j]);
			for (Point p: points){
				if (contains(c,p)){
					counter++;
				}
			}
		}
	if (counter > maxDiscCoverage);
	maxDiscCoverage = counter;
	}
}		
return maxDiscCoverage;

}

public double distb(Point p, Point q){
double dx = p.x - q.x;
double dy = p.y - q.y;
return Math.sqrt(dx * dx + dy * dy);
}

public boolean contains(Circle circle, Point p){
return distb(circle.centre, p) <= circle.radius;
}

Screenshots (if any):

Insert Images here if necessary

Lecture 4 Clarification

Screenshot 2020-09-10 at 5 21 51 PM

Hi, I would like to clarify this code from the lecture video.
'<? super Burger>' dictates that 'box' can only point to any superclasses above the Burger Box.
In this case, the 'box' is pointing to a new Burger Box as stated by the "new Box " and therefore we are able to put a Burger into the Burger Box via 'box.put(new Burger());'

However, I am not too sure how the 'new CheeseBurger()' works. Does the output mean that we are creating an empty Normal Burger Box and at the same time it also contains a CheeseBurger object? If so, must we always have an object inside when we create a box as seen in all the examples thus far? or is it possible to just create an empty Burger Box.

Lab 2 issues

I got this issue:
Loader.java: cruise not declared private final
Loader.java: identifier not declared private final
Grading terminated.

For level 6, what I think of it is that recycled loader inherits from loader class.
So why couldnt i set the variable fields to protected instead?
I can pass all the test cases in the test.jsh file.
This seems to be counter-intuitive.

Writing Java Code in Vim

Can anyone recommend something so that my vim will be like video 4 in LumiNUS? When I typed the code and the suggestion will jump out like when I use eclipse? When I type { and press enter for a new line I will get a } in the following line and my cursor is in between?

while (something) { // cursor is here and I press enter

while (something) {
    // cursor is here
}

Thanks a lot.

Unable to highlight in WSL Ubuntu 18.04

Unable to highlight in WSL Ubuntu 18.04

Hi guys, I am using the WSL Ubuntu 18.04 but I am unable to use my mouse to highlight texts. Same goes for copying and pasting into the unix terminal. Would really appreciate any advice for this issue faced

Description

I downloaded Ubuntu 18.04 from microsoft app store and I have even uninstalled and reinstalled the WSL but it still does not support highlighting of text

The weird thing is that I did the exact steps on my friend's Windows computer and in that computer, the highlighting is available by default after the WSL Ubuntu 18.04 is downloaded from the microsoft app store...

/edit throwing X11 Display Error in jshell (Resolved)

Summary
Running into exception thrown when executing /edit

Description
Was trying out vim/jshell during first lecture. However, ran into an error when wanting to edit sets of codes within jshell. Specifically, I tried /edit, with the following errors (Ref. to Screenshot).

I've also tried (export DISPLAY=:0.0) w/o parentheses, and removing the ".0" at the end, with no avail. I know jshell is meant for simple testing, but worries me if it's to bring up another issue in future.

1

Unable to run 'javac HelloWorld.java'

I followed the video and created a helloworld.java file on vim. When trying to compile it using javac, I encountered the issues as seen in the photo attached. Please help!
image

How to log in to CodeCrunch?

There was an announcement to access the lab 1 problems on CodeCrunch: https://codecrunch.comp.nus.edu.sg

Question: How to log in to CodeCrunch?
Is it the NUSNET ID (Exxxxxxx), or NUSSTU\Exxxxxxx, or the comp.nus.edu.sg username?
Is the password same as the one tagged to NUSNET or to the comp.nus.edu.sg?

Question: How to reset password if we forget the password?
The reset button on https://codecrunch.comp.nus.edu.sg only resets the form, it does not bring me to a page to reset the password.

PE1

Summary

Hi all, does anyone know when PE1 will be conducted. Thanks!

Description

NIL

Screenshots (if any):

NIL

What else do I need to add to my vimrc file?

I copied and pasted the .vimrc file provided but when I watch the videos on Luminus I realised some features on the vim in the videos is not present in my own vim (such as auto completing brackets or suggesting a list of possible code when I am typing code like java.util). What else do I need to add to my .vimrc file? Thanks.

Checkstyles for assessments

Summary

Will we have checkstyles during our assessment? Any style to recommend on vim?

Description

Describe the question here if necessary

Screenshots (if any):

Insert Images here if necessary

Symbol not found error

Description

Hi,
I was trying to code in the stuff from the lecture, but i keep running into a symbol not found error.
The error is in one of the 4 screenshots. The other 3 are for each of the classes: Point, Circle, and Main.
What is the issue here?

Screenshot 2020-08-17 at 12 44 51 PM

Screenshot 2020-08-17 at 12 44 51 PM

![Uploading Screenshot 2020-08-17 at 12.44.23 PM.png…](
![Uploading Screenshot 2020-08-17 at 12.44.23 PM.png…](

Screenshots

Screenshot 2020-08-17 at 12 44 18 PM

Screenshot 2020-08-17 at 12 44 18 PM

Screenshot 2020-08-17 at 12 44 21 PM

Screenshot 2020-08-17 at 12 44 21 PM

Screenshots (if any)

Question about compile-time and run time

Description

Hi am actually about confused about compile and run-time. For a method call A.method(B), What does the Compile-time type of A decide? and what does compile-time type of B decide? How about the runtime type of A and B? What do they decide about which exact method to call?

Topic:

Specific Topics this question is related to (If Any)

Screenshots (if any):

Insert Images here if necessary

CS2030 Question & Answer Guidelines

Hey All! 😄

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!

  1. If you have a new question, create a new post instead of posting it as a reply on someone else's unrelated question. Use an issue template to be able to refer it back later using the Labels feature!

  2. 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.

  3. 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)

  4. Github Issues supports powerful formatting. If your post or reply contain code, using proper formatting to make your post readable. For example:

public void sayHello() {
    System.out.println("Hello World!");
}
  1. 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 AY19/20 Semester 2 Piazza Forum]

Difference between interface and abstract class

Description

Hi, i would to ask what is the difference between an interface and an abstract class? why abstract class can implement new methods + write empty methods for sub-classes, while interface can only write empty methods for sub-classes and gives error if we try to implement a new method in it?

Topic:

Lecture 3 substitubability in OO design and interfaces

Lecture 4 on Superclasses

Hi! If I have a superclass A that implements interface B, and several subclasses (e.g. C) that inherit from superclass A, then must I write class C extends A implements B, or can I just write class C extends A and it will be taken that C will also be able to implement the methods from the interface B? Thanks!!

Unable to run sudo commands due to not being able to update local UNIX password

Hello,

Upon installing ubuntu I was prompted to enter username and password, which I did, but did not note the password I entered

Upon running sudo apt update and being prompted to enter password, I got "sorry, try again"

I then went to https://docs.microsoft.com/en-gb/windows/wsl/user-support and followed the instructions under "forgot your password" and successfully changed my UNIX password in Powershell.

However, going back to ubuntu and being prompted to enter password when running sudo commands, I still got "sorry, try again"

I tried to uninstall ubuntu but could not find it under control panel "uninstall programs"

image

Would appreciate any feedback on this.

Yexuan

Encountered error: Unable to access jarfile ./checkstyle-8.2-all.jar

Hello, I'm currently trying to set up checkstyle on terminal.
Runningjava -jar ./checkstyle-8.2-all.jar -c ./cs2030_checks.xml *.java throws Error: Unable to access jarfile ./checkstyle-8.2-all.jar. But the xml and jar files are in my current directory though, i have moved the xml and jar files to where my java files are located and have changed directory to where the java files are located, as pointed out kindly by Terence. I have also downloaded the dummy java file and moved it to the same directory. However the same error is shown.
image

Replacing the ./ with the entire path of where the java files were located does not work either:
java -jar **/Library/Java/JavaVirtualMachines/adoptopenjdk-14.jdk/Contents/Home**/checkstyle-8.2-all.jar -c /**Library/Java/JavaVirtualMachines/adoptopenjdk-14.jdk/Contents/Home/**cs2030_checks.xml *.java

Sorry for the trouble! ** i cant add a label to this post but its a Technical Issue

Cannot source ~/.vimrc

Summary

Cannot source ~/.vimrc

Description

I copy pasted the stuff from .vimrc into home dir(~). When I try to source it this happens:

filetype: command not found
filetype: command not found
-bash: ,: No such file or directory
-bash: /home/sora/.vimrc: line 28: syntax error near unexpected token 'newline'
-bash: /home/sora/.vimrc: line 28: 'set formatoptions+=r " auto insert comment leader after hitting '

Screenshots (if any):

Screenshot (11)
Screenshot (12)

Windows Subsystem for Linux 2 may cause laptop ethernet cable to stop working.

On the official Microsoft WSL installation guide (https://docs.microsoft.com/en-us/windows/wsl/install-win10), there is a step on updating to WSL 2 which requires enabling the 'Virtual Machine Platform'. There is a chance that doing will result in your laptop being unable to connect to the internet via an Ethernet cable.

If you are facing this issue, revert back to WSL 1 and disable the 'Virtual Machine Platform'.

To disable 'Virtual Machine Platform',
Go to 'Control Panel/Programs/Turn Windows features on or off'
and uncheck 'Virtual Machine Platform'.

image

Lecture 2 Static Binding & Typecasting

Description

Hi guys, I am a question regarding the typecasting in the code for explaining Static Binding.

Topic:

Static Binding, Typecasting

Screenshots

Prof explained that we had to typecast obj by doing (Point) obj so that obj can be recognised as Point class type.
image

In the code for explaining Static Binding, both the Circle and FilledCircle had to be typecasted as Circle.
I don't understand because:

  1. The first element in the array is already of a Circle object so why must it be typecasted?
  2. Why are we typecasting the second element as (FilledCircle)?
    image

I hope I'm making sense! Would appreciate any help :)

Is is possible to import packages in .jsh file to use ArrayList?

I was just wondering if it's possible to use import packages into .jsh files to use certain things like ArrayList. I've tried to put in ArrayList and even put in 'import java.util.ArrayList' into the file, however when I try to run it, I got errors about how the variables aren't declared and the .Add() function from ArrayList is not declared.

Thus, I'm wondering if it is possible to import packages like ArrayList and use them in .jsh files.

Arrays, Covariance and LSP

image

This slide implies that code written for Shape[] will work for when it's substituted for Circle[]

However shapes[0] = rectangle works but not circles[0] = rectangle (ArrayStoreException)

So how can we say that Circle[] is a subtype of Shape[]?

Vim AutoComplete Plug in

Summary

Want to know how our vim can be like the one in the videos where we don't need to type everything word by word.

Description

Suppose I want print out sth, I need to write:
System.out.printf("%s says Hello World!\n", this.name);
But the teacher has some auto completed things for him to choose.

I installed supertab but it is not as powerful as the teacher's is.

Is it achieved by adding some Plug-ins? If yes, what is the name of it?

Screenshots (if any):

image

Setting alias for checkstyle

Based on the checkstyle provided in the guides, we have to run the following command to check:

java -jar ./checkstyle-8.2-all.jar -c ./cs2030_checks.xml [YOUR_JAVA_FILES]

Has anyone successfully set up an alias for checkstyle so that we only need to run the following:

checkstyle Point.java

Unable to download Ubuntu

I am unable to download Ubuntu on Microsoft Stores. It is stuck at the starting download page but it does not load for hours :').
Screenshot

Error running java: Cannot execute binary file: Exec format error

Hello, I am setting up my checkstyle files and have downloaded the checkstyle jar and cs2030 xml files and put them in the same directory as my java files. However when I try running $java -jar ./checkstyle-8.2-all.jar -c ./cs2030_checks.xml *.java it displayed -bash: /usr/bin/java: cannot execute binary file: Exec format error. I've checked that my window version is 64 bit and I set up java using the two commands given for Ubuntu. I tried checking my java with $whereis java and it showed a correct directory. But when I typed $java -version, it showed -bash: /usr/bin/java: cannot execute binary file: Exec format error. Why does this happen and is there a way to resolve this error?

/open does not work on jshell

I used VSC to make my circle.java, point.java, and main.java files
I keep trying to open them using jshell and the /open command, but to no avail.
I tried setting the classpath within jshell, and there is still no difference.
The program runs on the terminal outside Jshell.

all my files are within the the directory that I set the classpath to.

Screenshot 2020-08-24 at 1 15 39 PM

Kindly assist,
Thank you

Lecture 4 regarding generic type and parameterised type

Description

After today's lecture and did some read up, i was a bit confused about the generic type and parameterised type. What are they referring to actually, like example Box T. Is Box T generic, and the parameterised type is T? sorry is couldnt write the diamond here

Topic:

Generics

Screenshots (if any):

Insert Images here if necessary

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.