Hey guys I'm having some trouble working on an assignment for class (... again) and was wondering you guys could give me a little bit of input that might be able to help me figure this out. We're working on an assignment to create a house through shapes and we need to create methods to change the shapes (parts of the house) and no matter what I've tried I can't figure out how to get the shapes to actually change via the created methods.

This is the first step of the assignment with the next steps being more of the same for the other fields.

Add to the House class a method named changeRoofColor that has a String parameter variable and changes the color of roof according to the argument passed in the parameter. (Use changeColor , not setColor .)

Here's what I've got so far, the lines you see in [ ] are thing's I've tried that haven't worked for me.

 /*** Write a description of class House here.* * @author Nicholas Thomas* @version 2/13/2018*/public class House{private Square wall; private Square window;private Triangle roof;/** Making a house.* House Constructor**/public House(){wall=new Square(); roof=new Triangle();window=new Square();wall.makeVisible();wall.changeSize(100);wall.moveHorizontal(40);wall.moveVertical(150);roof.makeVisible();roof.moveHorizontal(100);roof.changeSize(60, 150);roof.moveVertical(125);roof.changeColor("black");window.makeVisible();window.changeSize(25);window.moveHorizontal(50);window.moveVertical(170);window.changeColor("blue");}/** Contains the main method.* Method main** @param args A parameter*/public static void main(String[]args){House house=new House();}/** This is a method to change the color of the roof. * Method changeRoofColor** @param roofColor*/public void changeRoofColor(String roof){[changeRoofColor();][changeRoofColor("green");]}/*** Method changeWallColor** @param wall A parameter*/public void changeWallColor(String wall){[house.changeWallColor();][this.changeWallColor();]}/**.* Method changeWindowColor** @param window A parameter*/public void changeWindowColor(String window){}/**.* Method moveHorizontal**/public void moveHorizontal(int Hotizontal){}/**.* Method moveVertical**/public void moveVertical(int Vertical){}/**.* Method makeInvisible**/public void makeInvisible(){}/**.* Method makeVisible**/public void makeVisible(){}}

I'd appreciate any advice you guys may have, I understand some of you are uncomfortable with helping with homework related questions, but I want to be clear and say I'm not looking for the complete solution just some help figuring out what I'm doing wrong and where to go from here.

Thank you for taking the time to read this and giving me any advice.

share|improve this question
  • You are already changing roof color in the constructor. Do the same in the method as well.– tsolakpFeb 14 at 20:26
  • According to the code you posted, roof is a data member of class House and it is a Triangle instance. So where is the code for class Triangle?– AbraFeb 14 at 20:29
  • You are not using the roof variable in your changeRoofColor. Try inside the method "roof.changeColor(roof);" Also, I don't see where you are actually calling this method.– isaaceFeb 14 at 20:32

You seem confused on how to call methods and pass in parameters.

The method

public void changeRoofColor(String roof){[changeRoofColor();][changeRoofColor("green");]}

should look like this:

 public void changeRoofColor(String color){roof.changeColor(color);}

because the parameter is here to accept a color not a roof. and since you want to change the roof color, you need to use the roof variable to call the changeColor method.

and the same concept applies for all your other methods.

share|improve this answer
  • Thank you, that's definitely what was throwing me off.– Nicholas ThomasFeb 14 at 21:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.