Code Monkey home page Code Monkey logo

java-programming's Introduction

Material template

This repository contains both the source code of this course's webpage and the source for the content of the course. The content is located in the data folder and everything else is for the website.

Contributing to the content

If you spot a mistake, feel free to open an issue in this repo after consulting with the course assistants.

If you'd help us making the correction, you can open a pull request with your proposed changes. You may find these resources helpful for doing this:

Development environment

Below are instructions on how to setup a development environment on your own machine. These instructions are only relevant to you if you wish to change how the course's website works or looks like. If you don't know how to program or only wish to contribute to the content of the course, please skip this section.

Requirements: recent Node

npm ci
npm run develop

Content is in the data folder.

Custom markdown components are located in src/partials

If you want to use local, unpublished version of moocfi-quizzes for testing, run ./use-local-quizzes.sh before running the application. If your configuration differs from the default, add the path to the moocfi-quizzes as the first argument to the script. An illustration of the default configuration:

  (parent directory)
  /                \ 
(this repo)      [quizzes](https://github.com/rage/quizzes)
                      |
                  packages
                      |
                  moocfi-quizzes

Sometimes when making certain type of changes to the queries, you may wish to restart Gatsby automatically each time the development server exits. To accomplish this you can run the script: ./develop-loop.sh.

Authors

Material template created by Henrik Nygren and Antti Leinonen.

License

Material template

Copyright 2018 Henrik Nygren, Antti Leinonen, and the Agile Education Research group.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Course material

The course material is licensed under a Creative Commons BY-NC-SA 4.0 license.

java-programming's People

Contributors

2kofawsome avatar adikaiser avatar avihavai avatar avrh avatar benattenborough avatar concernedhobbit avatar d471061c avatar david145noone avatar dmitrilc avatar gamingdevilscc avatar gardalic avatar jarnovirta avatar jfmajer avatar josephkenny avatar joystickchevron avatar karkkieila avatar kevin0110w avatar ljleppan avatar nghian95 avatar nurou avatar nygrenh avatar redande avatar reettap avatar rgada28 avatar s4ndyk avatar snehasj avatar stadibo avatar ukonhattu avatar utkarsh1311 avatar vilmakoo 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  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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

java-programming's Issues

Typo in EqualsAndArrayList quiz 8.3

viestit is left untranslated to English.

Wrong:

if (!viestit.contains(sms)) {
    messages.add(sms);
}

Right:

if (!messages.contains(sms)) {
    messages.add(sms);
}

Duplicate Typo in Part 2 / 1-Problems and Patterns

For the quiz "Executing conditional statements" the question and code are duplicated and mentioned twice. Once left-aligned, and the other center-aligned.

quiz id="cf7bfa61-dc45-56f2-8913-fa8671dbfc4d"

image

introduce method references and use them in part 13 to enable/improve testing

although lambda expressions do have their place, they have the same problem as anon inner classes: you cannot access them easily, so testing, also from the students perspective, is hard. To improve testability use method references instead,
like this::digitHandler, which will allow the (pack private ) void digitHandler(event) to be tested separately. That would allow testing the business of the handler.

Type erasure is misrepresented in Part 12, Locker example.

The example code mis represents type erasure and makes it look like the Locker has been specialized by the compiler. That is not how Java works. All occurrences of type are replace by Object, and at the call site a cast to the proper type is applied.
Locker knows nothing of its content.

public class Locker {
    private Object element;
    public void setValue(Object element) {
        this.element = element;
    }
    public Object getValue() {
        return element;
    }
}

At the call site the compiler knows that the cast is allowed:

  String r = (String) Locker.getValue();

Generic information is primarily used by the compiler to proof the code. Once it is satisfied it removes (erases) the generic information. The drawback is that that information is hard to retrieve at runtime. The benefit is that you do NOT have to specialize classes, and fore-most that the compiler can do its job of ensuring type-safeness. Also type-erasure allows backward compatibility, you can mix old (compiled code) and new.

Typo in Part03_02.SecondPlusThird

In Line 20, the word 'luvut' has been given instead of the word 'numbers'. This results in the local run tests to not compile and results in an error.

Existing line : System.out.println(luvut.get(0));
Corrected line : System.out.println(numbers.get(0));

Error in code (Santa's Workshop Exercise, Part 6, sub-part 1)

In the part 6 of the course, one of the example use case in exercise Santa's Workshop in sub-part 1 (Objects on a list and a list as part of an object) contains a code error. Because the class name is Package, in the example code the object is instantiated with the following code:
Package package = new Package();.
This code does not compile because "package" is a Java keyword and cannot be used as an identifier. I suggest renaming the object something error-less. Below, I present the screenshot where the issue happens at.

image

Bug in Test Package for Part 03_32 PersonalDetails

The prompt in the exercise states: "If multiple names are equally longest, you can print any of them."

In test3(), the longest names are "martin" and "mickey". However, the test only accepts "martin" as the correct answer instead of both "martin" and "mickey" since both are 6 characters long.

It was not confusing for me to figure out and change my solution to work with the 'correct' name, but I could see how it could be potentially confusing and frustrating for people who might not see it immediately.

Typo in Part 6, Sub-part 1, Height Order Exercise Part 1

In part 6, sub-part 1, part 1 of the exercise "Height Order" contains a typo that causes the code not to compile. I attach a screenshot of the erroneous part below. (The sysout statement in red rectangle) The issue is that the class name (Person) , rather than the variable name (person), is used inside the enhanced for loop.

image

Quizzes won't complete, and 500 error on checking score.

Trying to answer the "Overloading a constructor" quiz. After clicking submit the submit button greys out. Whilst trying to checking scores I get the error "Fetching progress data failed with the following error: Error: Request failed with status code 500"

Typo in 5_11 Apartment.java

In the file Apartment.java at section 5_11, the instance variable princePerSquare should be written as pricePerSquare.

Illegal reflective access by org.netbeans.ProxyURLStreamHandlerFactory

TMCBeans (the snap package) does not launch by clicking its icon in the start menu (at least on Solus Linux 4.1 running the Plasma 5.18.4 desktop). The solution is to launch it from the terminal, when doing so it launches like normal, with the following message:

WARNING:` An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.netbeans.ProxyURLStreamHandlerFactory (file:/snap/tmcbeans/5/tmcbeans/platform/lib/boot.jar) to field java.net.URL.handler
WARNING: Please consider reporting this to the maintainers of org.netbeans.ProxyURLStreamHandlerFactory
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

Part 8 ToDoList

The description states, "Create a class called ToDoList. It should have a constructor without parameters and the following methods:"

When you run the code it checks for a class called TodoList instead of ToDoList.

More mistructured exercises.

part04-Part04_11.Film
part04-Part04_12.Gauge
part04-Part04_14.Multiplier
All need …\src\main\java directories created.
Thanks.

Java Programming, Part 1, Section 4: Media and technology use questionare not visible

Seen here: https://java-programming.mooc.fi/part-1/4-variables

Above the quiz that asks you to do a questionnaire, the questionnaire is missing and replaced with the following error:

Cannot load a part due to an error:
Error: Network Error

I primarily use Firefox (version 84.0.1) on Windows with uBlock Origin. I turned off uBlock Origin for a moment to see if it was that, but the same error persisted. The same is true in Chrome (version 87), both with uBlock Origin on and off.

exercise part1 6.3 and 6.4 (still) have finish names in the exercise repo.

When downloading the tasks for week 6, task 6.3 and 6.4 still appear under a finish name.
This can be fixed in the pom file.
part 6.3

 <artifactId>Part06_03.MessagingService</artifactId>
    <name>Part06_03.MessagingService</name>

part 6.4

 <artifactId>Part06_04.PrintingACollection</artifactId>
    <name>Part06_04.PrintingACollection</name>

Part 8/2 Error in comments

The first example in "Hash map as an Instance Variable" contains wrong comments.
image

Should be:
image

Tested with the following code:
image

Allow range of jdks in pom profile selection of javafx exercises

Students and teachers alike like to play with the newest things.
Java 8 is boring, Java 11 is already ancient and Java 15 (at the time of writing) is the newest release.
However, the profile selection in the pom files allows either java 8 or java 11.
By changing the activation value from 11 to e.g [11,16) (Open range start at 11 and accept everything below 16) would
allow the us of newer java versions than 11. See snippet below.

<id>java11</id>
      <activation>
           <jdk>[11,16)</jdk>
      </activation>

Programming exercise: Health station (3 parts) - Error in main() given on webpage

https://java-programming.mooc.fi/part-5/4-objects-and-references#programming-exercise-nullpointerexception

Main program given as
`public static void main(String[] args) {
// example main program for the first section of the exercise

HealthStation childrensHospital = new HealthInstitution();

Person ethan = new Person("Ethan", 1, 110, 7);
Person peter = new Person("Peter", 33, 176, 85);

System.out.println(ethan.getName() + " weight: " + childrensHospital.weigh(ethan) + " kilos");
System.out.println(peter.getName() + " weight: " + childrensHospital.weigh(peter) + " kilos");

}`

In the above,
HealthStation childrensHospital = new HealthInstitution();
should instead be
HealthStation childrensHospital = new HealthStation();

image

Typo in Part 9 - Interfaces

public class ReadingList implements Readable {
    private ArrayList<Readable> readables;

    public ReadingList() {
        this.readables = new ArrayList<>();
    }

    public void add(Readable readable) {
        this.readables.add(readable);
    }

    public int luettavia() {
        return this.readables.size();
    }

The "luettavia()" is not translated to English. It should be "toRead()"

This code is before the "Interface In A Box" exercise

Part1_10.story

My test cases were not passed because of error, which i think is probably because in second example when entered Ada and a Data Scientist , it print "a" two times.
We haven't taught anything advance to deal with this type of issue in course till now.
Can you please look into the matter and help.
Thanks & Regards,
Trapti.

Part 1 / 5-calculating Typo

Duplicate text in Quiz Division (quiz id = a1b73ba2-e36e-5db5-99d3-991c502a94ea)

Couldn't find where quizzes are located to try and solve this typo, if anybody can point me in the right direction I can try and fix it myself and open a new pull request.

image

Typo in Part 4 Exercise 7

Constructor is named Item in description when it should be named Product to correspond to class name.

Annotation 2020-04-08 085757

Misleading / wrong use of term throughout the course

The term "parameter" is used throughout the course to describe an argument passed to a method, function or class.
A parameter is the described inputs where the method, function or class is authored (ie. the actual method definition fx.).
"argument" should instead be used about the values passed on invocation.

I've created this issue as i believe how we communicate about code is vital - specially at the "beginner stage" as "poor" definitions, like this one, leads to blog posts, conversations, documentation etc. down the line with misleading terms.

Part 13-5: Example not working, invalid method names

The code example in the section "Separating application logic and user interface logic" is broken. Partly because some of the method names have not be translated. But also because, for example, there is no Person class which would be needed for this code to actually run... I'm not totally sure what needs to be done so I won't be touching it for now

Part12_10.MagicSquare: bug in sumsAreSame method

Hi. First of all, thank you for presenting such a great course.

I think there is a bug in exercise Part12_10.MagicSquare. The sumsAreSame method of the MagicSquare class does not work properly.

In the following code:

    public boolean sumsAreSame() {
        ArrayList<Integer> sums = new ArrayList<>();
        sums.addAll(sumsOfRows());
        sums.addAll(sumsOfColumns());
        sums.addAll(sumsOfDiagonals());

        if (sums.size() < 3) {
            return false;
        }

        for (int i = 1; i < sums.size(); i++) {
            if (sums.get(i - 1) != sums.get(i)) {
                return false;
            }
        }

        return true;
    }

The method's purpose is to check if all elements in sums are of the same value. But since the type of element in sums is Integer which is a reference type, comparing two elements using != will produce true for two Integer objects that contain the same value. IMHO, it seems that the comparison wrongly compares reference of the two objects instead of their values in logic.

A possible fix could be:

for (int i = 1; i < sums.size(); i++) {
    if (!sums.get(i - 1).equals(sums.get(i))) {
        return false;
    }
}

Or:

if (sums.stream().distinct().count() > 1) {
    return false;
}

This bug will further affect isMagicSquare method of MagicSquare class, which makes the last part of this exercise confusing.

[Part 3-2][Index of smallest]: Test case does not cover for multiple smallest number.

In example from material, program is be able to detect index from multiple smallest number
but test case does not cover it and let program that detects only single smallest number passes.

Example program

72
44
8
8
11
9999

Smallest number: 8
Found at index: 2
Found at index: 3  // Pass

User program

72
44
8
8
11
9999

Smallest number: 8
Found at index: 2    // Pass but it should not.

Potential defect in Part04_31.SportStatistics - Test Case winsAndLosses3()

Possibly require the following changes in SportStatisticTest.java (?):

-- io.setSysIn(fileName + "\nspiderman\n");
++ io.setSysIn(fileName + "\nsuperman\n");

-- assertTrue("With the file:\n" + textToWriteToTheFile + "\nWhen searcing for superman the output should have the line \" Wins: 0\".\nthe output was:\n" + io.getSysOut(), lines(io.getSysOut()).stream().filter(l -> l.contains("Wins: 0")).count() == 1);
++ assertTrue("With the file:\n" + textToWriteToTheFile + "\nWhen searcing for superman the output should have the line \" Wins: 1\".\nthe output was:\n" + io.getSysOut(), lines(io.getSysOut()).stream().filter(l -> l.contains("Wins: 1")).count() == 1);

The tests pass after making these changes locally.

Here's the original unit test:

    @Test
    @Points("04-31.2")
    public void winsAndLosses3() {
        String fileName = "file1.txt";
        String textToWriteToTheFile = "bestTeam,superteam,32,34\nbatman,superman,30,31\nbatman,robin,1,0\ncats,dogs,3,0";
        deleteAndCreateNew(fileName, textToWriteToTheFile.split("\n"));
        io.setSysIn(fileName + "\nspiderman\n");
        
        try {
            SportStatistics.main(new String[]{});
        } catch (Exception e) {
            fail("Error when running the program: " + e.getMessage());
        } finally {
            deleteFile(fileName);
        }
       
        assertTrue("With the file:\n" + textToWriteToTheFile + "\nWhen searcing for superman the output should have the line \" Wins: 0\".\nthe output was:\n" + io.getSysOut(), lines(io.getSysOut()).stream().filter(l -> l.contains("Wins: 0")).count() == 1);
        assertTrue("With the file:\n" + textToWriteToTheFile + "\nWhen searcing for superman the output should have the line \" Losses: 0\".\nthe output was:\n" + io.getSysOut(), lines(io.getSysOut()).stream().filter(l -> l.contains("Losses: 0")).count() == 1);
    }

I'm wondering if it should be:

@Test
    @Points("04-31.2")
    public void winsAndLosses3() {
        String fileName = "file1.txt";
        String textToWriteToTheFile = "bestTeam,superteam,32,34\nbatman,superman,30,31\nbatman,robin,1,0\ncats,dogs,3,0";
        deleteAndCreateNew(fileName, textToWriteToTheFile.split("\n"));
        io.setSysIn(fileName + "\nsuperman\n");
        
        try {
            SportStatistics.main(new String[]{});
        } catch (Exception e) {
            fail("Error when running the program: " + e.getMessage());
        } finally {
            deleteFile(fileName);
        }
       
        assertTrue("With the file:\n" + textToWriteToTheFile + "\nWhen searcing for superman the output should have the line \" Wins: 1\".\nthe output was:\n" + io.getSysOut(), lines(io.getSysOut()).stream().filter(l -> l.contains("Wins: 1")).count() == 1);
        assertTrue("With the file:\n" + textToWriteToTheFile + "\nWhen searcing for superman the output should have the line \" Losses: 0\".\nthe output was:\n" + io.getSysOut(), lines(io.getSysOut()).stream().filter(l -> l.contains("Losses: 0")).count() == 1);
    }

Typo on Equals quiz 8.3

The word nimi is left untranslated to English in this quiz. The code will not compile as is.

Wrong:
this.nimi.equals(compared);

Right:
this.name.equals(compared);

Typo in code snippet, Part 6, Sub-part 1, "Cargo Hold" Exercise, Part 4

There is a typo in the example code of the exercise named "Cargo Hold (Part 4)", which is located in the subpart-1 of the Part 6 of the course. The task instruction requests the student to write a method named "printGoods()" but the example code snippet includes a method named "printItems()". The method name in the instruction should be renamed to "printItems()" because the underlying unit tests check for the existence of a method named "printItems()".

Below is the code where this error happens.

image

[Part6] Quiz points

There's only one quiz in Part6 under Complex programs section worth 1 point.
But the evaluator is considering it worth 5 points and hence showing only 20% is completed.

Typo Part 4 exercise 15 Statistics

In part 4 exercise 15 the following sentence appears in its description where 'in the' is written twice:

Create a class Statistics that has the following functionality (the file for the class is provided in the in the exercise template):

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.