Question

Need help with Java, I was able to get this done half way but still very...

Need help with Java, I was able to get this done half way but still very confusing afterwards.

for this class create an outer class called OuterCar with method called drive.

Create an inner class called InnerEngine with methods called start, stop and shift (all methods with simple print statements)

Call inner class methods called start, stop and shift from outer class drive method.

The solution will produce the following:

  1. OuterCar class
  2. OuterCar class with drive method
  3. InnerEngine class
  4. InnerEngine methods start, stop and shift
  5. OuterCarTest class with main method
0 0
Add a comment Improve this question Transcribed image text
Answer #1
//OuterCar.java
public class OuterCar {
    // Instance variable
    InnerEngine innerEngine;

    // Constructor
    public OuterCar() {
        innerEngine = new InnerEngine();
    }

    // drive method
    void drive(){
        //Calling inner class methods called start, stop and shift
        innerEngine.stop();
        innerEngine.shift();
        innerEngine.stop();
    }

    private class InnerEngine {
        // start method
        void start(){
            System.out.println("Engine started");
        }

        // stop method
        void stop(){
            System.out.println("Engine stopped");
        }

        // shift method
        void shift(){
            System.out.println("Moving...");
        }
    }
}

/////////////////////////////////////////////////////////////

//OuterCarTest.java
public class OuterCarTest {
    public static void main(String[] args) {
        OuterCar outerCar = new OuterCar();
        outerCar.drive();
    }
}

Engine stopped
Moving...
Engine stopped
Add a comment
Know the answer?
Add Answer to:
Need help with Java, I was able to get this done half way but still very...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need this in java please Create an automobile class that will be used by a...

    I need this in java please Create an automobile class that will be used by a dealership as a vehicle inventory program. The following attributes should be present in your automobile class: private string make private string model private string color private int year private int mileage. Your program should have appropriate methods such as: default constructor parameterized constructor add a new vehicle method list vehicle information (return string array) remove a vehicle method update vehicle attributes method. All methods...

  • easy question but i am confused. someone help Consider the following Java classes: class OuterClass {...

    easy question but i am confused. someone help Consider the following Java classes: class OuterClass { static class InnerClass { public void inner Method({ System.out.println("This is my inner class"); public static void outer Method{ System.out.println("This is my outer class"); public class OuterClass Test{ public static void main(String args[]) { Complete the class OuterClass Test to produce as output the two strings in class OuterClass. What are the outputs of your test class?

  • Please I need help with the following questions in JAVA programming language. Please comment the code...

    Please I need help with the following questions in JAVA programming language. Please comment the code to help me understand, thanks. Exercise 1: Inheritance 1. Firstly, create and compile a simple class called Parent. Give it the following behaviour: a. A default constructor that does nothing other than print out “Parent default constructor” using System.out b. A single method called getMessage which returns a String, e.g. “Parent message” 2. Next, create and compile a class called Child. Give it the...

  • i was able to make sense on the others but this two i need help Name:...

    i was able to make sense on the others but this two i need help Name: ImprovedQueue<T> Access Modifier: public Implements: QueueInterface<T> Instance variables Name: front Access modifier: private Data type: QueueNode<T> Constructors: Name: ImprovedQueue Access modifier: public Parameters: none (default constructor) Task: sets the value of front to null Methods Name: isEmpty Access modifier: public Parameters: none Return type: boolean Task: returns true if the front is equal to null; otherwise return false Name: dequeue                            Access modifier: public Parameters:...

  • in java : Create Java Application you are to create a project using our designated IDE...

    in java : Create Java Application you are to create a project using our designated IDE (which you must download to your laptop). Create the code to fulfill the requirements below. Demonstrate as stipulated below. Create a Main Application Class called AddressBookApplication (a counsole application / command line application). It should Contain a Class called Menu that contains the following methods which print out to standard output a corresponding prompt asking for related information which will be used to update...

  • please help me I need two methods that add and subtract two very large numbers in...

    please help me I need two methods that add and subtract two very large numbers in java created in a class called number and it runs on the demo below class below. Please don't use parseInt or BigIntger, they are not allowed. Thank you so much public class demoClass { public static void main(String[] args) { number num1; //number is class that we need to create to the add and subtract methods num1 = new number("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"); number num2; //number is...

  • Is there any way that I can call method in other class without constructor in java?...

    Is there any way that I can call method in other class without constructor in java? public class Chest { private String contents; public String getContents()    {        return contents;    } public void setContents(String contents)    {               this.contents = contents;           } I need to set content and print out in the main method, but it keep gives me a error message when I try Chest.setContents("Gold"); on main class. I suppose...

  • PLEASE I NEED HELP WITH THIS JAVA CODE Homework 3-3 Create a Driver class to use...

    PLEASE I NEED HELP WITH THIS JAVA CODE Homework 3-3 Create a Driver class to use your Airplane and Passenger classes and create instances of them. In the main method do the following: Create an Airplane that will store up to 100 Passengers Create 5 Passenger Objects with the details specified in the table below Add the 5 Passenger objects to the Airplane Call the printDetails method from the Airplane to print all the Airplane and Passenger details. variable name...

  • I need help writing my main method**** Computer Science 111 Introduction to Algorithms and Programming: Java...

    I need help writing my main method**** Computer Science 111 Introduction to Algorithms and Programming: Java Programming Project #4 – Classes and Objects (20 Points) You will create 3 new classes for this project, two will be chosen from the list below and one will be an entirely new class you invent.Here is the list: Shirt Shoe Wine Book Song Bicycle VideoGame Plant Car FootBall Boat Computer WebSite Movie Beer Pants TVShow MotorCycle Design First Create three (3) UML diagrams...

  • Hi, I need help with this Java activity. The requirements are: 1. Create a NetBeans project...

    Hi, I need help with this Java activity. The requirements are: 1. Create a NetBeans project for this activity. 2. Create a new class with attributes name and address. Both data type will be String. Create a constructor and assign the parameters to the attributes. 3. Create a class with the main method and create an instance of the class that you created in Test Stem 1. 4. Create an instance of the string in your test class and assign...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT