Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: help with interface

  1. #1
    Junior Member
    Join Date
    Aug 2017
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default help with interface

    The CarPart class should also implement a Functional interface, which declares a method "function()".< ------ This is an instruction which I am trying to do but it is not working. Please help. I got an error ---class Engine extends CarPart implements myinterface ----at this line
     
     
     
    public class Simulator {
     
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		Car mycar = new Car("Red");
    		mycar.run();
     
    		CarPart my_car_part = new CarPart();
    		my_car_part.status(90);
     
     
    		Engine my_engine = new Engine(true);
    		my_engine.status(100);
     
    		my_engine.function();
    	}
     
     
     
    }
     
    class Car{
    	private String color = " ";
    	public Car(String n_color)
    	{
    		this.color = n_color;
    	}
    	public void run() {
    		System.out.println("This can can run");
    	}
    }
    class CarPart
    {
    	public interface myinterface{
     
    		public void function();
     
    	}
     
     
     
    	public static final int MAX = 100;
    	public static final int MIN = 0;
    	int condition;
     
     
    	public CarPart()
    	{
    		this.condition = MAX;
    	}
    	public void status(int n_condition)
    	{
    		condition = n_condition;
    		if(condition == MAX )
    		{
    			System.out.println("Brand new part");
    		}
    		else if (condition <100 && condition > 80)
    		{
    			System.out.println("Fairly new part");
    		}
    		else if(condition <= 80 && condition > 40)
    		{
    			System.out.println("ok part");
    		}
    		else if(condition <= 40 && condition > 0)
    		{
    			System.out.println("old Part");
    		}
    		else if (condition == 0)
    		{
    			System.out.println("Not working Part");
    		}
    		else
    		{
    			System.out.println("Invalid Input");
    		}
     
    		//System.out.println("update satus");
    	}
    }
     
     
    class Engine extends CarPart implements myinterface {
    	//private String engine_type = " ";
    	private boolean engineState = false;
    	private int engine_horse_power = 100;
     
    	public Engine( boolean n_engineState) {
    		super();
    		this.engineState = n_engineState;
    		if(engineState == true)
    		{
    			engineSound();
    		}
    		else
    		{
    			System.out.println("Engine is dead");
    		}
    	}
     
    	public void function()
    	{
     
    	}

  2. #2
    Junior Member
    Join Date
    Aug 2017
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default help with interface

    The CarPart class should also implement a Functional interface, which declares a method "function()".< ------ This is an instruction which I am trying to do but it is not working. Please help
     
     
     
    public class Simulator {
     
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		Car mycar = new Car("Red");
    		mycar.run();
     
    		CarPart my_car_part = new CarPart();
    		my_car_part.status(90);
     
     
    		Engine my_engine = new Engine(true);
    		my_engine.status(100);
     
    		my_engine.function();
    	}
     
     
     
    }
     
    class Car{
    	private String color = " ";
    	public Car(String n_color)
    	{
    		this.color = n_color;
    	}
    	public void run() {
    		System.out.println("This can can run");
    	}
    }
    class CarPart
    {
    	public interface myinterface{
     
    		public void function();
     
    	}
     
     
     
    	public static final int MAX = 100;
    	public static final int MIN = 0;
    	int condition;
     
     
    	public CarPart()
    	{
    		this.condition = MAX;
    	}
    	public void status(int n_condition)
    	{
    		condition = n_condition;
    		if(condition == MAX )
    		{
    			System.out.println("Brand new part");
    		}
    		else if (condition <100 && condition > 80)
    		{
    			System.out.println("Fairly new part");
    		}
    		else if(condition <= 80 && condition > 40)
    		{
    			System.out.println("ok part");
    		}
    		else if(condition <= 40 && condition > 0)
    		{
    			System.out.println("old Part");
    		}
    		else if (condition == 0)
    		{
    			System.out.println("Not working Part");
    		}
    		else
    		{
    			System.out.println("Invalid Input");
    		}
     
    		//System.out.println("update satus");
    	}
    }
     
     
    class Engine extends CarPart implements myinterface {
    	//private String engine_type = " ";
    	private boolean engineState = false;
    	private int engine_horse_power = 100;
     
    	public Engine( boolean n_engineState) {
    		super();
    		this.engineState = n_engineState;
    		if(engineState == true)
    		{
    			engineSound();
    		}
    		else
    		{
    			System.out.println("Engine is dead");
    		}
    	}
     
    	public void function()
    	{
     
    	}


    --- Update ---

    Never mind, I found the problem. Thanks

Similar Threads

  1. Interface
    By gautammuktsar@gmail.com in forum Object Oriented Programming
    Replies: 2
    Last Post: February 7th, 2014, 03:00 AM
  2. interface
    By tungan91 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 13th, 2012, 09:50 PM
  3. Interface?
    By jean28 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 14th, 2012, 01:02 AM
  4. Interface
    By kaasi in forum Member Introductions
    Replies: 4
    Last Post: April 21st, 2011, 10:45 AM
  5. interface
    By nasi in forum Object Oriented Programming
    Replies: 5
    Last Post: September 2nd, 2010, 10:36 PM