rage / java-programming Goto Github PK
View Code? Open in Web Editor NEWHome Page: https://java-programming.mooc.fi
Home Page: https://java-programming.mooc.fi
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.
This exercise's examples till part 2, use integer value as weight parameter on class constructors even though weight values have to be double, as stated in the exercise.
Part "When Should Hash maps Be Used?" contains four paragraphs written in Finnish.
In my mind, it supposed to be "5 ", so I tried it, but that failed. So I tried just "5", and that failed too.
Just to make sure I ran the code it did print "5 "
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.
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):
the toString() method attempts to return "this.nimi" which I assume is meant to return "this.name" ?
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.
viestit is left untranslated to English.
Wrong:
if (!viestit.contains(sms)) {
messages.add(sms);
}
Right:
if (!messages.contains(sms)) {
messages.add(sms);
}
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.
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
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.
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.
part04-Part04_11.Film
part04-Part04_12.Gauge
part04-Part04_14.Multiplier
All need โฆ\src\main\java directories created.
Thanks.
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);
}
I thought that the answer was 2, but submitted it and it was wrong. Ran the code in my IDE and got 2 as the answer also, however the quiz says the correct answer is 8.
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();
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.
class diagram is:
[Show]<-*[Ticket]
[Show|- movie: String;- time: String]
[Ticket|- seat: int;- code: int]
there should be:
[Show]<show-[Ticket]
[Show|- movie: String;- time: String]
[Ticket|- seat: int;- code: int]
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.
The import command for Scanner utility is missing in the main java exercise template.
Line 2 : import java.util.Scanner;
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);
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.
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
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.
Hello, I had to create a ".../src/main/java/" directory in the part04-Part04_10.Song exercise to complete the exercise.
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));
In the file Apartment.java at section 5_11, the instance variable princePerSquare
should be written as pricePerSquare
.
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
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.
The exercise text talks about a completed command and a remove command, which appear to do the same, but only the remove command is wanted by the tests and used in the reference solution.
Part07_08.BigYear finish word for "Quit" now in English, which I updated it to be English when the mainProgram is displayed for the demonstration.
TMC return IOException: No space left on device on the tests:
ReadingFilesPerLineTest methodReturnsLines
ReadingFilesPerLineTest methodReturnsLines2
Locally ReadingFilesPerLineTest.java is all green when ran.
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"
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>
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>
https://github.com/rage/java-programming/blob/master/data/slideshows/test-driven-development.pdf has some errors in the code on the right.
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.
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.
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.