Skip to content

Instantly share code, notes, and snippets.

@PocasPedro
Created October 30, 2017 17:48
Show Gist options
  • Save PocasPedro/dbb81693cd94b9abd92aa184fca679d2 to your computer and use it in GitHub Desktop.
Save PocasPedro/dbb81693cd94b9abd92aa184fca679d2 to your computer and use it in GitHub Desktop.
Java Fundamentals for Kids - Exercise 21
public class Head {
String eyecolor;
String nosetype;
boolean moustache;
Head (String eyes, String nose, boolean mouthhair){
eyecolor = eyes;
nosetype = nose;
moustache = mouthhair;
}
public static void main(String[] args) {
Head newhead = new Head("Green","Round",false);
newhead.print();
}
void print(){
System.out.println("My head has " + eyecolor + " eyes and a " + nosetype + " nose!");
if(moustache==true)
System.out.println("My head has a moustache!");
else
System.out.println("My head has no moustache!");
}
}
@jabrena
Copy link

jabrena commented Oct 30, 2017

Minor change:

public class Head {

String eyecolor;
String nosetype;
boolean moustache;

public Head (String eyes, String nose, boolean mouthhair){
	eyecolor = eyes;
	nosetype = nose;
	moustache = mouthhair;
}

public static void main(String[] args) {
	
	Head newhead = new Head("Green","Round",false);
	newhead.print();
}

void print(){
	System.out.println("My head has " + eyecolor + " eyes and a " + nosetype + " nose!");
	if (moustache==true) {
		System.out.println("My head has a moustache!");
	} else {
		System.out.println("My head has no moustache!");
	}
}

}

@jabrena
Copy link

jabrena commented Oct 30, 2017

public class Head {

String eyecolor;
String nosetype;
boolean moustache;

public Head (String eyes, String nose, boolean mouthhair){
	eyecolor = eyes;
	nosetype = nose;
	moustache = mouthhair;
}

void print(){
	System.out.println("My head has " + eyecolor + " eyes and a " + nosetype + " nose!");
	if (moustache==true) {
		System.out.println("My head has a moustache!");
	} else {
		System.out.println("My head has no moustache!");
	}
}

//Main method
public static void main(String[] args) {
	
	Head newhead = new Head("Green","Round",false);
	newhead.print();
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment