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 » » Help with Java Homework Page [1]  
billybob66
All American
1617 Posts
user info
edit post

Here is the assignment:
http://www.cs.unca.edu/~brock/classes/Fall2007/201/homework/home06.html

I've gotten as far as filling in the constructors and mutators, but I don't know what to do for the draw methods. And that array just confuses the fuck out of me. Help?

11/30/2007 6:41:58 PM

A Tanzarian
drip drip boom
10995 Posts
user info
edit post

Quote :
"I don't know what to do for the draw methods."


What did you do for assignment 3? It should be pretty similar.

Quote :
"And that array just confuses the fuck out of me."


An array is just a list.

Head[] totempole = new Head[4];


This creates a list of four Head objects, numbered 0, 1, 2, and 3.

You can access each one using totempole[0], totempole[1], totempole[2], or totempole[3]. This is what your instructor is doing here:

for (int i=0; i<totempole.length; i++) {
totempole[i] = new Head();

11/30/2007 6:51:35 PM

billybob66
All American
1617 Posts
user info
edit post

Cool, thanks. That makes sense. Now, I just need to know how to call those constructors...er, how do I use them? I fail to see the point in making them.

11/30/2007 6:58:32 PM

A Tanzarian
drip drip boom
10995 Posts
user info
edit post

Constructors are called automatically when you create a new object. The line

totempole[i] = new Head();

creates a new Head, assigns it to totempole[i], and calls the constructor.

Constructors are used to setup the object when you create it. Put code in it that creates the default head.

11/30/2007 7:08:36 PM

billybob66
All American
1617 Posts
user info
edit post

Here is the code from assignment 3, I am trying to figure out how to apply this to the draw methods.

Quote :
"
import java.util.Scanner ;
/**
*
* @author jernigcr
*/
public class Main {

/** Creates a new instance of Main */
public Main() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

System.out.println("Choices of hair style") ;
System.out.println("1) Straight") ;
System.out.println("2) Curly") ;
System.out.println("3) Balding") ;

System.out.println("Enter choice: ") ;
Scanner scanner = new Scanner(System.in);
int number = scanner.nextInt();

System.out.println("Choices of eye style") ;
System.out.println("1) Beady-Eyed") ;
System.out.println("2) Wide-Eyed") ;
System.out.println("3) Wears Glasses") ;

System.out.println("Enter choice: ") ;
int number2 = scanner.nextInt();

System.out.println("Choices of mouth style") ;
System.out.println("1) Smiling") ;
System.out.println("2) Frowning") ;
System.out.println("3) Surprised") ;

System.out.println("Enter choice: ") ;
int number3 = scanner.nextInt();

if (number <= 1) {
System.out.println(" ||||||||||||");
System.out.println(" ||||||||||||||||") ;
}else if (number <= 2) {
System.out.println(" @@@@@@@@@@@@") ;
System.out.println(" @@@@@@@@@@@@@@@@") ;
}else {
System.out.println(" ||| |||") ;
}

if (number2 <= 1) {
System.out.println(" | |") ;
System.out.println(" | |") ;
System.out.println(" | (*) (*) |") ;
System.out.println(" | |") ;
System.out.println(" _| |_") ;
}else if (number2 <=2) {
System.out.println(" | __ __ |") ;
System.out.println(" | ! ! ! ! |") ;
System.out.println(" | !o ! !o ! |") ;
System.out.println(" | !__! !__! |") ;
System.out.println(" _| |_") ;
}else {
System.out.println(" | |") ;
System.out.println(" | --- --- |") ;
System.out.println(" |---|o|--|o|---|") ;
System.out.println(" | --- --- |") ;
System.out.println(" _| |_") ;
}

if (number3 <= 1) {
System.out.println("|_ _|") ;
System.out.println(" | |______| |") ;
System.out.println(" | |") ;
System.out.println(" ______________ ") ;
}else if (number3 <= 2) {
System.out.println("|_ _|") ;
System.out.println(" | ______ |") ;
System.out.println(" | |______| |") ;
System.out.println(" ______________ ") ;
}else {
System.out.println("|_ _|") ;
System.out.println(" | o |") ;
System.out.println(" | |") ;
System.out.println(" ______________ ") ;
}
}
}
"

11/30/2007 7:12:57 PM

skokiaan
All American
26447 Posts
user info
edit post

Not only are you dumb, you have no integrity. I hope you fail

12/1/2007 5:37:29 AM

Rat
Suspended
5724 Posts
user info
edit post

lol @ this thread.

please choose another major if you can't do this in csc201

12/3/2007 5:15:40 PM

 Message Boards » Tech Talk » Help with Java Homework 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.39 - our disclaimer.