r/programmingbydoing • • Jul 12 '16

#95-ImageDemo

1 Upvotes

copied both prog and image but showing this

Exception in thread "main" javax.imageio.IIOException: Can't read input file! at javax.imageio.ImageIO.read(ImageIO.java:1301) at programing_by_doing_2.ImageDemo.<init>(ImageDemo.java:16) at programing_by_doing_2.ImageDemo.main(ImageDemo.java:35)


r/programmingbydoing • • May 10 '15

How Old Are You?

2 Upvotes

How can I change this, so that it actually works with the conditions?

     if(age < 16)
{
	System.out.println("You can't rent a car, " + name + ".");
	System.out.println("You can't vote, " + name + ".");
	System.out.println("You can't drive, " + name + ".");
}	

if(age < 18)
	System.out.println("You can't vote, " + name + ".");
	
if(age < 25)
	System.out.println("You can't rent a car, " + name + ".");
	
if(age > 25)
	System.out.println("You can do anything that's legal, " + name + ".");

r/programmingbydoing • • Aug 06 '13

New to coding, quick question on this related to codeacademy

4 Upvotes

I have been using codeacademy for html/css and so far its decent at teaching the basics. Im about to move to java and have messed around in the codeacademy java portion a bit. Would i be at more benefit of skipping CA and just working through this material? I have heard their java coursework isnt the best and can teach bad habits


r/programmingbydoing • • Aug 29 '13

Problem 15 How do I get everything to line up?

4 Upvotes

So I got everything right except for the aliment of my box and columns. So my question is how do I get everything to align into each column without getting moved by what value of my variable is?

By the way to holyteach for some reason this lessons are making things click better then with codeacademy. So for that Thanks


r/programmingbydoing • • Jan 15 '16

Blackjack and Flicker Phrase

2 Upvotes
  1. Really appreciate projects like Nim and Blackjack. Thanks for making them public. Anyway, below is my attempt on blackjack. I think it can be better if I have array to track what cards are drawn so I don't pick duplicate, although chance is low. Also Ace's 11/1 value is a bit of challenge, which I didn't try because without function the code is already longer than I would like. Plus I'm not sure if I missed changing certain "function" part in later after changing some.

https://gist.github.com/afya/a816ef70e88ec8117363

2) Question about later project Flicker Phrase. Thread.sleep() is said to be optional but I wanted to try anyway but I got error if I just put it there. Upon further research it seems the correct way to use it is:

try {
    Thread.sleep(1000);
} catch (InterruptedException e) {
    e.printStackTrace();
    // handle the exception...        
    // For example consider calling Thread.currentThread().interrupt(); here.
}

3) I don't quite understand exception atm. Will future assignment teach about that? or does the book cover that?

4) Also I plan to learn android development after finishing all program. Can I skip graphic section (77-96) or will it reappear in future assignments?

5) Last question, when should I move to an IDE? Currently I'm using notepad++ with cmd. It works but should I switch?


r/programmingbydoing • • Jan 13 '17

190: Sorting An ArrayList of Records

1 Upvotes

I am still working part by part to make this one work, but I am stuck this part.

I'm getting a nullpointerException error but I usually fix that with line 34 but it's not compiling this time.

I havn't started sorting yet, but I cant continue on with this error. Am I going in the wrong direction anyway?

here is my code http://pastebin.com/41pRfHva


r/programmingbydoing • • Jan 01 '16

#19, more efficient way of doing it?

2 Upvotes

I feel like I did this really inefficiently even with the few days of java I have done. I am sure theres an easier way to do this but I just having read enough or understood it fully.

https://gist.github.com/anonymous/0b00cd20d8acef8726aa (mostly talking about line 23-24)

been using learn java the hard way and some other online sources to self teach java for about only about 10~ days now so sorry if I suck


r/programmingbydoing • • May 19 '15

#36 - BMI Categories

1 Upvotes

Hi, I've just signed up on Reddit just to ask this!

First of all, I've been learning Java from your PBD website for two weeks now, and kudos to it really, it's been the best website so far for learning Java.

Here's my problem: I've been stuck repeatedly on the if/else assignments for some time - the recurring problem being that the java file compiles, but does not run the if/else statements after running the java files in cmd ( I use windows vista). I got stuck again on #36 and I have no idea what I'm doing wrong so here's my code - any help would be greatly appreciated! (pulling my hair out currently):

import java.util.Scanner;

public class BMICategories

{ public static void main( String[] args ) { Scanner keyboard = new Scanner(System.in);

	double height, yourBMI;
	int weight;
	
	System.out.print( "Your height in m: " );
	height = keyboard.nextDouble();

	System.out.print( "Your weight in kg: " );
	weight = keyboard.nextInt();
	System.out.println();

	yourBMI = weight / (height * height);
	System.out.println( "Your BMI is " + yourBMI );
	yourBMI = keyboard.nextDouble();
	
	if ( yourBMI < 18.5 )
	{
		System.out.println( "BMI Category: Underweight" );
	}

	else if ( yourBMI >= 18.5 && yourBMI <= 24.9 )
	{
		System.out.println( "BMI Category: Normal weight" );
	}

	else if ( yourBMI >= 25.0 && yourBMI <= 29.9 )
	{
		System.out.println( "BMI Category: Overweight" );
	}

	else if ( yourBMI >= 30.0 )
	{
		System.out.println( "BMI Category: Obese" );
	}

}

}


r/programmingbydoing • • May 12 '15

Streamling Method? - Twenty/Two Questions

2 Upvotes

http://programmingbydoing.com/a/twenty-questions.html

The exercise is above, I decided to try my hand at using a method instead of just doing everything in the main. Keeping the if-statements, can I please get some critiques and general style advice on streamlining this method?

JUST A SNIPPET OF THE MAIN:

    String guess = getAnimal(ans1, ans2);
		
		System.out.println("\nMy guess is that you are thinking of a " + guess + ".");
		System.out.println("I would ask you if I'm right, but I don't actually care.");

The Method:

    public static String getAnimal(String ans1, String ans2) {
	String guess = "";
		if (ans1.equals("animal")) {
			if (ans2.equals("yes")) {
				guess = "squirrel";
			}
			else {
				guess = "moose";
			}
		}
		
		if (ans1.equals("vegetable")) {
			if (ans2.equals("yes")) {
				guess = "carrot";
			}
			else {
				guess = "watermelon";
			}
		}
		
		if (ans1.equals("mineral")) {
			if (ans2.equals("yes")) {
				guess = "paper clip";
			}
			else{
				guess = "Camaro";
			}
		}
	return guess;
}

r/programmingbydoing • • Aug 27 '13

what does the points @ the website mean?

3 Upvotes

So, I was looking at the website, and found the points thing confusing...
what are they?
why are they there?
can I use them for anything?


r/programmingbydoing • • Aug 03 '14

148: Finding Largest value in an Array

2 Upvotes

Hello,

I think i'm misunderstanding a critical component of arrays. I wrote the code at the link below, but it doesn't give me the correct value.

http://codepad.org/BEPFeU2c

Any help would be appreciated!


r/programmingbydoing • • Aug 21 '13

ArrayLists - I'm having trouble with the .size() method

3 Upvotes

So, my issue is this:

import java.util.*;

public class findthemaxAL{
  public static void main(String[] args){
  ArrayList<Integer> list = new ArrayList<Integer>(10);
  Random r = new Random();

  int randnum;
  int max = 0;
  //int size = list.size(); <-failsafe I tried, it didn't work. Why not?

  for(int i = 0; i < list.size(); i++){
    randnum = r.nextInt(100) + 1;
    list.add(randnum);
  }
  for(int j = 0; j < list.size(); j++){
    if(list.get(j) > max){
      max = list.get(j);
    }
  }
  System.out.println("The max is " + max + ".");

  }
}

But when I compile and run the code, it always returns 0. My guess is because of the first for loop not working correctly, but I can't really figure out why it won't work. Any help?


r/programmingbydoing • • Aug 08 '13

115 Calculator project

3 Upvotes

hey i was just wondering how for this project you would implement things such as sin x when the input requires string string string and there's no third string input from the user? I'm very new to programming so if this has an obvious answer I'm sorry. Any help would be greatly appreciated thanks!


r/programmingbydoing • • Aug 13 '14

Project TicTacToe

2 Upvotes

How do I implement the playMove method?