User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » java n00b question Page [1]  
Novicane
All American
15411 Posts
user info
edit post

say I want to create a class Bitch

and in Bitch I want it to perform a mathmetical operation (whore = 10 x 50 ^ 5) and return a simple double value

how can I call that value of whore from the class bitch to use in my public static void main?

(As in, take the value of whore and add 50 to it in the public main)
( or just display whore in a JPoptionpane.)

[Edited on October 19, 2005 at 10:17 PM. Reason : d]

10/19/2005 10:16:45 PM

confusi0n
All American
5076 Posts
user info
edit post

public class Bitch
{
//same for all Bitches
static double ovaries = 2.0

//different for each bitch
double slutFactor;

public double whore()
{
return 10f * slutFactor ^ ovaries;
}

public static double staticWhore()
{
//since this is static we can't use the instance variable slutFactor
// lets use a normal value (like 50, for example Joie would be 9813598 and sarose 981359898358913509896426249861938619305 )
double slutFactor = 50;
return 10f * slutFactor ^ ovaries;
}

public static void main(String[] args)
{
Bitch sarose = new Bitch();
sarose.slutFactor = 981985198f;
double sexLikelihood = sarose.whore();

//or
double sexLiklihood = Bitch.staticWhore();
}

}


[Edited on October 19, 2005 at 10:29 PM. Reason : code]

10/19/2005 10:28:15 PM

Novicane
All American
15411 Posts
user info
edit post

I laughed and I learned

amazing wolf web

10/19/2005 10:29:45 PM

psnarula
All American
1540 Posts
user info
edit post

something like this:

public class Witch
{
private double where = 10 * Math.pow(50,5);

public void setWhere(double d)
{
where = d;
}

public double getWhere()
{
return where;
}

public static void main
{
Witch myWitch = new Witch();
double asdf = myWitch.getWhere();
asdf += 50;
System.out.println("asdf = " + asdf);

}

10/19/2005 10:31:51 PM

Novicane
All American
15411 Posts
user info
edit post

im just having trouble understanding classes.

I could do this all in one public main, but I know I could make it less messy with classes.

10/19/2005 10:33:11 PM

psnarula
All American
1540 Posts
user info
edit post

take a look at the concepts in "Classes I", "Classes II", and "Classes III" here:

http://www.cs.umbc.edu/courses/undergraduate/202/fall05/schedule.shtml

it's C++ instead of java but the ideas are the same.

10/19/2005 10:39:49 PM

confusi0n
All American
5076 Posts
user info
edit post

it's really easy once you get it

say you have a factory that makes wigets.

Now this factory makes 3 different kind of widgets: sprocket, gear and chain

so lets make a class Widget

public class Widget
{
public static Material _my_material = Material.STEEL;

//Constructor makes a single Widget
public Widget()
{
}
}


okay so Widget is pretty boring but one thing is interesting. All widgets are always made of the Material 'Steel'.

Now if we take gear.....and say it's a type of Widget we are extending the functionality of Wdiget. This means he's everything a Widget is but even more!

public class Gear extends Widget
{
//I already have a material

public static boolean has_teeth = true; //this is something that is true for ALL gears.

//Variables that are specific to a single instance or type of gear!
public int num_teeth, size_teeth, diameter, pitch;

//Constructor
public Gear(int num_teeth, int size_teeth, int diameter, int pitch)
{
this.num_teeth = num_teeth //set the number of teeth for THIS gear
this.diameter = diameter //set the diameter for THIS gear!
.....
}

public Material getMaterial()
{
return _my_material;
}

public static Main(....)
{
//lets make multiple gears and put them together with a Chain

Gear gear1 = new Gear(1,2,3,4); //make a simple Gear
Gear gear2 = new Gear(4,3,2,1); //make another Gear

Material m = gear1.getMaterial //m will ALWAYS be Steel because ALL Widgets are steel
if ( gear1.has_teeth && gear2.has_teeth )
{
//always enter this block since ALL gears have teeth
}
}
}

10/19/2005 10:48:14 PM

Novicane
All American
15411 Posts
user info
edit post

Another n00b question

say I am writing writing a Slut public class

I want to take this:


inputStr = JOptionPane.showInputDialog(null, "Enter Dicks sucked:");
dicksSucked = Double.parseDouble(inputStr);
inputStr = JOptionPane.showInputDialog(null, "Enter Pussies Licked:");
pussiesLicked = Double.parseDouble(inputStr);


now I want to write a section to pass the parameters of how many dicks sucked AND pussiesLicked.


public class whoreLevel {
double x;
x = dicksSucked * pussiesLicked
return x
}


now I want to take that new number of dicks sucked * pussiesLicked and display it back in the main class:

JOptionPane.showMessageDialog(null, "Your chance of contracting HIV is: " + whoreLevel + "%");
}


this is the meat of java I fail to understand. Passing parameters to subclasses, creating a return value then passing that to the main class to display. What am I missing?

10/24/2005 3:20:14 PM

agentlion
All American
13936 Posts
user info
edit post

for one, you're placing too much emphasis on the "main class". There is no "main class" - each class has it's own separate functionality. If you are actually talking about the "main" method, then that is even worse. If you're trying to write programs with GUIs and elements like JOptionPanes, you really really need to get the class and division of labor concepts down.

10/24/2005 4:28:06 PM

Novicane
All American
15411 Posts
user info
edit post

Im use to visual basic. Each button did something when you wanted it to. You wrote code for it and that was it.

10/24/2005 4:50:35 PM

Incognegro
Suspended
4172 Posts
user info
edit post

[an elaboration on the differences between procedural programming and object-oriented programming goes here]

10/24/2005 4:54:19 PM

zorthage
1+1=5
17148 Posts
user info
edit post

Quote :
"Each button did something when you wanted it to."


It still does that, there is just more abstraction between "button pressed" and "something you wanted it to do." Like mentioned, get a grasp of OO, and it will make a world of sense.

10/24/2005 9:55:56 PM

 Message Boards » Tech Talk » java n00b question Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.38 - our disclaimer.