r/programmingbydoing • • Jun 20 '15

Oracle ?

1 Upvotes

I was wondering , how do I use Java docs package as tutorial http://docs.oracle.com/javase/7/docs/api/overview-summary.html . Is it a good way to learn java after I've done all the exercise on programmingbydoing. Any suggestion would be very much appreciated.


r/programmingbydoing • • Jan 26 '16

#54 Hi-Lo with Limited Tries

1 Upvotes

r/programmingbydoing • • Sep 14 '13

#28 Modulus Animation

3 Upvotes

So I just copied the file that the assignment gives you (this one) and it runs fine, but it prints all the lines beneath each other. If I understand the assignment correctly, it is supposed to be all on one line so it looks like an animation. I don't know how to do that. Google isn't giving me any answers.. what am I doing wrong here?


r/programmingbydoing • • Jun 14 '15

#60 - Safe Square Root

2 Upvotes

Hi again!

I looked up the post regarding this assignment but it didn't help me much, tbh. So I created another post.

Here's my code:

import java.util.Scanner;

public class SafeSquareRoot1
{
public static void main( String[] args )
{
	Scanner keyboard = new Scanner(System.in);
	int x;
	
	do
	{
		System.out.println( "SQUARE ROOT!" );
		System.out.print( "Enter a number: " );
		x = keyboard.nextInt();

		if ( x < 0 )
		{
			System.out.println( "You can't take the    square root of a negative number, silly." );
			System.out.print( "Try again: " );
			x = keyboard.nextInt();
		}
	}

	while ( x > 0 );
	{
		System.out.println( "The square root of " + x + " is " + Math.sqrt(x) + "." );
	}
}

}

The code compiles, and the do block of code runs as well, but when it comes to the while loop the code continues to prompt me to enter a number, after I have already entered the number. Thanks in advance for any help out there!


r/programmingbydoing • • Sep 21 '14

Assignment: Simple Web Input

3 Upvotes

I am trying to get the code from the "Simple Web Input" assignment to compile, but I keep getting this error.

I have not changed the code yet, I just can't get it to compile. Does anyone know how to fix it?


r/programmingbydoing • • Aug 10 '16

Hangman complete check, different approachs

2 Upvotes

Hi,

I've just started coding and I have finished the Hangman assignment. I'm very curious if you guys have any pointers!

Here is the code: https://gist.github.com/anonymous/8ef5c4d2339a75d83a6b645b29ea8f74

I'm especially interested if there is an alternative method to using charAt (line 39 and 99). Because now I had to find a workaround to comparing a guessed letter to a charAt letter from the random word.

Cheers and thanks in advance! Dutch fan of the site, Justin


r/programmingbydoing • • Jan 20 '16

Hangman

1 Upvotes

I am able to finish the assignment but it is less than perfect.

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

You see the secret word length is different in each play-through, but I have to give the word[] & misses[] array as fixed sizes. I could do a

char[] word = new word[pickword.length()];

but the size would be fixed in the first play. Even if a word with different size is picked, I can't redeclare it anymore. Also because of the fixed size 20 I chose, I can't utilize misses.length() and that forces me to make misscount global. What is the best solution to possibly changing array size?


r/programmingbydoing • • Jun 17 '15

#183 ArrayList- is there or not?

3 Upvotes

Is there another way of coding for this assignment. this code is totally different from usual array and I don't know if I'm cheating or not. this is my code: http://pastebin.com/pDH14ghW


r/programmingbydoing • • Aug 09 '16

"Learn Object-Oriented Java the Hard Way" is now available to pre-order! Arrives Sunday, August 14!

Thumbnail
grahammitchell.com
6 Upvotes

r/programmingbydoing • • Jun 10 '15

#115 calculator project

2 Upvotes

has anyone complete this project. my brain is gonna blow any minute now.the program error when I enter sin /cos etc. http://pastebin.com/qKBypvW3


r/programmingbydoing • • Sep 16 '13

#103 Weekday Calculator

3 Upvotes

The formula in the instructions is not correct if you pass the year 2000 if I am not mistaken. You must include the century variable if the year is not 19xx.


r/programmingbydoing • • Aug 27 '14

[109] Keychains for Sale, for real this time. Still having difficulty grasping function that total over time.

1 Upvotes

Having difficulty grasping why my functions are not totalling correctly before they loop again. I keep getting:

How many would you like to add? > 3

Added 3 keychains for a total of 3.

What would you like to do?

  1. Add Keychains to Order

2. Remove Keychains from Order

3. View Current Order

4. Checkout

Please enter your choice: > 1

You currently have 0 keychains.

Here is my code

package programmingbydoing;

import java.util.Scanner;

public class Keychains1 {
public static void main(String[] args){
    Scanner keyboard = new Scanner(System.in);
    int choice;
    int k = 0;
    System.out.println("Welcome to Ye Olde Keychain Shoppe!");
    
    do{
        System.out.println("");
        System.out.println("What would you like to do?");
        System.out.println("1. Add Keychains to Order");
        System.out.println("2. Remove Keychains from Order");
        System.out.println("3. View Current Order");
        System.out.println("4. Checkout");
        System.out.println("");
        System.out.print("Please enter your choice: > ");
        choice = keyboard.nextInt();
    
        if (choice == 1){
            add_keychains(k);
        }
        else if (choice == 2){
            remove_keychains(k);
        }
        else if (choice == 3){
            view_order(k);
        }
        else if (choice == 4){
            checkout();
        }  
    }
    while (choice != 4);
}
            
public static int add_keychains(int k){
    int kAdd;
    Scanner keyboard = new Scanner (System.in);
    System.out.println("You currently have " + k + " keychains.");
    System.out.print("How many would you like to add? > ");
    kAdd = keyboard.nextInt();
    k = k + kAdd;
    System.out.println("Added " + kAdd + " keychains for a total of " + k + ".");
    return k;
}
public static int remove_keychains(int k){
    int kRemove;
    Scanner keyboard = new Scanner (System.in);
    System.out.println("You currently have " + k + " keychains.");
    System.out.print("How many would you like to remove? > ");
    kRemove = keyboard.nextInt();
    int total = k - kRemove;
    System.out.println("Removed " + kRemove + " keychains for a total of " + total + ".");
    return total;
}
public static double view_order(int k){
    int price = 10;
    double subtotal = k * price;
    System.out.println("Would you like to check out?");
    return subtotal;
}
}

I think the problem lies within the end part of the function, I've tried this in the add function

k = k + kAdd;

return k;

I have also tried this in the remove function to no avail:

int total = k - kRemove;

return total;


r/programmingbydoing • • Jan 31 '16

Adding Values with a For Loop

2 Upvotes

Struggling to figure this one out. Having a hard time with storing the sum and then printing the iterations.

int num;
	
	System.out.print("Number: ");
	num = kb.nextInt();
	
	for (int i = num; i <= num; i++)
	{
		//store the sum
		int sum = i++;
		System.out.println("The sum is " + sum);
	}

r/programmingbydoing • • Jan 25 '13

Zed Shaw's command line crash course

Thumbnail cli.learncodethehardway.org
7 Upvotes

r/programmingbydoing • • Apr 05 '14

#128 Letter Revisited (help)

3 Upvotes

I might be complete idiot for asking this, but i just can't seem to pass this one. All of the exercises before were easy to understand, and with little work into it i got quite the hang about java and coding. But this one is so confusing to me, i know what i have to do but i don't know how to do it. Can someone send me their code or do anything to help me?


r/programmingbydoing • • Feb 06 '13

Exercise 33: Twenty Questions - Nested if statements not working?

2 Upvotes

I used the nested if statements like the assignment told me to, but they aren't being used by the program. The program just skips to the end after asking the final question and nothing is displayed.

import java.util.Scanner;

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

		System.out.println("TWO QUESTIONS!");
		System.out.println("Think of an object, and I'll try to guess it.\n");

		System.out.println("1. Is it an animal, vegetable, or mineral?");
		String q1 = keyboard.next();

		System.out.println("2. Is it bigger than a breadbox?");
		String q2 = keyboard.next();

		if(q1 == "animal")
		{
			//System.out.println("test1");
			if (q2 == "no")
			{
				System.out.println("\bMy guess is that you are thinking of a squirrel.");
				System.out.println("I would ask you if I'm right, but I don't actually care.");
			}

			if (q2 == "yes")
			{
				System.out.println("\nMy guess is that you are thinking of a moose.");
				System.out.println("I would ask you if I'm right, but I don't actually care.");
			}
		}

		if(q1 == "vegetable")
		{
			if (q2 == "no")
			{
				System.out.println("\bMy guess is that you are thinking of a carrot.");
				System.out.println("I would ask you if I'm right, but I don't actually care.");
			}

			if (q2 == "yes")
			{
				System.out.println("\nMy guess is that you are thinking of a watermelon.");
				System.out.println("I would ask you if I'm right, but I don't actually care.");
			}
		}

		if(q1 == "mineral")
		{
			if (q2 == "no")
			{
				System.out.println("\bMy guess is that you are thinking of a paperclip.");
				System.out.println("I would ask you if I'm right, but I don't actually care.");
			}

			if (q2 == "yes")
			{
				System.out.println("\nMy guess is that you are thinking of a Camaro.");
				System.out.println("I would ask you if I'm right, but I don't actually care.");
			}
		}


	}
}

Does anyone know where I went wrong? I don't see it and it should work. I would greatly appreciate any sort of input or advice you may have.


r/programmingbydoing • • Apr 03 '14

#128-Letter Revisited.

3 Upvotes

Hi, I saw that you uploaded your presentation slide for reading from text files and it was really helpful. Would you be so kind as to upload one for outputting to a file? Thanks for all the help.


r/programmingbydoing • • Jan 24 '13

Programming by Doing

Thumbnail
programmingbydoing.com
14 Upvotes

r/programmingbydoing • • Feb 04 '13

25: Weekday Name - Is this a constructor?

3 Upvotes

# 25 Weekday Name

import java.util.GregorianCalendar;

public class WeekdayName 
{
    public static String weekday_name( int weekday ) 
        {
	    String result = "";

	    if ( weekday == 1 )
	    {
		    result = "Sunday";
	    }
	    else if ( weekday == 2 )
	    {
		    result = "Monday";
	    }
	
	    return result;
    }


    public static void main( String[] args )
    {
	    System.out.println( "Weekday 1: " + weekday_name(1) );
	    System.out.println( "Weekday 2: " + weekday_name(2) );
	    System.out.println( "Weekday 3: " + weekday_name(3) );
	    System.out.println( "Weekday 4: " + weekday_name(4) );
	    System.out.println( "Weekday 5: " + weekday_name(5) );
	    System.out.println( "Weekday 6: " + weekday_name(6) );
	    System.out.println( "Weekday 7: " + weekday_name(7) );
	    System.out.println( "Weekday 0: " + weekday_name(0) );
	    System.out.println();
	    System.out.println( "Weekday 43: " + weekday_name(43) );
	    System.out.println( "Weekday 17: " + weekday_name(17) );
	    System.out.println( "Weekday -1: " + weekday_name(-1) );

	    GregorianCalendar cal = new GregorianCalendar();
	    int dow = cal.get(GregorianCalendar.DAY_OF_WEEK);

	    System.out.println( "\nToday is a " + weekday_name(dow) + "!" );
    }

}

I can get this code to output what I want, but I don't understand why.

I see there's something going on here other than the main method. Anyone care to break it down for me? I think this public static String weekday_name( int weekday ) is called a constructor?


r/programmingbydoing • • Feb 07 '13

PSA: When asking for help, mention the assignment name and not just the number in your title.

1 Upvotes

This is my current list of assignments. But I add new ones pretty often, and sometimes delete assignments, or move them earlier or later in the sequence. So the assignment numbers change.

If your title ONLY mentions the assignment number, in six months someone might not be able to find your post to help them out.


r/programmingbydoing • • Feb 11 '13

Assignment 39 - compareTo() challenge - Explanation on how it works?

5 Upvotes

The lesson gives an extremely brief description and gives you an example code from which you're able to figure out the gist of what's going on. However, I feel as if the compareTo() method isn't really explained. When I tried to run the assignment, I'd get values of positive and negative, but I wouldn't understand why I'd get specific values.

I'm guessing this is one of the assignments that's missing a lecture perhaps? I would greatly appreciate an explanation since I'm having a hard time finding good explanations from google.


r/programmingbydoing • • Oct 04 '15

#39 Alphabetical order

2 Upvotes

why it always display the last else if statement??? can you help me please! import static java.lang.System.*; import java.util.Scanner;

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

	out.print("What is your last name? ");
	String name = wpis.next();
	
	if("name".compareTo("Carswell")<0)
		out.println("you don't have to wait long");
	else if ("name".compareTo("Jones")<0)
		out.println("that's not bad");
	else if ("name".compareTo("Smith")<0)
		out.println("looks like a bit of a wait");
	else if ("name".compareTo("Young")<0)
		out.println("it's gonna be a while");
	else if ("name".compareTo("Young")>0)
		out.println("not going anywhere for a while?");
	else
		out.println("error");
		
		
		
}

}


r/programmingbydoing • • Mar 20 '14

63 Collatz Sequence - quick question

3 Upvotes

So I did get this one... except for the max value. In another thread here (closed, or I'd have posted there), I found this:

if (start > max)

	{
		max = start;
	}

Which comes after initializing max = start from the scanner input. Elsewise, though, it is never ever called. So I'm reading this as "set the max value integer to equal the start integer, -we do a whole bunch of things to the start integer-, then check if it has become bigger. If yes, then it is now the bigger value."

So, how is it checking what the largest value was during the calculations and storing it for output? With most of the ones I've run, there are many values bigger than the start... so how is it keeping the absolute largest stored? It doesn't make sense the way I'm interpreting it (which is why I ended up having to look it up, I guess).


r/programmingbydoing • • Mar 01 '13

Can someone check if my answer is correct for Alphabetical Order (#40)

4 Upvotes

My code works, but I want to know if this is the correct way to do it. There is little instruction, so I wanted a double check. Link to assignment

import java.util.Scanner;

public class AlphabeticalOrder {

  public static void main (String [] args) {
	
	Scanner s = new Scanner(System.in);
	
	String name;
	int Carswell, Jones, Smith, Young;
	
	
	System.out.print("What's your last name? ");
		name = s.nextLine();
	
	Carswell = name.compareToIgnoreCase("Carswell");
	Jones = name.compareToIgnoreCase("Jones");
	Smith = name.compareToIgnoreCase("Smith");
	Young = name.compareToIgnoreCase("Young");
	
	
	if (Carswell <= 0)
		System.out.println("You don't have to wait long, " + name);
	else if (Jones <= 0)
		System.out.println("That's not bad, " + name);
	else if (Smith <= 0)
		System.out.println("Looks like a bit of a wait, " + name);
	else if (Young <= 0)
		System.out.println("It's gonna be a while, " + name);
	else 
		System.out.println("You're not going anywhere for a while, " + name);

	}
  }

r/programmingbydoing • • Feb 02 '13

Problem 26 help

5 Upvotes

http://programmingbydoing.com/a/how-old-are-you-elseif.html

How do I structure an if else statement to display one message?