• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 14:48
CEST 20:48
KST 03:48
  • 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
Code S Season 1 - RO8 Preview3[ASL21] Ro8 Preview Pt2: Progenitors8Code S Season 1 - RO12 Group A: Rogue, Percival, Solar, Zoun13[ASL21] Ro8 Preview Pt1: Inheritors16[ASL21] Ro16 Preview Pt2: All Star10
Community News
Maestros of The Game 2 announcement and schedule !2Weekly Cups (April 27-May 4): Clem takes triple0RSL Revival: Season 5 - Qualifiers and Main Event12Code S Season 1 (2026) - RO12 Results12026 GSL Season 1 Qualifiers25
StarCraft 2
General
Code S Season 1 - RO8 Preview Behind the Blue - Team Liquid History Book Weekly Cups (April 27-May 4): Clem takes triple Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool Code S Season 1 (2026) - RO12 Results
Tourneys
Maestros of The Game 2 announcement and schedule ! GSL Code S Season 1 (2026) Sea Duckling Open (Global, Bronze-Diamond) RSL Revival: Season 5 - Qualifiers and Main Event Sparkling Tuna Cup - Weekly Open Tournament
Strategy
Custom Maps
[D]RTS in all its shapes and glory <3 [A] Nemrods 1/4 players
External Content
Mutation # 524 Death and Taxes The PondCast: SC2 News & Results Mutation # 523 Firewall Mutation # 522 Flip My Base
Brood War
General
Do we have a pimpest plays list? BGH Auto Balance -> http://bghmmr.eu/ (Spoiler) Asl ro8 D winner interview BW General Discussion AI Question
Tourneys
Small VOD Thread 2.0 [ASL21] Ro8 Day 4 [BSL22] RO16 Group Stage - 02 - 10 May [ASL21] Ro8 Day 3
Strategy
Simple Questions, Simple Answers Fighting Spirit mining rates What's the deal with APM & what's its true value Any training maps people recommend?
Other Games
General Games
Dawn of War IV Nintendo Switch Thread Stormgate/Frost Giant Megathread OutLive 25 (RTS Game) Daigo vs Menard Best of 10
Dota 2
The Story of Wings Gaming
League of Legends
G2 just beat GenG in First stand
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
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas TL Mafia Community Thread Five o'clock TL Mafia
Community
General
US Politics Mega-thread European Politico-economics QA Mega-thread The Letting Off Steam Thread Russo-Ukrainian War Thread 3D technology/software discussion
Fan Clubs
The IdrA Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [Req][Books] Good Fantasy/SciFi books
Sports
2024 - 2026 Football Thread McBoner: A hockey love story Formula 1 Discussion
World Cup 2022
Tech Support
streaming software Strange computer issues (software) [G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
How EEG Data Can Predict Gam…
TrAiDoS
ramps on octagon
StaticNine
Funny Nicknames
LUCKY_NOOB
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1932 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
Poland17743 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
Poland17743 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
Poland17743 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
Next event in 5h 12m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 508
Hui .218
BRAT_OK 64
MindelVK 10
StarCraft: Brood War
Calm 3884
ggaemo 133
Hyuk 126
Hyun 26
IntoTheRainbow 14
Sacsri 13
NaDa 7
Dota 2
Gorgc5812
qojqva1824
monkeys_forever296
Counter-Strike
fl0m2132
kRYSTAL_44
Heroes of the Storm
Liquid`Hasu268
XaKoH 123
Other Games
gofns8914
Grubby5386
Liquid`RaSZi1352
FrodaN1315
B2W.Neo970
ceh9646
C9.Mang0285
420jenkins252
RotterdaM202
QueenE79
Mew2King72
Trikslyr55
mouzStarbuck38
Organizations
Other Games
gamesdonequick2774
StarCraft 2
angryscii 20
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 15 non-featured ]
StarCraft 2
• StrangeGG 80
• intothetv
• AfreecaTV YouTube
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• 80smullet 14
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• imaqtpie2021
• TFBlade1306
Other Games
• Shiphtur299
Upcoming Events
Replay Cast
5h 12m
Escore
15h 12m
The PondCast
15h 12m
WardiTV Invitational
16h 12m
Zoun vs Ryung
Lambo vs ShoWTimE
Big Brain Bouts
21h 12m
Fjant vs Bly
Serral vs Shameless
OSC
1d 3h
Replay Cast
1d 5h
CranKy Ducklings
1d 15h
RSL Revival
1d 15h
SHIN vs Bunny
ByuN vs Shameless
WardiTV Invitational
1d 16h
Krystianer vs TriGGeR
Cure vs Rogue
[ Show More ]
uThermal 2v2 Circuit
1d 20h
BSL
2 days
Artosis vs TerrOr
spx vs StRyKeR
Replay Cast
2 days
Sparkling Tuna Cup
2 days
RSL Revival
2 days
Cure vs Zoun
Clem vs Lambo
WardiTV Invitational
2 days
BSL
3 days
Dewalt vs DragOn
Aether vs Jimin
GSL
3 days
Afreeca Starleague
3 days
Soma vs Leta
Wardi Open
3 days
Monday Night Weeklies
3 days
OSC
4 days
CranKy Ducklings
4 days
Afreeca Starleague
4 days
Light vs Flash
Replay Cast
5 days
Replay Cast
6 days
The PondCast
6 days
Liquipedia Results

Completed

Proleague 2026-05-05
WardiTV TLMC #16
Nations Cup 2026

Ongoing

BSL Season 22
ASL Season 21
CSL 2026 SPRING (S20)
IPSL Spring 2026
KCM Race Survival 2026 Season 2
Acropolis #4
SCTL 2026 Spring
RSL Revival: Season 5
2026 GSL S1
BLAST Rivals Spring 2026
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026

Upcoming

Escore Tournament S2: W6
KK 2v2 League Season 1
BSL 22 Non-Korean Championship
YSL S3
Escore Tournament S2: W7
Escore Tournament S2: W8
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
Maestros of the Game 2
2026 GSL S2
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
IEM Atlanta 2026
Asian Champions League 2026
PGL Astana 2026
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 © 2026 TLnet. All Rights Reserved.