• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 12:01
CET 17:01
KST 01:01
  • 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] Finals Preview: Sweet Victory!12[ASL22] Ro4 Preview: Mirror Mirror6[ASL22] Ro8 Preview: Within Reach5[ASL22] Ro8 Preview: In A Tizzy11[ASL22] Ro16 Preview: Holy Diver5
Community News
Weekly Cups (October 19-25): Clem triples first in 5.0.175Evil Geniuses - shutting down20ISSL (IntoTheTV x SOOP SC2 League): Premier6Weekly Cups (October 12-18): 5.0.17 era begins1[$1250] International ShieldBattery League92
StarCraft 2
General
No more SC2 streamers on team liquid? Weekly Cups (October 19-25): Clem triples first in 5.0.17 How do you feel about the mass reverts in the 5.0.17 PTR? Evil Geniuses - shutting down REPORT: StarCraft 2: Remastered In Development
Tourneys
ISSL (IntoTheTV x SOOP SC2 League): Premier Stellar Fest TWO the Moon (Dec 16-20) RSL 2026 Offline Finals LCQ Sign-Ups Sparkling Tuna Cup - Weekly Open Tournament 2026 KungFu Cup Announcement
Strategy
[H] ZvP Mid-Late Game: Stalkers Collossi HT
Custom Maps
Simple Questions/Answers [G] How to playtest arcade maps [A] Nemrods 1/4 players
External Content
Mutation # 549 Endless Sparkles The PondCast: SC2 News & Results Mutation # 548 Shining Bright Mutation # 547 Temple Of Terror
Brood War
General
SCHNAIL now supports Remastered Rollback Netcode in Brood War BW General Discussion [Megathread] Daily Funny Videos SC4ALL II Brood War Complete Invited Player Lineup
Tourneys
[Megathread] Daily Proleagues [Women's StarCraft] MonstarZ vs BA 2026-10-30 Star Con San Diego 2026 Small VOD Thread 2.0
Strategy
50,000-Word Terran Builds Memo 2026-10-22 Cliff Jump Revisited (1 in a 1000 strategy) Simple Questions, Simple Answers
Other Games
General Games
Nintendo Switch Thread Stormgate/Frost Giant Megathread Mobile Legends: Bang Bang Armies of Exigo - YesYes? General RTS Discussion Thread
Dota 2
Dota 2 Champions League Season 3 Begins April 25!
League of Legends
[TL LoL EUW IHs] Teemo shall perish
Heroes of the Storm
Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
TL Mafia Community Thread
Community
General
US Politics Mega-thread European Politico-economics QA Mega-thread R I P Patrick Stewart Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine
Fan Clubs
Reynor Fan Club The Flash Fan Club Serral Fan Club
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece
Sports
TeamLiquid Health and Fitness Initiative For 2023 Football (Soccer) Thread MLB/Baseball 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Recent Gifted Posts
Blogs
Innovate or Game Over?
TrAiDoS
ShieldBattery on Mac
Kraekkling
[ASL22] Ro4 Day1 Ticket Giv…
bITt.mAN
Can Bots Beat Pros?? Starcr…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 8935 users

The Big Programming Thread - Page 437

Forum Index > General Forum
Post a Reply
Prev 1 435 436 437 438 439 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.
Badboyrune
Profile Blog Joined May 2010
Sweden2247 Posts
February 02 2014 19:59 GMT
#8721
On February 02 2014 20:05 teamamerica wrote:
Show nested quote +
On January 29 2014 09:01 Badboyrune wrote:
Ok I'm getting quite confused. I'm making a pretty basic android app, it's my first so my experience is very limited. It basically displays data from a database based on intent sent from the intent sent from another activity in the app. This all worked fine, I could navigate without any issue with the android OS back button.

However when I enable "getActionBar().setDisplayHomeAsUpEnabled(true);" and try to navigate backwards with the Home button that breaks any activity that relies on receiving an intent, because it doesn't receive any. I tried putting the information in the onSaveInstanceState bundle, but the activity does not receive the bundle when navigated to with the Home button (savedInstanceState != null returns false).

I've looked through all I've been able to find online (which has been limited because searches involving android home button are generally unhelpful) and all I've really been able to find is that the home button seems to not be programmable anymore, it either sends you to the app home activity, or the activities parent activity which is what I'm trying to achieve. I'm assuming there's some way of doing this so any help would be much appreciated.


Would you mind posting a code listing of the relevant activities? There are a lot of lifecycle callbacks - onRestoreInstanceState() for example.


I managed to solve it by passing the intent through the onOptionsItemSelected() method. I still don't quite understand the actual difference in what happens when you press the device back button or the app home button though. My best guess so far is that using the back button retrieves the activity from the back stack and therefore it keeps all the variables the activity had saved at the time, while the home button simply creates a new activity of the parent activity.
"If yellow does start SC2, I should start handsomenerd diaper busniess and become a rich man" - John the Translator
meatpudding
Profile Joined March 2011
Australia520 Posts
February 04 2014 09:06 GMT
#8722
On February 02 2014 18:08 wozzot wrote:
Made a Mandelbrot fractal generator, but the issue is that it runs really slowly: it takes a whole minute to generate a single fractal. Would like to know whether the problem is because my program is inefficient or because of Perl / the GD library. tia

+ Show Spoiler +

#!perl
use strict;
use GD;

# Mandelbrot fractal generator

my ($width, $height) = (900, 675);
my ($x_min, $x_max) = (-2, 1);
my ($y_min, $y_max) = (-1, 1);
my ($x_min, $x_max) = (-2, .65);
my ($y_min, $y_max) = (-1, 1);
my ($y_min, $y_max) = (-1, 1);

my $multi = 1/1.1;
$_ /= $multi for ($x_min, $x_max, $y_min, $y_max);

my $x_range = $x_max - $x_min;
my $y_range = $y_max - $y_min;
my $x_offset = 0;
my $y_offset = 0;
my $it_count = 30;
my $bound = 1000;

my $filename = 'fractal.png';
open STDOUT, ">", "$filename";
binmode STDOUT;

my $bitmap = new GD::Image($width, $height, 0) or die "Could not initialize bitmap\n";

my %colors = (); # keys: "$r $g $b"
# Allocate colors like this:
# $colors{"$r $g $b"} = $bitmap->colorAllocate($r, $g, $b)
# unless exists($colors{"$r $g $b"});
#
# Set pixel like this:
# $bitmap->setPixel($pix_h, $pix_v, $colortable{"$a $b $c"});

my $black = $bitmap->colorAllocate(0, 0, 0); # Black background
my @color_inner = (128, 255, 0);
my @color_outer = (0, 0, 96);

sub color {
my ($it, $pix_h, $pix_v) = @_;
my $percent = $it/ $it_count;
$percent *= .8;
$percent = 1 if $percent > 1;

my $r = int($color_inner[0] * $percent + $color_outer[0] * (1 - $percent));
my $g = int($color_inner[1] * $percent + $color_outer[1] * (1 - $percent));
my $b = int($color_inner[2] * $percent + $color_outer[2] * (1 - $percent));

$colors{"$r $g $b"} = $bitmap->colorAllocate($r, $g, $b)
unless exists($colors{"$r $g $b"});

$bitmap->setPixel($pix_h, $pix_v, $colors{"$r $g $b"});
}

sub calc {
my ($r, $i, $it, $pix_h, $pix_v, @c) = @_;

# (a + bi) ** 2 = a ** 2 + 2abi - b ** 2
# z = z**2 + c

my $real = $r ** 2 - $i ** 2 + $c[0];
my $imag = 2 * $r * $i + $c[1];
color($it, $pix_h, $pix_v) if ($real > $bound);
return ($real, $imag);
}

for my $pix_h (0..$width-1) {
for my $pix_v (0..$height-1) {
my $r = ($pix_h + 1) / $width * $x_range + $x_min + $x_offset;
my $i = ($pix_v + 1) / $height * $y_range + $y_min + $y_offset;
my @c = ($r, $i);

for (1..$it_count) {
($r, $i) = calc($r, $i, $_, $pix_h, $pix_v, @c);
}
}
}

print $bitmap->png;


Can't say for sure, but colorAllocate and setPixel are usually bottlenecks in those kinds of situations. You may want to create an array of pixel data and 'set' that on the image all at once. (I don't know PERL)
Be excellent to each other.
Animzor
Profile Joined March 2011
Sweden2154 Posts
February 04 2014 18:07 GMT
#8723
Quick noob question about Java: I've created a method that iterates through an arraylist and changes certain values (StockValue) inside certain objects (Stock). Code below.

+ Show Spoiler +
for(Item thisItem : belongings){
if(thisItem instanceof Stock){
((Stock) thisItem).setStockValue(0);


the code works, but it changes the value StockValue for all objects of the Stock type, even objects that are created in the future. My question is, how do I set StockValue to zero but still have the ability to create new objects of Stock class with values other than zero?
ThatGuy
Profile Blog Joined April 2008
Canada695 Posts
February 04 2014 18:13 GMT
#8724
On February 05 2014 03:07 Animzor wrote:
Quick noob question about Java: I've created a method that iterates through an arraylist and changes certain values (StockValue) inside certain objects (Stock). Code below.

+ Show Spoiler +
for(Item thisItem : belongings){
if(thisItem instanceof Stock){
((Stock) thisItem).setStockValue(0);


the code works, but it changes the value StockValue for all objects of the Stock type, even objects that are created in the future. My question is, how do I set StockValue to zero but still have the ability to create new objects of Stock class with values other than zero?


This code should not (and could not) be affecting objects that have not been created yet. It's possible that you are calling this method more often than you would like, re-iterating over the list AFTER you've created more stocks and inserted them into the list.
ThatGuy
Profile Blog Joined April 2008
Canada695 Posts
February 04 2014 18:21 GMT
#8725
Of course, there could be a ton of other things happening here. Maybe you don't set the stock value on a newly created stock. Maybe you're using a copy constructor and another Stock with an empty Stock value. You'll either need to debug deeper or be more open with the question to actually isolate whether that block of code is indeed causing your issues.
Animzor
Profile Joined March 2011
Sweden2154 Posts
February 04 2014 18:40 GMT
#8726
On February 05 2014 03:21 ThatGuy wrote:
Of course, there could be a ton of other things happening here. Maybe you don't set the stock value on a newly created stock. Maybe you're using a copy constructor and another Stock with an empty Stock value. You'll either need to debug deeper or be more open with the question to actually isolate whether that block of code is indeed causing your issues.


Sorry, I didn't want to be an asshole and post too much code. Anyway, what I have is a Person class and a Stock class. Every Person includes an arraylist which can contain a bunch of items, like Stock. In the Stock class I have a method setStockValue that looks like this

+ Show Spoiler +
public void setStockValue(int price) {

this.price = price;
}


I assume that by changing the price in the Stock class, I am changing it permanently. But I can't think of another way to do it.
betaflame
Profile Joined November 2010
175 Posts
February 04 2014 18:40 GMT
#8727
On February 05 2014 03:07 Animzor wrote:
Quick noob question about Java: I've created a method that iterates through an arraylist and changes certain values (StockValue) inside certain objects (Stock). Code below.

+ Show Spoiler +
for(Item thisItem : belongings){
if(thisItem instanceof Stock){
((Stock) thisItem).setStockValue(0);


the code works, but it changes the value StockValue for all objects of the Stock type, even objects that are created in the future. My question is, how do I set StockValue to zero but still have the ability to create new objects of Stock class with values other than zero?

Maybe StockValue is static?
Blitzkrieg0
Profile Blog Joined August 2010
United States13132 Posts
Last Edited: 2014-02-04 20:22:26
February 04 2014 19:07 GMT
#8728
Are all of your stock values using the same reference memory? That is the only reason you should be able to overwrite all of them at the same time, and new ones pull this value since they're using that same reference.
I'll always be your shadow and veil your eyes from states of ain soph aur.
Pseudoku
Profile Joined March 2011
Canada1279 Posts
Last Edited: 2014-02-04 19:47:52
February 04 2014 19:40 GMT
#8729
How are you creating your Stock objects?
Logic fails because we are lazy.
Vorenius
Profile Blog Joined December 2010
Denmark1979 Posts
Last Edited: 2014-02-04 20:06:53
February 04 2014 20:03 GMT
#8730
On February 05 2014 03:40 Animzor wrote:
Show nested quote +
On February 05 2014 03:21 ThatGuy wrote:
Of course, there could be a ton of other things happening here. Maybe you don't set the stock value on a newly created stock. Maybe you're using a copy constructor and another Stock with an empty Stock value. You'll either need to debug deeper or be more open with the question to actually isolate whether that block of code is indeed causing your issues.


Sorry, I didn't want to be an asshole and post too much code. Anyway, what I have is a Person class and a Stock class. Every Person includes an arraylist which can contain a bunch of items, like Stock. In the Stock class I have a method setStockValue that looks like this

+ Show Spoiler +
public void setStockValue(int price) {

this.price = price;
}


I assume that by changing the price in the Stock class, I am changing it permanently. But I can't think of another way to do it.

A small tip unrelated to your question:
+ Show Spoiler +

If your function sets the price, then name it setPrice.
If the price is actually the stock value, then rename that variable to stockValue or something similar.

Having a function called setStockValue that doesn't modify anything called stockValue is quite confusing


As for your problem, feel free to post more of your code. Where are you creating your stocks? When are you running your for-loop?
Animzor
Profile Joined March 2011
Sweden2154 Posts
Last Edited: 2014-02-04 22:36:46
February 04 2014 22:35 GMT
#8731
On February 05 2014 05:03 Vorenius wrote:
Show nested quote +
On February 05 2014 03:40 Animzor wrote:
On February 05 2014 03:21 ThatGuy wrote:
Of course, there could be a ton of other things happening here. Maybe you don't set the stock value on a newly created stock. Maybe you're using a copy constructor and another Stock with an empty Stock value. You'll either need to debug deeper or be more open with the question to actually isolate whether that block of code is indeed causing your issues.


Sorry, I didn't want to be an asshole and post too much code. Anyway, what I have is a Person class and a Stock class. Every Person includes an arraylist which can contain a bunch of items, like Stock. In the Stock class I have a method setStockValue that looks like this

+ Show Spoiler +
public void setStockValue(int price) {

this.price = price;
}


I assume that by changing the price in the Stock class, I am changing it permanently. But I can't think of another way to do it.

A small tip unrelated to your question:
+ Show Spoiler +

If your function sets the price, then name it setPrice.
If the price is actually the stock value, then rename that variable to stockValue or something similar.

Having a function called setStockValue that doesn't modify anything called stockValue is quite confusing


As for your problem, feel free to post more of your code. Where are you creating your stocks? When are you running your for-loop?


Alright, here's some more code, it's very messy. Kind of embarrassing to post really. Thanks for the help guys.

create stock method:
+ Show Spoiler +
private void addStock() {

System.out.println("Enter name of stock entry: ");

String stockName = keyboard.nextLine();

System.out.println("Enter amount: ");

int stockAmount = keyboard.nextInt();

keyboard.nextLine();

System.out.println("Enter price: ");

int stockPrice = keyboard.nextInt();

keyboard.nextLine();

Stock newStock = new Stock(stockName, stockAmount, stockPrice);

System.out.println("Enter name of owner: ");

String owner = keyboard.nextLine();

for(Person personEntry : personList) {
if(personEntry.name.equals(owner)) {
personEntry.belongings.add(newStock);

}

}
}


Person class where for-loop is run
+ Show Spoiler +
import java.util.ArrayList;


public class Person{

public String name;
public String items;

public ArrayList<Item> belongings = new ArrayList<Item>();

public Person(String name){

this.name = name;
}

public String getName(){
return name;

}

public ArrayList<Item> getBelongings() {
return belongings;
}

public void setStockCrash() {


for(Item thisItem : belongings){
if(thisItem instanceof Stock){
((Stock) thisItem).setStockPrice(0);
}
}
}

public void addItem(Person owner, Item newItem){

owner.belongings.add(newItem);
}

public String toString() {
return "Name: " + name;
}
}


Stock class
+ Show Spoiler +

public class Stock extends Item {

protected int amount;
protected int price;

public Stock(String type, int amount, int price){
super(type);


this.amount = amount;
}


public int getAmount() {
return amount;
}

public int getStockValue() {
return amount * price ;

}

public int getPrice() {
return price ;

}


public void setStockPrice(int price) {

this.price = price;
}

public String toString(){
return "type: " + type + "amount: " + amount + "price: " + price;
}

}
wozzot
Profile Joined July 2012
United States1227 Posts
February 05 2014 00:33 GMT
#8732
I've been doing problems on HackerRank during the past couple of days and it is sheer hell. Made me realize how narrow my limitations are right now.

Seriously, the 1/x + 1/y = 1/N! problem is listed as Easy, can't figure out how to code it even after searching for the solution.
Also, I need to learn to use sorting algorithms other than insertion sort
(ノ´∀`*)ノ ♪ ♫ ヽ(´ー`)ノ ♪ ♫ (✌゚∀゚)☞ ♪ ♫ ヽ(´ー`)ノ ♫ ♫ (ノ´_ゝ`)ノ彡 ┻━┻
berated-
Profile Blog Joined February 2007
United States1134 Posts
February 05 2014 02:14 GMT
#8733
On February 05 2014 07:35 Animzor wrote:
Show nested quote +
On February 05 2014 05:03 Vorenius wrote:
On February 05 2014 03:40 Animzor wrote:
On February 05 2014 03:21 ThatGuy wrote:
Of course, there could be a ton of other things happening here. Maybe you don't set the stock value on a newly created stock. Maybe you're using a copy constructor and another Stock with an empty Stock value. You'll either need to debug deeper or be more open with the question to actually isolate whether that block of code is indeed causing your issues.


Sorry, I didn't want to be an asshole and post too much code. Anyway, what I have is a Person class and a Stock class. Every Person includes an arraylist which can contain a bunch of items, like Stock. In the Stock class I have a method setStockValue that looks like this

+ Show Spoiler +
public void setStockValue(int price) {

this.price = price;
}


I assume that by changing the price in the Stock class, I am changing it permanently. But I can't think of another way to do it.

A small tip unrelated to your question:
+ Show Spoiler +

If your function sets the price, then name it setPrice.
If the price is actually the stock value, then rename that variable to stockValue or something similar.

Having a function called setStockValue that doesn't modify anything called stockValue is quite confusing


As for your problem, feel free to post more of your code. Where are you creating your stocks? When are you running your for-loop?


Alright, here's some more code, it's very messy. Kind of embarrassing to post really. Thanks for the help guys.

create stock method:
+ Show Spoiler +
private void addStock() {

System.out.println("Enter name of stock entry: ");

String stockName = keyboard.nextLine();

System.out.println("Enter amount: ");

int stockAmount = keyboard.nextInt();

keyboard.nextLine();

System.out.println("Enter price: ");

int stockPrice = keyboard.nextInt();

keyboard.nextLine();

Stock newStock = new Stock(stockName, stockAmount, stockPrice);

System.out.println("Enter name of owner: ");

String owner = keyboard.nextLine();

for(Person personEntry : personList) {
if(personEntry.name.equals(owner)) {
personEntry.belongings.add(newStock);

}

}
}


Person class where for-loop is run
+ Show Spoiler +
import java.util.ArrayList;


public class Person{

public String name;
public String items;

public ArrayList<Item> belongings = new ArrayList<Item>();

public Person(String name){

this.name = name;
}

public String getName(){
return name;

}

public ArrayList<Item> getBelongings() {
return belongings;
}

public void setStockCrash() {


for(Item thisItem : belongings){
if(thisItem instanceof Stock){
((Stock) thisItem).setStockPrice(0);
}
}
}

public void addItem(Person owner, Item newItem){

owner.belongings.add(newItem);
}

public String toString() {
return "Name: " + name;
}
}


Stock class
+ Show Spoiler +

public class Stock extends Item {

protected int amount;
protected int price;

public Stock(String type, int amount, int price){
super(type);


this.amount = amount;
}


public int getAmount() {
return amount;
}

public int getStockValue() {
return amount * price ;

}

public int getPrice() {
return price ;

}


public void setStockPrice(int price) {

this.price = price;
}

public String toString(){
return "type: " + type + "amount: " + amount + "price: " + price;
}

}


The default value of int is 0, it isn't overriding it, it's never getting set. Check your constructor in Stock.
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
Last Edited: 2014-02-05 02:37:33
February 05 2014 02:37 GMT
#8734
On Ubuntu one of the recent updates apparently messed up gcc(or I may have messed it up when I was trying to get an old version of gcc for something that required it). I am trying to compile and link together a skeleton assembly file. I can compile all the files with gcc no problem. However, when I go to link them together into an executable it complains that it "Cannot find crt1.o". Looking online suggests that this was moved in a recent update, and gcc doesn't know where it is.

The 2 suggestions I saw were this workaround which doesn't work for me and this one which I don't trust.

So I would like some advice on how to handle this. So far I have tried the first workaround, and have also tried reinstalling gcc(which states all 11 were unchanged) using the command sudo apt-get install gcc. If anyone can give me advice on what else would be worth trying I would appreciate it. Alternatively, I may move to using g++ in order to compile/link the files, but this is partly for an assignment due in a week so I'd rather not have to do that. Thank you for reading.
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
sluggaslamoo
Profile Blog Joined November 2009
Australia4494 Posts
Last Edited: 2014-02-05 05:26:39
February 05 2014 05:14 GMT
#8735
On February 05 2014 05:03 Vorenius wrote:
Show nested quote +
On February 05 2014 03:40 Animzor wrote:
On February 05 2014 03:21 ThatGuy wrote:
Of course, there could be a ton of other things happening here. Maybe you don't set the stock value on a newly created stock. Maybe you're using a copy constructor and another Stock with an empty Stock value. You'll either need to debug deeper or be more open with the question to actually isolate whether that block of code is indeed causing your issues.


Sorry, I didn't want to be an asshole and post too much code. Anyway, what I have is a Person class and a Stock class. Every Person includes an arraylist which can contain a bunch of items, like Stock. In the Stock class I have a method setStockValue that looks like this

+ Show Spoiler +
public void setStockValue(int price) {

this.price = price;
}


I assume that by changing the price in the Stock class, I am changing it permanently. But I can't think of another way to do it.

A small tip unrelated to your question:
+ Show Spoiler +

If your function sets the price, then name it setPrice.
If the price is actually the stock value, then rename that variable to stockValue or something similar.

Having a function called setStockValue that doesn't modify anything called stockValue is quite confusing


As for your problem, feel free to post more of your code. Where are you creating your stocks? When are you running your for-loop?


I disagree. Programs should model the Business Rules, in this case it is more correct this way.

In the future the prices may change but the stock values may be slightly different (or vice-versa), but in the end we want the list of stock prices not values (or vice-versa). However stock price may mostly rely on the value given, so the stock price right now would be the value of the stock, but maybe not later.

From a maintenance and design perspective the way he has done it is actually better. Although there still could be some improvement, so it is not as side-effect prone.

Be careful not to carpet bomb your's and other's code with conventions purely for the sake of convention. Every convention has a context, be aware of the context, in many contexts you would be correct, but not in this one. I see it all the time in this thread.

When you model the business rules with your logic, the code is much easier to maintain, than faux clean code because you followed all the conventions. The latter will cause all sorts of headaches for you when your client decides he wants some "simple changes". When your code aligns with the business rules, the clients suggestions become much simpler to understand and implement.
Come play Android Netrunner - http://www.teamliquid.net/forum/viewmessage.php?topic_id=409008
Animzor
Profile Joined March 2011
Sweden2154 Posts
February 05 2014 06:49 GMT
#8736
On February 05 2014 11:14 berated- wrote:
Show nested quote +
On February 05 2014 07:35 Animzor wrote:
On February 05 2014 05:03 Vorenius wrote:
On February 05 2014 03:40 Animzor wrote:
On February 05 2014 03:21 ThatGuy wrote:
Of course, there could be a ton of other things happening here. Maybe you don't set the stock value on a newly created stock. Maybe you're using a copy constructor and another Stock with an empty Stock value. You'll either need to debug deeper or be more open with the question to actually isolate whether that block of code is indeed causing your issues.


Sorry, I didn't want to be an asshole and post too much code. Anyway, what I have is a Person class and a Stock class. Every Person includes an arraylist which can contain a bunch of items, like Stock. In the Stock class I have a method setStockValue that looks like this

+ Show Spoiler +
public void setStockValue(int price) {

this.price = price;
}


I assume that by changing the price in the Stock class, I am changing it permanently. But I can't think of another way to do it.

A small tip unrelated to your question:
+ Show Spoiler +

If your function sets the price, then name it setPrice.
If the price is actually the stock value, then rename that variable to stockValue or something similar.

Having a function called setStockValue that doesn't modify anything called stockValue is quite confusing


As for your problem, feel free to post more of your code. Where are you creating your stocks? When are you running your for-loop?


Alright, here's some more code, it's very messy. Kind of embarrassing to post really. Thanks for the help guys.

create stock method:
+ Show Spoiler +
private void addStock() {

System.out.println("Enter name of stock entry: ");

String stockName = keyboard.nextLine();

System.out.println("Enter amount: ");

int stockAmount = keyboard.nextInt();

keyboard.nextLine();

System.out.println("Enter price: ");

int stockPrice = keyboard.nextInt();

keyboard.nextLine();

Stock newStock = new Stock(stockName, stockAmount, stockPrice);

System.out.println("Enter name of owner: ");

String owner = keyboard.nextLine();

for(Person personEntry : personList) {
if(personEntry.name.equals(owner)) {
personEntry.belongings.add(newStock);

}

}
}


Person class where for-loop is run
+ Show Spoiler +
import java.util.ArrayList;


public class Person{

public String name;
public String items;

public ArrayList<Item> belongings = new ArrayList<Item>();

public Person(String name){

this.name = name;
}

public String getName(){
return name;

}

public ArrayList<Item> getBelongings() {
return belongings;
}

public void setStockCrash() {


for(Item thisItem : belongings){
if(thisItem instanceof Stock){
((Stock) thisItem).setStockPrice(0);
}
}
}

public void addItem(Person owner, Item newItem){

owner.belongings.add(newItem);
}

public String toString() {
return "Name: " + name;
}
}


Stock class
+ Show Spoiler +

public class Stock extends Item {

protected int amount;
protected int price;

public Stock(String type, int amount, int price){
super(type);


this.amount = amount;
}


public int getAmount() {
return amount;
}

public int getStockValue() {
return amount * price ;

}

public int getPrice() {
return price ;

}


public void setStockPrice(int price) {

this.price = price;
}

public String toString(){
return "type: " + type + "amount: " + amount + "price: " + price;
}

}


The default value of int is 0, it isn't overriding it, it's never getting set. Check your constructor in Stock.


That's... very odd, not sure how that happened. Thanks.
icystorage
Profile Blog Joined November 2008
Jollibee19350 Posts
February 05 2014 07:14 GMT
#8737
in the future, what do you guys think of a stay-home programmer dad? like just do freelance or similar-work in the house?
LiquidDota StaffAre you ready for a Miracle-? We are! The International 2017 Champions!
nunez
Profile Blog Joined February 2011
Norway4003 Posts
February 05 2014 08:27 GMT
#8738
On February 05 2014 16:14 icystorage wrote:
in the future, what do you guys think of a stay-home programmer dad? like just do freelance or similar-work in the house?

almost as cool as stay-home progamer dad.
conspired against by a confederacy of dunces.
WolfintheSheep
Profile Joined June 2011
Canada14127 Posts
February 05 2014 09:02 GMT
#8739
On February 05 2014 16:14 icystorage wrote:
in the future, what do you guys think of a stay-home programmer dad? like just do freelance or similar-work in the house?

Far more viable for positions like Web Designers or UI Designers, where you create something to a client's liking and then hand it over 100%.

The more you become involved in software or other back-end development, the more your role involves maintenance and upkeep, which inevitably leads to demand for physical presence.

Like all careers, though, anything's possible if there's a demand, and if you sell yourself properly.
Average means I'm better than half of you.
icystorage
Profile Blog Joined November 2008
Jollibee19350 Posts
February 05 2014 09:10 GMT
#8740
well i have a friend (single) who is currently working at home and is like being out-sourced. he just collaborates with the other programmers (i dont know if all of them are out-sourced). but i find it very hard to work with especially if you have time constraints.
LiquidDota StaffAre you ready for a Miracle-? We are! The International 2017 Champions!
Prev 1 435 436 437 438 439 1032 Next
Please log in or register to reply.
Live Events Refresh
Epic.LAN
22:00
Epic.LAN 49 Group Stage
Liquipedia
GSL
21:00
GSL CK 6
IntoTheiNu 886
SHIN 136
Maru 88
CranKy Ducklings SOOP72
Zoun (SOOP) 54
herO (SOOP) 48
Solar (SOOP)38
Rogue 31
ByuN (SOOP) 29
Rex21
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Lowko481
SHIN 136
Maru 88
Zoun (SOOP) 54
herO (SOOP) 48
Solar (SOOP) 38
Rogue 31
ByuN (SOOP) 29
Rex 21
StarCraft: Brood War
Jaedong 1468
Light 1134
Horang2 1014
EffOrt 970
BeSt 399
FanTaSy 383
Soma 343
Snow 317
ggaemo 244
actioN 240
[ Show more ]
ZerO 175
Rush 147
Hyuk 145
White-Ra 137
Mind 114
Barracks 111
Hyun 85
hero 69
sSak 55
Yoon 52
Mong 50
Classic 48
Sea.KH 44
Shinee 35
ToSsGirL 32
910 26
Trap 26
HiyA 23
Sharp 22
soO 19
Terrorterran 18
JYJ 17
Rock 11
Bishop 11
Noble 3
Dota 2
Gorgc21775
qojqva1395
syndereN347
Fuzer 178
LuMiX0
League of Legends
Trikslyr39
Heroes of the Storm
crisheroes384
Other Games
singsing1593
Liquid`RaSZi1034
hiko1002
Mlord655
DeMusliM345
Hui .176
ArmadaUGS149
Liquid`VortiX149
KnowMe127
XaKoH 94
QueenE44
ZerO(Twitch)15
Organizations
Counter-Strike
PGL25255
StarCraft: Brood War
lovetv 8
[ Show 15 non-featured ]
StarCraft 2
• poizon28 65
• StrangeGG 55
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• Migwel
StarCraft: Brood War
• HerbMon 30
• FirePhoenix7
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Nemesis1967
• TFBlade518
Other Games
• Shiphtur345
Upcoming Events
Big Brain Bouts
59m
OSC
5h 59m
Replay Cast
6h 59m
Sparkling Tuna Cup
17h 59m
WardiTV Invitational
19h 59m
Epic.LAN
20h 59m
IPSL
23h 59m
eOnzErG vs McRibbed
LancerX vs StRyKeR
AI Arena Tournament
1d 1h
OSC
1d 21h
Yamato Cup
1d 22h
[ Show More ]
IPSL
2 days
Artosis vs RiceHat
Kyrie vs Sony
Map Test Tournament
2 days
WardiTV Weekly
2 days
Ultimate Battle
2 days
Rush vs BeSt
Replay Cast
3 days
Rogue vs Classic
Patches Events
3 days
PiGosaur Cup
4 days
Kung Fu Cup
4 days
The PondCast
5 days
KCM Race Survival
5 days
Liquipedia Results

Completed

Proleague 2026-10-28
Blizzard Classic Cup 2026
HCC Season 3

Ongoing

Acropolis #5
KCM Race Survival 2026 Season 4
International ShieldBattery League
BSL Season 23
PGL Masters Bucharest 2026
Stake Ranked Episode 5
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
FISSURE Playground #3
BLAST Open Fall 2026
Esports World Cup 2026

Upcoming

IPSL Winter 2026-27
1xBet Invitational
SC4ALL II: Brood War
BSL 23: Non-Korean Championship
HSC XXX
Stellar Fest 2: Lunar Cup
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
RSL Offline Finals
eXTREMESLAND 2026
PGL Major Singapore 2026
Stake Ranked Episode 6
BLAST Rivals Fall 2026
IEM Beijing 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.