Fires of Heaven Guild Message Board  

Go Back   Fires of Heaven Guild Message Board > General forums > Development
User Name
Password
Or, use your gamerDNA username: (more...)
ForumSpy Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 10-27-2007, 08:14 AM   #76 (permalink)
Fog
Registered User
 
Join Date: Feb 2006
Posts: 1,657
+5 Internets
Quote:
Originally Posted by Zippygoose View Post
This is an excellent point. I can remember sitting in a Freshman year OO concepts class and thinking-"Man this polymorphism shit is totally useless!"

I think the difficulty lies in the fact that an application a beginner would write is almost always in and of itself simplistic-and the entire basis of OO programming is the ability to take a large and complex problem and organize it into managable and reusable code. I mean how many times were you writing out prototypes for your "hello world" program and cursing the prof for all of this pesky "busy work"? That was me every day.
I strongly agree and that is exactly what I meant to say.
Fog is offline   Reply With Quote
Old 10-29-2007, 03:47 PM   #77 (permalink)
Kuriin
Registered User
 
Kuriin's Avatar
 
Join Date: Aug 2006
Location: Raleigh, NC
Posts: 2,173
Help...I'm stuck /because/ of my computeMax method. It's not generating the max of converges.

/*
* Created: *** put the date here ***
*
* Author: *** put your name here ***
*
* Program to compute Hailstone series.
*/

import java.util.Scanner;

public class Lab5
{
public static void main(String[] args)
{
Scanner in = new Scanner (System.in);
int length, start, max;
System.out.print("Would you like to compute a hailstorm series?");
String compute = in.nextLine();
if(compute.charAt(0) != 'Y' || compute.charAt(0) != 'y')
{
while((compute.charAt(0) == 'y' || compute.charAt(0) == 'Y'))
{

start = getStartingValue(in);
length = computeLength(start);
max = computeMax(start);
outputResults(start, length, max);
in.nextLine();
System.out.println();
System.out.println("Would you like to compute another hailstorm series?");
compute = in.nextLine();
}
}
System.out.println("Goodbye.");
System.exit(0);
}


// Given a Scanner in, this method (repeatedly, if necessary)
// prompts the user to enter a positive integer, inputs the
// integer, and if it is positive returns it. Otherwise, is
// keeps asking the user for a positve integer.
private static int getStartingValue(Scanner in)
{
System.out.print("Enter a positive integer.");
int x = in.nextInt();
if(x <= 0)
{
System.out.print("Enter a positive integer.");
x = in.nextInt();
}
return x;
}

// Do not declare the Scanner variable in this method.
// You must use the value this method receives in the
// argument (in).


// Given a positive starting value x, this method generates the
// corresponding Hailstone series and returns the length of the
// series (i.e., how many steps it takes before the series hits 1).
private static int computeLength(int x)
{
int length = 1;
if (x == 1)
{
length++;
}
else
{
while(x > 1)
{
if(x%2 == 0)
{
x = x/2;
length++;
}
else
{
x = (3 * x) + 1;
length++;
}
}
}
return length;
}

// Given a positive starting value x, this method generates the
// corresponding Hailstone series and returns the maximum value
// in the series (i.e., the largest value it generates before
// the series hits 1).
private static int computeMax(int x)
{
int length = 1;
int between;
between = x;
if(x == 1)
{
length = x;
}
else
{
while(x > 1)
{
if(x%2 == 0){
x = x/2;
length++;
}
else
{

x = (3 * x) + 1;
length++;
if(between > x)
{
between = x;
}
}
}
}
return between;
}


// Given the starting value, the length, and the max value in a
// Hailstone series, this method outputs them with appropriate
// messages.
private static void outputResults(int start, int length, int max)
{
System.out.println("The generated series for starting value " + start);
System.out.println("Series converged in " + length + " steps.");
System.out.println("Largest value generated is " + max);

}
}
Kuriin is offline   Reply With Quote
Old 10-29-2007, 03:55 PM   #78 (permalink)
Kuriin
Registered User
 
Kuriin's Avatar
 
Join Date: Aug 2006
Location: Raleigh, NC
Posts: 2,173
Nevermind. Found it. Incorrect boolean sign.
Kuriin is offline   Reply With Quote
Old 11-05-2007, 02:08 AM   #79 (permalink)
slitz
euro scum
 
slitz's Avatar
 
Join Date: Aug 2002
Location: Sweden
Posts: 819
-9 Internets
btw! much easier to read if you use the code tags [ code ] and end with [ / code ] without the whitespace.
slitz is offline   Reply With Quote
Old 11-05-2007, 07:10 AM   #80 (permalink)
Kuriin
Registered User
 
Kuriin's Avatar
 
Join Date: Aug 2006
Location: Raleigh, NC
Posts: 2,173
Quote:
Originally Posted by slitz View Post
btw! much easier to read if you use the code tags [ code ] and end with [ / code ] without the whitespace.
Oh okay. Sorry about that. Didn't realize there were tags for code.
Kuriin is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On
uberguilds network



All times are GMT -7. The time now is 01:18 AM.


Powered by vBulletin® Version 3.6.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.0.0 RC6