• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 11:55
CEST 17:55
KST 00:55
  • 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
[ASL22] Ro16 Preview: Holy Diver1[ASL22] Ro16 Preview: Rough Waters10[ASL22] Ro24 Preview: Siren's Call8[ASL22] Ro24 Preview: Summer's End9Serral wins HomeStory Cup 2915
Community News
StarCraft open world shooter announced at BlizzCon72Weekly Cups (Aug 30-Sep 7): herO thrives amid growing schism10Official StarCraft website teases new content ahead of BlizzCon?172Stellar Fest TWO the Moon (Dec 16-20)9Weekly Cups (August 24-30): Patches' balance mod takes over3
StarCraft 2
General
StarCraft open world shooter announced at BlizzCon How do you feel about the StarCraft shooter announcement at BlizzCon 2026? Balance hotfix patch 5.0.16b (July 16) Team Liquid Map Contest #22: Results and Winners Weekly Cups (Aug 30-Sep 7): herO thrives amid growing schism
Tourneys
Sparkling Tuna Cup - Weekly Open Tournament RSL goes to London! 2026 Offline Finals Nov 21-22 KSL Week #92 IntoTheTV X SOOP SC2 League : Weekly & Monthly 2026 GSTL Announcement
Strategy
[G] Having the right mentality to improve
Custom Maps
Nexus Wars 2021 GUIDE [M] (2) Industrial Park
External Content
The PondCast: SC2 News & Results Mutation # 542 The Ascended Mutation # 541 Binary Choice Mutation # 540 Dodge This
Brood War
General
[ASL22] Ro16 Preview: Holy Diver Official StarCraft website teases new content ahead of BlizzCon? ASL22 General Discussion BGH Auto Balance -> http://bghmmr.eu/ Broodwar Prediction Market
Tourneys
[ASL22] Ro16 Group C [ASL22] Ro16 Group B [ASL22] Ro16 Group A Escore Tournament - Season 3
Strategy
Replay Review Process - What do you do? Simple Questions, Simple Answers Odyssey Mineral Stack Saturation Game Theory for Starcraft
Other Games
General Games
Diablo IV Nintendo Switch Thread EVE Corporation [Maplestory Hardcore] Let's Play~!! General RTS Discussion Thread
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
[TL LoL EUW IHs] Teemo shall perish TSM pausing esports and CLG Dead
Heroes of the Storm
Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
TL Mafia Community Thread
Community
General
UK Politics Mega-thread US Politics Mega-thread Things Aren’t Peaceful in Palestine Trading/Investing Thread Russo-Ukrainian War Thread
Fan Clubs
MarineLorD Fan Club The Creator Fan Club The ShoWTimE Fan Club
Media & Entertainment
[Manga] One Piece Movie Discussion! Diablo Animated Series on Netflix
Sports
Football (Soccer) Thread TeamLiquid Health and Fitness Initiative For 2023 MLB/Baseball 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Northern Ireland Global Starcraft
Blogs
Virtual Romance, Real-Life C…
TrAiDoS
Regacy Esports:Our Goa…
regacyesports
Dreaming of BW patches (mod…
c3rberUs
LOCKPICKING NOOB
LUCKY_NOOB
Customize Sidebar...

Website Feedback

Closed Threads



Active: 6536 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
Poland17843 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
Poland17843 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
Poland17843 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 5m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 587
Tasteless 173
Rex 104
SHIN 62
RotterdaM 19
Railgan 16
StarCraft: Brood War
Britney 42888
Calm 5624
Jaedong 924
PianO 681
firebathero 337
Shuttle 249
ggaemo 220
Artosis 186
910 91
Bonyth 72
[ Show more ]
Mini 66
Sea.KH 63
Mong 60
Hyun 57
Liquid`Ret 45
sSak 38
Sharp 26
Trap 23
Rock 20
HiyA 15
Hm[arnc] 14
SilentControl 11
Shine 8
Dota 2
qojqva3882
syndereN873
Fuzer 272
LuMiX1
Super Smash Bros
Mew2King103
Heroes of the Storm
MindelVK6
Liquid`Hasu1
Other Games
Grubby3241
Liquid`RaSZi1318
singsing1301
Hui .187
QueenE139
Organizations
Other Games
EGCTV1308
StarCraft 2
StarCraft495
Heroes of the Storm
Heroes of the Storm377
Other Games
gamesdonequick280
StarCraft 2
ComeBackTV 90
StarCraft: Brood War
Afreeca ASL 53
Kim Chul Min (afreeca) 15
[ Show 15 non-featured ]
StarCraft 2
• StrangeGG 85
• Adnapsc2 36
• mYiSmile136
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• Migwel
StarCraft: Brood War
• Michael_bg 11
• FirePhoenix8
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Nemesis3806
Other Games
• Shiphtur158
Upcoming Events
RSL Revival
5m
Serral vs Rogue
BlizzCon
2h 35m
IdrA vs MC
Afreeca Starleague
18h 5m
Light vs JyJ
Soulkey vs hero
WardiTV Weekly
19h 5m
Monday Night Weeklies
1d
Afreeca Starleague
1d 18h
Snow vs Shinee
Shine vs EffOrt
GSL
1d 19h
PiGosaur Cup
2 days
The PondCast
2 days
Kung Fu Cup
2 days
[ Show More ]
Replay Cast
3 days
KCM Race Survival
3 days
IntoTheTV X SOOP
3 days
Replay Cast
4 days
IntoTheTV X SOOP
4 days
Replay Cast
5 days
GSL
5 days
Replay Cast
6 days
GSL
6 days
Shopify Rebellion Sundays
6 days
Spirit vs Mixu
Liquipedia Results

Completed

Acropolis #5 - TRS
PiG Sty Festival 8.0
Big Dog Cup 2026 Div 1

Ongoing

KCM Race Survival 2026 Season 3
K-JUNGMAN
ASL Season 22
Super Anchor Qualifying S3
CSL 2026 AUTUMN (S22)
Acropolis #5
Blizzard Classic Cup 2026
Blizzard Classic Cup 2026
RSL Revival: Season 6
Calamity Invitational
FISSURE Playground #3
BLAST Open Fall 2026
Esports World Cup 2026
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
Stake Ranked Episode 3
XSE Pro League 2026

Upcoming

Acropolis #5 - GSA
Acropolis #5 - GSB
Acropolis #5 - GSC
SC4ALL II: Brood War
HSC XXX
Stellar Fest 2: Lunar Cup
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
RSL Offline Finals
PGL Major Singapore 2026
Stake Ranked Episode 6
BLAST Rivals Fall 2026
IEM Beijing 2026
Stake Ranked Episode 5
PGL Masters Bucharest 2026
1win Private Club #2
Thunderpick World Champ. '26
ESL Pro League Season 24
Stake Ranked Episode 4
1win Private Club #1
Logitech G Play Connect 2026
SL StarSeries Fall 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.