• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 20:26
CET 02:26
KST 10:26
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10
Community News
Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2BGE Stara Zagora 2026 announced15[BSL21] Ro.16 Group Stage (C->B->A->D)4Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win3RSL Season 3: RO16 results & RO8 bracket13
StarCraft 2
General
Chinese SC2 server to reopen; live all-star event in Hangzhou Maestros of the Game: Live Finals Preview (RO4) BGE Stara Zagora 2026 announced Weekly Cups (Nov 24-30): MaxPax, Clem, herO win SC2 Proleague Discontinued; SKT, KT, SGK, CJ disband
Tourneys
RSL Offline FInals Sea Duckling Open (Global, Bronze-Diamond) $5,000+ WardiTV 2025 Championship Constellation Cup - Main Event - Stellar Fest RSL Revival: Season 3
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 502 Negative Reinforcement Mutation # 501 Price of Progress Mutation # 500 Fright night Mutation # 499 Chilling Adaptation
Brood War
General
BW General Discussion Which season is the best in ASL? Data analysis on 70 million replays BGH Auto Balance -> http://bghmmr.eu/ [ASL20] Ask the mapmakers — Drop your questions
Tourneys
[BSL21] RO16 Group D - Sunday 21:00 CET [BSL21] RO16 Group A - Saturday 21:00 CET [Megathread] Daily Proleagues [BSL21] RO16 Group B - Sunday 21:00 CET
Strategy
Current Meta Game Theory for Starcraft How to stay on top of macro? PvZ map balance
Other Games
General Games
ZeroSpace Megathread Stormgate/Frost Giant Megathread Nintendo Switch Thread The Perfect Game Path of Exile
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Mafia Game Mode Feedback/Ideas TL Mafia Community Thread
Community
General
Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread US Politics Mega-thread The Big Programming Thread Artificial Intelligence Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Where to ask questions and add stream? The Automated Ban List
Blogs
James Bond movies ranking - pa…
Topin
Esports Earnings: Bigger Pri…
TrAiDoS
Thanks for the RSL
Hildegard
Saturation point
Uldridge
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1632 users

The Big Programming Thread - Page 480

Forum Index > General Forum
Post a Reply
Prev 1 478 479 480 481 482 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Manit0u
Profile Blog Joined August 2004
Poland17496 Posts
May 13 2014 23:23 GMT
#9581
size_t won't do. I guess I should use vector<T>::size_type
Time is precious. Waste it wisely.
nunez
Profile Blog Joined February 2011
Norway4003 Posts
Last Edited: 2014-05-13 23:42:37
May 13 2014 23:24 GMT
#9582
i used reference in median since that was what manitou used, this changes sorts the indexes in the actual vector ofc. if this is acceptable then that's better than copy.

edit: you can just use auto i think. integer types round down(right?).

alternatively you could enforce the 'default constructibleness' (LOL) with a static assert like so:
template<class T>
T avg(vector<T> const& v){
static_assert(std::is_default_constructible<T>::value,"default constructibleness lacking");
auto size=v.size();
assert(size>0);
return std::accumulate(std::begin(v),std::end(v),T())/size;
}


if you are commited to size_type, you gotta use typename ...::size_type, since the type is dependant on the template.
conspired against by a confederacy of dunces.
Manit0u
Profile Blog Joined August 2004
Poland17496 Posts
Last Edited: 2014-05-14 21:10:38
May 14 2014 21:06 GMT
#9583
I guess I'm overthinking this...


#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>

template<class T>
class Stack
{
public:
T GetSum();
T GetMean();
T GetMedian();
void AddElement(T const&);
void Display();

private:
std::vector<T> elements;
};

template<class T>
void Stack<T>::AddElement(T const& element)
{
elements.push_back(element);
}

template<class T>
void Stack<T>::Display()
{
std::copy(elements.begin(), elements.end(), std::ostream_iterator<T>(std::cout));
std::cout << std::endl;
}

template<class T>
T Stack<T>::GetSum()
{
return std::accumulate(std::begin(elements), std::end(elements), T());
}

template<class T>
T Stack<T>::GetMean()
{
T size = elements.size();
T sum = GetSum();

return sum / size;
}

template<class T>
T Stack<T>::GetMedian()
{
T size = elements.size();
T num = size / 2;

std::nth_element(elements.begin(), elements.begin() + num, elements.end());

return elements[num];
}

int main()
{
// create stacks
Stack<double> doubleStack;
Stack<float> floatStack;
Stack<int> intStack;

// populate stacks
doubleStack.AddElement(7.1);
doubleStack.AddElement(1.3);
doubleStack.AddElement(3.8);
doubleStack.AddElement(8.7);

floatStack.AddElement(7.138);
floatStack.AddElement(1.387);
floatStack.AddElement(3.871);
floatStack.AddElement(8.713);

intStack.AddElement(7);
intStack.AddElement(1);
intStack.AddElement(3);
intStack.AddElement(8);

// display data
std::cout << "Stack of doubles: " << std::endl;
std::cout << doubleStack.Display();
std::cout << "Doubles mean: " << doubleStack.GetMean() << std::endl;
std::cout << "Doubles median: " << doubleStack.GetMedian() << std::endl;

std::cout << "Stack of floats: " << std::endl;
std::cout << floatStack.Display();
std::cout << "Floats mean: " << floatStack.GetMean() << std::endl;
std::cout << "Floats median: " << floatStack.GetMedian() << std::endl;

std::cout << "Stack of ints: " << std::endl;
std::cout << intStack.Display();
std::cout << "Ints mean: " << intStack.GetMean() << std::endl;
std::cout << "Ints median: " << intStack.GetMedian() << std::endl;

return 0;
}


93:35 note: mismatched types `const std::basic_string<_CharT, _Traits, _Alloc>` and `void`

And I'm getting a wall of weird errors, mostly relating to ostream and not being able to convert from void to different chars. What should I do about it?
Time is precious. Waste it wisely.
nunez
Profile Blog Joined February 2011
Norway4003 Posts
Last Edited: 2014-05-14 21:33:48
May 14 2014 21:30 GMT
#9584
dblpost.
conspired against by a confederacy of dunces.
nunez
Profile Blog Joined February 2011
Norway4003 Posts
Last Edited: 2014-05-14 21:35:24
May 14 2014 21:33 GMT
#9585
the Display functions return value is void, so you can't pass the result to std::cout's << operand.
however the printing is done internally in your display function, so you don't have to.
intStack.Display();
would do the trick instead of
std::cout<<intStack.Display();

nitpick on your interface is that getMean, getSum and Display should be const functions.
conspired against by a confederacy of dunces.
Manit0u
Profile Blog Joined August 2004
Poland17496 Posts
Last Edited: 2014-05-14 22:13:02
May 14 2014 21:41 GMT
#9586
On May 15 2014 06:33 nunez wrote:
the Display functions return value is void, so you can't pass the result to std::cout's << operand.
however the printing is done internally in your display function, so you don't have to.
intStack.Display();
would do the trick instead of
std::cout<<intStack.Display();

nitpick on your interface is that getMean, getSum and Display should be const functions.


Doh... That's what you get for trying to do stuff for fun after an entire day of looking at some completely different and unrelated code...

Edit: There were a couple more errors. Didn't make stuff const because the compiler was complaining a lot and I really don't have time or strength for it today.

Anyway, here's a working program if anyone needs anything like that in the future:
+ Show Spoiler +


#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>

template<class T>
class Stack
{
public:
T GetSum();
float GetMean();
float GetMedian();
void AddElement(T const&);
void Display();

private:
std::vector<T> elements;
};

template<class T>
void Stack<T>::AddElement(T const& element)
{
elements.push_back(element);
}

template<class T>
void Stack<T>::Display()
{
std::copy(elements.begin(), elements.end(), std::ostream_iterator<T>(std::cout, " "));
std::cout << std::endl;
}

template<class T>
T Stack<T>::GetSum()
{
return std::accumulate(std::begin(elements), std::end(elements), T());
}

template<class T>
float Stack<T>::GetMean()
{
T size = elements.size();
T sum = GetSum();

return float(sum) / float(size);
}

template<class T>
float Stack<T>::GetMedian()
{
T size = elements.size();
T num = size / 2;

std::nth_element(elements.begin(), elements.begin() + num, elements.end());

return int(size) % 2 ? elements[num] : (elements[num] + elements[num -1]) / 2;
}

int main()
{
// create stacks
Stack<double> doubleStack;
Stack<float> floatStack;
Stack<int> intStack;

// populate stacks
doubleStack.AddElement(7.1);
doubleStack.AddElement(1.3);
doubleStack.AddElement(3.8);
doubleStack.AddElement(8.7);

floatStack.AddElement(7.138);
floatStack.AddElement(1.387);
floatStack.AddElement(3.871);
floatStack.AddElement(8.713);

intStack.AddElement(7);
intStack.AddElement(1);
intStack.AddElement(3);
intStack.AddElement(8);

// display data
std::cout << "Stack of doubles: " << std::endl;
doubleStack.Display();
std::cout << "Doubles mean: " << doubleStack.GetMean() << std::endl;
std::cout << "Doubles median: " << doubleStack.GetMedian() << std::endl;

std::cout << "Stack of floats: " << std::endl;
floatStack.Display();
std::cout << "Floats mean: " << floatStack.GetMean() << std::endl;
std::cout << "Floats median: " << floatStack.GetMedian() << std::endl;

std::cout << "Stack of ints: " << std::endl;
intStack.Display();
std::cout << "Ints mean: " << intStack.GetMean() << std::endl;
std::cout << "Ints median: " << intStack.GetMedian() << std::endl;

return 0;
}

Time is precious. Waste it wisely.
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
May 14 2014 22:27 GMT
#9587
Why do methods start with a capital letter? I've checked some C++ code, and all start with a lowercase letter such as here:
http://www3.ntu.edu.sg/home/ehchua/programming/cpp/cp3_OOP.html
netherh
Profile Blog Joined November 2011
United Kingdom333 Posts
May 15 2014 00:05 GMT
#9588
On May 15 2014 07:27 darkness wrote:
Why do methods start with a capital letter? I've checked some C++ code, and all start with a lowercase letter such as here:
http://www3.ntu.edu.sg/home/ehchua/programming/cpp/cp3_OOP.html


C++ doesn't have fixed style rules / guidelines:

median()
Median()
get_median()
getMedian()
GetMedian()

Take your pick.
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
May 15 2014 00:26 GMT
#9589
On May 15 2014 09:05 netherh wrote:
Show nested quote +
On May 15 2014 07:27 darkness wrote:
Why do methods start with a capital letter? I've checked some C++ code, and all start with a lowercase letter such as here:
http://www3.ntu.edu.sg/home/ehchua/programming/cpp/cp3_OOP.html


C++ doesn't have fixed style rules / guidelines:

median()
Median()
get_median()
getMedian()
GetMedian()

Take your pick.


Well, that's bad for C++ then. However, (some of) C++ STL methods start with a lowercase letter. So why don't you follow the standard?
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2014-05-15 00:46:49
May 15 2014 00:45 GMT
#9590
--- Nuked ---
WolfintheSheep
Profile Joined June 2011
Canada14127 Posts
May 15 2014 00:57 GMT
#9591
On May 15 2014 09:26 darkness wrote:
Show nested quote +
On May 15 2014 09:05 netherh wrote:
On May 15 2014 07:27 darkness wrote:
Why do methods start with a capital letter? I've checked some C++ code, and all start with a lowercase letter such as here:
http://www3.ntu.edu.sg/home/ehchua/programming/cpp/cp3_OOP.html


C++ doesn't have fixed style rules / guidelines:

median()
Median()
get_median()
getMedian()
GetMedian()

Take your pick.


Well, that's bad for C++ then. However, (some of) C++ STL methods start with a lowercase letter. So why don't you follow the standard?


There is no universal standard. There is only "currently accepted standards" which seem to change every decade.

And C++ spans basically very age of coding standards. That means Pascal and Camel case, underscores in variables/methods, underscore prefixes for private, and on and on and on.
Average means I'm better than half of you.
Frudgey
Profile Joined September 2012
Canada3367 Posts
May 15 2014 01:20 GMT
#9592
Do you guys know where I could find any information about running a .py file over multiple computers?

Basically I want to know where I can find any information about running a particular python program over multiple computers. I guess to be more clear, I'd want multiple computers running the same program at the same time. One computer is capable of running the program just fine and it doesn't take very long, but I'd be able to collect data much faster if I could have several computers crunching numbers into the program at the same time.

I'm not sure if I'm describing what it is exactly that I want to do in the right way, so if you have any information that you think might be remotely helpful, or if you could point me in the direction to find said information that'd be much appreciated.

Thanks!
It is better to die for The Emperor than live for yourself.
phar
Profile Joined August 2011
United States1080 Posts
May 15 2014 01:39 GMT
#9593
Some starting points:

https://wiki.python.org/moin/ParallelProcessing
http://blog.cloudera.com/blog/2013/01/a-guide-to-python-frameworks-for-hadoop/
Who after all is today speaking about the destruction of the Armenians?
Cyx.
Profile Joined November 2010
Canada806 Posts
May 15 2014 01:58 GMT
#9594
On May 15 2014 10:20 Frudgey wrote:
Do you guys know where I could find any information about running a .py file over multiple computers?

Basically I want to know where I can find any information about running a particular python program over multiple computers.

I guess to be more clear, I'd want multiple computers running the same program at the same time.

phar's post is a good place to start... I just though having these three sentences one after another was a little overkill rofl
sluggaslamoo
Profile Blog Joined November 2009
Australia4494 Posts
Last Edited: 2014-05-15 05:32:05
May 15 2014 05:29 GMT
#9595
On May 15 2014 10:20 Frudgey wrote:
Do you guys know where I could find any information about running a .py file over multiple computers?

Basically I want to know where I can find any information about running a particular python program over multiple computers. I guess to be more clear, I'd want multiple computers running the same program at the same time. One computer is capable of running the program just fine and it doesn't take very long, but I'd be able to collect data much faster if I could have several computers crunching numbers into the program at the same time.

I'm not sure if I'm describing what it is exactly that I want to do in the right way, so if you have any information that you think might be remotely helpful, or if you could point me in the direction to find said information that'd be much appreciated.

Thanks!


This would be much the same as doing merge sort algorithms over multiple cores I presume. Number crunching can mean a lot of things so you might have to be more specific.

Basically some software have multicore capability built in, you will need to decipher these and learn how to code them manually, so that instead of doing multicore, you are doing multiprocessor. Basically there is almost no difference between the two except that data is transferred over the wire rather than exclusively inside the motherboard.

After that it shouldn't be difficult at all, it would be like torrenting, each computer is given a piece of the pie to number crunch, and it all gets inserted into the final collection. This collection then does a basic sort using presumptions made by the smaller pieces to put everything in order very quickly.

http://en.wikipedia.org/wiki/Merge_sort
Come play Android Netrunner - http://www.teamliquid.net/forum/viewmessage.php?topic_id=409008
3FFA
Profile Blog Joined February 2010
United States3931 Posts
Last Edited: 2014-05-15 12:36:28
May 15 2014 12:35 GMT
#9596
For my AP CS class we are creating the DownloadInfo and MusicDownloads classes(along with a main) from 2013 Question 1: http://media.collegeboard.com/digitalServices/pdf/ap/apcentral/ap13_frq_comp_sci.pdf

As part of this she wants us to check that this segment works properly:
public DownloadInfo getDownloadInfo(String title)
{
for(DownloadInfo info : downloadList)
{
if (info.getTitle().equals(title))
{
return info;
}
}
return null;
}


She told me to write the following in main to check it (unless I misunderstood / misheard) :
DownloadInfo temp = music.getDownloadInfo("Pompeii");
if((temp.getTitle()) == null) //returns false, moves on to else as it should(Pompeii is in the musicList)
System.out.println(temp.getTitle() + " was never downloaded");
else
System.out.println(temp.getTitle() + " was downloaded " + temp.getTimesDownloaded() + " times");

DownloadInfo temp2 = music.getDownloadInfo("Jingle Bells");
if((temp2.getTitle()) == null) //returns a Null Pointer Exception due to not being in the list.
System.out.println(temp2.getTitle() + " was never downloaded");
else
System.out.println(temp2.getTitle() + " was downloaded " + temp2.getTimesDownloaded() + " times");

Any help with determining how to fix this would be great. Thanks guys
"As long as it comes from a pure place and from a honest place, you know, you can write whatever you want."
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
May 15 2014 12:52 GMT
#9597
--- Nuked ---
Amnesty
Profile Joined April 2003
United States2054 Posts
May 15 2014 23:36 GMT
#9598
On May 15 2014 06:06 Manit0u wrote:
I guess I'm overthinking this...


#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>

template<class T>
class Stack
{
public:
T GetSum();
T GetMean();
T GetMedian();
void AddElement(T const&);
void Display();

private:
std::vector<T> elements;
};

.... code removed....


93:35 note: mismatched types `const std::basic_string<_CharT, _Traits, _Alloc>` and `void`

And I'm getting a wall of weird errors, mostly relating to ostream and not being able to convert from void to different chars. What should I do about it?


This is not good design.

Ideally, you wouldn't do this at all. A better design would not having them be members at all because they don't need to be. Then you can use whatever container you wanted too and It would just work. But of course, you cant do that because it would be a failing grade and you need to turn in poop. I had to cringe my way through programming courses before heh.


First It asked for an array class. So make it an array class and not a dynamic array class (vector).
You can't remove elements in your vector approach even though vector can do removes.

You cant use the algorithms on it because you didnt provide the the standard iterator interface.
Its hard to initialize. No constructors taking std::initalizer_list
Don't make display functions member functions. That should be separated. It's hard here because you didnt provide a iterator interface.


#include <algorithm>
#include <iterator>
#include <array>


template<typename T, std::size_t size>
class math_array
{
public:
typedef T* iterator;
typedef const T* const_iterator;

typedef std::reverse_iterator<T*> reverse_iterator;
typedef std::reverse_iterator<const T*> const_reverse_iterator;

iterator begin() { return &data[0]; }
iterator end() { return &data[size]; }

const_iterator begin() const { return &data[0]; }
const_iterator end() const { return &data[size]; }

reverse_iterator rbegin() { return reverse_iterator(end()); }
reverse_iterator rend() { return reverse_iterator(begin()); }

const_reverse_iterator rbegin() const { return reverse_iterator(end()); }
const_reverse_iterator rend() const { return reverse_iterator(begin()); }

T& operator[] (std::size_t index)
{
return data[index];
}
T const& operator[] (std::size_t index) const
{
return data[index];
}

template<class FuncT>
void for_each(FuncT func)
{
std::for_each(begin(),end(), func);
}

T average(T const& i = 0)
{
auto size=v.size();
assert(size>0);
return std::accumulate(std::begin(v),std::end(v),i)/size;
}
/// rest of your math functions already provided...

T data[size];
};


First of all. The only member is a public data. No constructors, everything is public. This makes the class an aggregate type so you can use array initialization on it like you can on regular arrays making it more natural.

Has iterator interface. Overloaded [] operator to make it similar to array.

Here I made a member function called for_each. This is kind of a trade off. It technically does not need to be a member, because there is a global equivalent so this should scream bad design. But after using C# for a long time, i find the member function ForEach's much more readable when you can just pass it a lambda and turn a multi-liner into a one liner. And easier to read code screams good design.



math_array<int,10> f = {3,4,5,56,234,23,4234,234,23423,4234};

f.for_each([](int n)
{
std::cout << n << std::endl;
});




Other thoughts

T average(T const& i = 0) {...}


Having math functions return T is weird. If you have are working with an int's and you run averages and other statistical math functions on it usually you want the decimal places too. Returning float or double causes other problems.
The sky just is, and goes on and on; and we play all our BW games beneath it.
3FFA
Profile Blog Joined February 2010
United States3931 Posts
May 16 2014 00:27 GMT
#9599
On May 15 2014 21:52 Nesserev wrote:
Show nested quote +
On May 15 2014 21:35 3FFA wrote:
For my AP CS class we are creating the DownloadInfo and MusicDownloads classes(along with a main) from 2013 Question 1: http://media.collegeboard.com/digitalServices/pdf/ap/apcentral/ap13_frq_comp_sci.pdf

As part of this she wants us to check that this segment works properly:
+ Show Spoiler +
public DownloadInfo getDownloadInfo(String title)
{
for(DownloadInfo info : downloadList)
{
if (info.getTitle().equals(title))
{
return info;
}
}
return null;
}


She told me to write the following in main to check it (unless I misunderstood / misheard) :
DownloadInfo temp = music.getDownloadInfo("Pompeii");
if((temp.getTitle()) == null) //returns false, moves on to else as it should(Pompeii is in the musicList)
System.out.println(temp.getTitle() + " was never downloaded");
else
System.out.println(temp.getTitle() + " was downloaded " + temp.getTimesDownloaded() + " times");

DownloadInfo temp2 = music.getDownloadInfo("Jingle Bells");
if((temp2.getTitle()) == null) //returns a Null Pointer Exception due to not being in the list.
System.out.println(temp2.getTitle() + " was never downloaded");
else
System.out.println(temp2.getTitle() + " was downloaded " + temp2.getTimesDownloaded() + " times");

Any help with determining how to fix this would be great. Thanks guys

First part of code should work as intended, I think.

In the second part, you're calling temp.getTitle(), even though you just checked that temp == null. You should store the 'search string' ("Pompeii", "Jingle Bells") in a string first, and then reuse those to print the messages (or put the thing in one function, you're basically doing the same thing 2 times).


Yes the first part does work, as I commented.

1) I can't put it in a function because she said I HAVE TO do it in main for this assignment. =/
2) I don't understand why the second part doesn't work. How come calling temp.getTitle() again after checking that temp == null has any effect?
3) Why should I store the 'search string' in a string first?(Probably goes hand in hand with #2)
Lastly, I want to make clear that this is to check whether or not the song titles were downloaded. Pompeii was downloaded, but Jingle Bells was not.
"As long as it comes from a pure place and from a honest place, you know, you can write whatever you want."
Ben...
Profile Joined January 2011
Canada3485 Posts
Last Edited: 2014-05-16 01:17:31
May 16 2014 00:56 GMT
#9600
On May 16 2014 09:27 3FFA wrote:


1) I can't put it in a function because she said I HAVE TO do it in main for this assignment. =/
2) I don't understand why the second part doesn't work. How come calling temp.getTitle() again after checking that temp == null has any effect?
3) Why should I store the 'search string' in a string first?(Probably goes hand in hand with #2)
Lastly, I want to make clear that this is to check whether or not the song titles were downloaded. Pompeii was downloaded, but Jingle Bells was not.

1) That sucks.

2) Because you just checked if the title was null. In the case where it is null, trying to call the getTitle() function to print out that the title was not found will not work because the title doesn't exist in your temp variable in the first place. That is where your null pointer exception is coming from. getTitle() retrieves the title from the song object, but if the title doesn't exist, you can't exactly retrieve it to output it. In the case where it is not null, it will work as you expect. Don't worry, this is a common mistake people just getting used to OO will make. I made it a few times myself back when I was first doing stuff with classes.

This leads to:

3) Since you cannot access the title from within your container of songs (because it is not in your container of music files), having a separate variable that stores the title is useful (for example, if your test fails, you can put
System.out.Println(songTitle + " was not downloaded!")
or something, rather than having to update the error message every time). This will allow more flexibility for your program (if you continue on with CS you will find that having programs that are flexible and can handle many situations are quite useful, and usually expected in assignments). If you replace each time you filled in "Pompeii" and "Jingle Bells" that with a variable storing a song name (just update the variable between songs. IE:
String songTitle = "Pompeii";
...
songTitle = "Jingle Bells";
...

), then you can search for whatever the title you need while only having to update one variable. Ideally, you would create a boolean search function that would return true if the song was found, but it doesn't sound like that is allowed according to your post and the link you provided.

Also, small nit-pick on your comments. You should not use "return" to describe things unless you are actually returning something. In the case of your comments about the if statements, you should use something like "evaluates false" rather than "returns false", since the boolean expression inside the if statement is evaluating whether or not the statement is true, and isn't technically returning anything. It's a small technicality, but it makes it easier for others to understand.

Hopefully I helped a bit.
"Cliiiiiiiiiiiiiiiiide" -Tastosis
Prev 1 478 479 480 481 482 1032 Next
Please log in or register to reply.
Live Events Refresh
Replay Cast
00:00
WardiTV Mondays #62
CranKy Ducklings114
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
PiGStarcraft499
elazer 162
Nathanias 60
CosmosSc2 49
StarCraft: Brood War
Artosis 672
Larva 175
Bale 39
Noble 27
Dota 2
monkeys_forever545
NeuroSwarm46
League of Legends
C9.Mang0241
Counter-Strike
Foxcn222
Other Games
summit1g12507
tarik_tv5188
FrodaN1212
Day[9].tv726
shahzam520
RotterdaM153
Maynarde132
Mew2King65
ViBE33
ToD29
Organizations
Other Games
gamesdonequick741
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 18 non-featured ]
StarCraft 2
• Hupsaiya 51
• davetesta22
• Migwel
• AfreecaTV YouTube
• sooper7s
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
StarCraft: Brood War
• RayReign 41
• Azhi_Dahaki14
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• Ler56
League of Legends
• Doublelift4765
Other Games
• imaqtpie1390
• Day9tv726
Upcoming Events
The PondCast
8h 34m
OSC
14h 34m
Demi vs Mixu
Nicoract vs TBD
Babymarine vs MindelVK
ForJumy vs TBD
Shameless vs Percival
Replay Cast
22h 34m
Korean StarCraft League
2 days
CranKy Ducklings
2 days
WardiTV 2025
2 days
SC Evo League
2 days
BSL 21
2 days
Sziky vs OyAji
Gypsy vs eOnzErG
OSC
2 days
Solar vs Creator
ByuN vs Gerald
Percival vs Babymarine
Moja vs Krystianer
EnDerr vs ForJumy
sebesdes vs Nicoract
Sparkling Tuna Cup
3 days
[ Show More ]
WardiTV 2025
3 days
OSC
3 days
BSL 21
3 days
Bonyth vs StRyKeR
Tarson vs Dandy
Replay Cast
4 days
Wardi Open
4 days
StarCraft2.fi
4 days
Monday Night Weeklies
4 days
Replay Cast
4 days
WardiTV 2025
5 days
StarCraft2.fi
5 days
PiGosaur Monday
5 days
StarCraft2.fi
6 days
Tenacious Turtle Tussle
6 days
Liquipedia Results

Completed

Proleague 2025-11-30
RSL Revival: Season 3
Light HT

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
YSL S2
BSL Season 21
CSCL: Masked Kings S3
Slon Tour Season 2
Acropolis #4 - TS3
META Madness #9
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
Kuram Kup
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.