Coding challenge #2 We need to go deeper

in #programming7 years ago

Hi everyone,

We've got some awesome contributions in our last coding challenge.

First of all, like promised my solution of the challenge:
https://pastebin.com/7QcxjVpu

But your contributions are at least as good!

But now, let's get to the point.
This next coding challenge is all about objects.

Objects?

Yes, Object-oriented programming has become one of the most successful programming paradigms because of the ease to map real-world problems to code.

Since you've shown in the previous challenge that you know your way around loops, switch-case, random numbers and reading or writing from and to the console, I feel we're ready for this.

The next coding challenges will build upon each other to have our first little project to show off to our friends, family, dogs or cats, so stay tuned.

You can show it to your goldfish as well (Please don't wake up your Hamster yet)

The task will be the following:

You will create one class called "Movie"
This class will have several variables:
Title (String), Overview(String), Genre (String[]), release-date(String) + any other info you would like.

After you created this class I want you to create several objects of this class
That means, you will create instances of your "Movie" filling the variables you previously defined.

In order to fill those movies let the user at the console define the number of movies he wants to create and then let him type the data in the console.

Following this you will store all those movies in a List/Set/Map/Array and print them out to console.

Hint: create a .toString method in your movie class

IMG_20170729_210816.jpg

Don't feel down! Start coding!
If you have any questions or problems just write it into the comments so I can help you!

Sort:  

Looking perfectly fine =)

nice post ;)

Congratulations @raycoms! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes received

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

The above code is not working out the way i thought it would. I am going to leave it though and see if I can get the issue figured out. it is in my if/else statements, I know that. just not sure what to do about it yet.

So, I have spent the last few hours redoing the code (I am still new to Programming) and basically had to change all of it.

Now I keep getting a null pointer exception, where just a bit ago, I wasn't. Right when the user needs to hit a number 1-4 to choose the genre of the movie.

Before this, it ran fine until I asked the user if they would like to enter another movie. That throws an exception about a missing element. I am putting the code up.

https://pastebin.com/w1qQY5aM

Please take a look and help me to understand what happened.

I put comments in the code regarding the issue.

Thank You,

Gene @btcworker

Hi @btcworker, the issue is that:

private static ArrayList"Movie" movieA;

Is not initialized you have to do:

private static ArrayList"movie" movieA = new Arraylist""();

Additionally, I would create the class "Movie" in a separate file and call it from another file with the main class.

This is not only important for readability but will also help us to extend the program later on.

Keep on coding!

P.S: I had to remove the > and the < tags because steemit doesn't like them =)

Besides that your variables in the movie should not be static

Thanks for the help on it. The only reason I didn't create it in a separate file/class was because i thought it was supposed to be one file.

I also already posted my solution in the next challenge or if you need any more help, just ask =)