Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2012
    Location
    united states
    Posts
    4
    Rep Power
    0

    Default □ Inheritance and extends □ Overridden methods FRSTIATION OF FUN :(

    Please I need a lot of help on this, I am having difficulties trying to figure a way to get this code to work. I have tried a lot and even not sense staff. so please sorry if you dot see something right.

    What I trying to do is to get this program to show something like this :


    Please enter a radius in meters: 3

    Details for circle

    with radius 3.0:

    The area is 28.274333882308138 meters.

    The perimeter is 18.84955592153876 meters.


    main class:

    **
    *
    */
    Java Code:
    /**
     * @author giancarlo
     *
     */
    public class ShapeClass {
    	//Create a field (attribute) called type and another getter called getType() that returns a String,
    	//“generic type”. 
    	//This field will hold the type of the shapes when new shapes are created.
    	public String  Type;
    	
    
    	public String getType(){
    		return "generic type";
    	}//Create three getters for area, perimeter and parameters. 
    	//There is no need to create fields for these values, 
    	//simply have the methods return a default value: getArea() and getPerimeter() just return 0, 
    	//getParameterString() will return the String “no parameters specified for “+getType();
    		public  double getArea(){
    			return 0 ;
    			
    		}
    		
    		public double  getPerimeter(){
    			return 0 ;
    	}
    	public String getParameterString(){
    		return ("no parameters specified for "+getType());
    	}
    	//Create a default constructor and a 
    	//constructor that accepts the shape type as a parameter.
    	
    	public ShapeClass(String Type){
    		this.Type=Type; 
    	}
    	//Create a requestInput() method with type void. This is a 
    	//placeholder method in Shape. We will implement the method in the subclasses. 
    	//The only thing in this method will be a ;.
    	public void requestInput(){
    		;
    	}
        //Create an output method that displays the following information:
            //Details for <the shape type goes here>
    //with <the parameter string goes here>:
    //The area is <the area value goes here> meters.
    //The perimeter is <the perimeter value goes here> meters.
    	public void Outputmethod(){
    		System.out.println("   Details For: "+Type);
    		System.out.println("With: "+getParameterString());
    		System.out.println("The area is: "+getArea()+"meters");
    		System.out.println("The Perimeter: "+getPerimeter()+"meters");
    	}
    	//Test the shape class from the main method. Create a shape object and call its output method.
    	public static void main(String[] args) {
    		ShapeClass shapeClass= new ShapeClass("Circle");
    		
    		shapeClass.Outputmethod();
    		
    		
    	}
    }
    
    extention class:
    
    import edu.grcc.co117.utilities.InputHelper;
    
    
    public class CircleShape extends ShapeClass {
    	//Create the input parameters as attributes with appropriate types and create getters and setters for each,
    	//overriding the getters and setters from Shape. These should be standard getters and setters. 
    	//DO NOT request input from the user in the getters and setters. That will be accomplished in the next step 
    	//in the requestInput() method.
    	
    public double Parameter;
    
    /**
     * @return the parameter
     */
    public double getParameter() {
    	super.getParameterString();
    	return Parameter;
    }
    
    /**
     * @param parameter the parameter to set
     */
    public void setParameter(double parameter) {
    	Parameter = parameter;
    } 
    
    //Implement requestInput() to ask for the input parameters, overriding Shape's requestInput() method. 
    //The getParameterString() method creates a String of input parameters and their corresponding values.
    //Call the getter methods for each of the input parameters to print the value.
    
    public void requestInput(){
    	super.requestInput();
    	System.out.println("please enter radius: ");
    	Parameter=InputHelper.getDouble();
    }
    
    
    //Implement the getters for area and perimeter.
    public double getArea(double area){
    	super.getArea();
    	area=Math.PI*Parameter*Parameter; 
    	return area;
    }
    
    public double getPerimeter(double Perimeter){
    	Perimeter=2*Math.PI*Parameter;
    	return Perimeter;
    	
    }
    
    
    //DO NOT implement the output method in the child class. Let the class inherit this method from the Shape class.
    //Since the getters are defined in the Shape class and overridden in the child shape, the correct value will 
    //display for the shape created.
    
    	
    
    //Create a default constructor that calls the Shape class's constructor to set the type. 
    //Use the super method.
    public CircleShape(){
    	super("Circle");
    	
    }
    	
    
    //Create a main method that creates the child shape object, calls the requestInput() and output methods. 
    //Ask the user if they want to try again and loop. Make sure this is the main 
    //method selected when creating the jar file.
    	
    public static void main(String[] args) {
    	ShapeClass circleClass = new CircleShape();
    	boolean Answer;
    	do{
    	circleClass.requestInput();
    	circleClass.Outputmethod();
    	
    	System.out.println("Do you want to keep going (y/n)?");
    
    	 Answer = InputHelper.getBoolean("y");
    	}
    while (Answer);
    
    System.out
    		.println("thank you for working with us Today, Have a Nice Day.");
    }
    }
    Last edited by Norm; 03-28-2012 at 09:13 PM. Reason: added code tags

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,261
    Rep Power
    25

    Default Re: □ Inheritance and extends □ Overridden methods FRSTIATION OF FUN :(

    am having difficulties trying to figure a way to get this code to work
    Please explain what the problem is. Post the full text of the error messages.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Join Date
    Mar 2012
    Location
    united states
    Posts
    4
    Rep Power
    0

    Default Re: □ Inheritance and extends □ Overridden methods FRSTIATION OF FUN :(

    I am so sorry, the program runs but I am getting 0.0 values for getArea and getPerimeter instead of the actual values.
    I also want to print the parameter value in the getParameterString(), but I keep getting "no parameters specified for "+getType()
    please help!!!

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,261
    Rep Power
    25

    Default Re: □ Inheritance and extends □ Overridden methods FRSTIATION OF FUN :(

    Add some println statements to the getArea() method that prints out the values of all the variables used to compute the area value. The print outs should show you why the value is 0.

    no parameters specified for "+getType()
    That message comes from your code. If you want the code to do something different change it.


    If you get errors, copy the full text of the message and paste it here.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Join Date
    Mar 2012
    Location
    united states
    Posts
    4
    Rep Power
    0

    Default Re: □ Inheritance and extends □ Overridden methods FRSTIATION OF FUN :(

    this is what the console is showing:

    3
    Details For: Circle
    With: no parameters specified for generic type
    The area is: 0.0meters
    The Perimeter: 0.0meters
    Do you want to keep going (y/n)?

    as i said the program is working but is not showing what I want, somethig like this :

    Please enter a radius in meters: 3

    Details for circle

    with radius 3.0:

    The area is 28.274333882308138 meters.

    The perimeter is 18.84955592153876 meters.

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,261
    Rep Power
    25

    Default Re: □ Inheritance and extends □ Overridden methods FRSTIATION OF FUN :(

    Try debugging your code by Adding some println statements to the getArea() method that prints out the values of all the variables used to compute the area value. The print outs should show you why the value is 0.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    Join Date
    Mar 2012
    Location
    united states
    Posts
    4
    Rep Power
    0

    Default Re: □ Inheritance and extends □ Overridden methods FRSTIATION OF FUN :(

    No way!!!! you are a genius!!!! thank you it helps a lot, I am new at this and sometime I get frustrated easily, I just now have a small problem to change a double with a String.
    thank you

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,261
    Rep Power
    25

    Default Re: □ Inheritance and extends □ Overridden methods FRSTIATION OF FUN :(

    Is you have more questions, please post them.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Help with Inheritance and Static Methods
    By modhz in forum New To Java
    Replies: 13
    Last Post: 11-23-2011, 03:21 AM
  2. problem with two extends of Inheritance
    By MaceMan in forum New To Java
    Replies: 29
    Last Post: 04-14-2011, 04:06 PM
  3. Replies: 1
    Last Post: 03-20-2011, 05:11 PM
  4. Inheritance, methods, and toString...
    By Kreuz14 in forum New To Java
    Replies: 1
    Last Post: 04-01-2008, 10:12 PM
  5. Graphic settings being overridden?
    By sjchase in forum New To Java
    Replies: 0
    Last Post: 01-16-2008, 11:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •