Question

Java Programming, I have already finished SportCar and Airplane.

Java Programming, I have already finished SportCar and Airplane.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Short Summary:

  • Implemented Playground.java to call respective methods based on the instances in the array

Playground.java


//This class creates instances and adds to Object array
public class Playground {

   public static void main(String[] args) {
       //Create instances for sportscar and airplane
       SportsCar sportsCar1=new SportsCar();
       SportsCar sportsCar2=new SportsCar();
       Airplane airplane1=new Airplane();
       Airplane airplane2=new Airplane();
       //Create generic object array
       Object[] vehicle= {sportsCar1,sportsCar2,airplane1,airplane2};

       //Iterate through Object array and check if the object is Sprotscar or Airplane
       for(Object obj:vehicle)
       {
           //Check if array element is instance of Sportscar
           if(obj instanceof SportsCar)
           {
               ((SportsCar) obj).sound();
           }
           //else it is instance of Sportscar
           else
           {
               ((Airplane) obj).changeSpeed();
           }
       }
   }

}

**************Please do upvote to appreciate our time. Thank you!******************

Add a comment
Know the answer?
Add Answer to:
Java Programming, I have already finished SportCar and Airplane.
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 have a question regarding java programming. If I have this in a text file, "...

    I have a question regarding java programming. If I have this in a text file, " hey you <hello world> " How can I get it so that it only extracts the words in between the "< > " ? I am doing this with a stream and I know you can get it with the .map() function but I cannot figure out how to do it.

  • JAVA PROGRAMMING I want to make sure I have learned the compareto statements correct and other...

    JAVA PROGRAMMING I want to make sure I have learned the compareto statements correct and other things. This was on my lecture slide today and I don't understand the compare to regarding how they get values for the strings. Please answer the following. Suppose that s1, s2, and s3 are three strings, given as follows String s1 = "Welcome to Java". String s2 = "Programming is fun". String s3- "Welcome to Java" hat are the results of the following expressions?...

  • Working in java programming. I have a class (call it manage) that takes in an arraylist...

    Working in java programming. I have a class (call it manage) that takes in an arraylist (list) and a boolean (switch), which is created/preset in the parent main function above this class. The arraylist is modified and returned to the main function however, hence it's name 'manage.' I need help declaring the arraylist in the constructor? public class manage{ public manage(){ //Constructor // What is arraylist construction? this.switch = false; } public manage(ArrayList<Integer> list, boolean switch) { this.list = list;...

  • JAVA ONLY I have a programming project, and I have to create a method called String...

    JAVA ONLY I have a programming project, and I have to create a method called String computePay(double hours) - computes the weekly pay for a Worker. Returns the output as a String that always displays the result to 2 decimal points. This is what I have done thus far... Can you help? public class Worker{ private String name; private double salaryrate; private double a;    public void Gavin(String uname, double usalaryrate){ name=uname; salaryrate=usalaryrate; }    public String computePay (double hours){...

  • This is in java language. Please use simple java programming language. Each of the parts a....

    This is in java language. Please use simple java programming language. Each of the parts a. through c. below is preceded by a comment indicating what the code do. There is a least one problem with each section of code and it fails to do what was inte Show how to modify or rewrite the code so that it works as intended. Assume that all varia used have already been declared. а. // INTENT : given an array arr of...

  • I am in java programming I need to // TO DO: Add a function call to...

    I am in java programming I need to // TO DO: Add a function call to the function named // findMaxSalesAndBestSellingAgent() // with 3 arguments (maxSalesDouble, totalHousePriceDouble, and // totalHousePriceDouble) // using an assignment statement form) and store the value returned by the // function // in the input variable maxSalesDouble I wrote this in the code maxSalesDouble = findMaxSalesAndBestSellingAgent(totalHousePriceDouble); Would this be correct?

  • (Java with Netbeans) Programming. Please show modified programming code for already given Main class, and programming...

    (Java with Netbeans) Programming. Please show modified programming code for already given Main class, and programming for code for the new GameChanger class. // the code for Main class for step number 6 has already been given, please show modified progrraming for Main class and GameCHanger class, thank you. package .games; import java.util.Random; import java.util.Scanner; public class Main { public static void main(String args[]) { System.out.println("Welcome to the Number Guessing Game"); System.out.println(); Scanner sc = new Scanner(System.in); // Get upper...

  • really need help. All information that i have is posted, In java Dynamic programming allows you...

    really need help. All information that i have is posted, In java Dynamic programming allows you to break a large problem into multiple subproblems. Each of these subproblems must be solved, and the solution must be stored as a memory-based solution. Solve the following binary search algorithm using dynamic programming (Adapted from Esquivalience, 2018): Graph To solve this problem, complete the following tasks: Create a binary search tree using a data structure. Insert the node values as described in the...

  • I have nine different programming textbooks on my bookshelf, five C++ and four Java. In how many ways can I arrange the...

    I have nine different programming textbooks on my bookshelf, five C++ and four Java. In how many ways can I arrange the books a) if there are no restrictions? b) ifthe languages should alternate? c) if all the C++books must be next to each other? d) if all the C++books must be next to each other and all the Java books must be next to each other? 1. 2. Suppose that you draw five cards from a standard deck of...

  • Programming in Java. Please attached the screenshot of source code and the output Thanks. Java Programming:...

    Programming in Java. Please attached the screenshot of source code and the output Thanks. Java Programming: A Comprehensive Introductia See this solution in the app :3 Chapter 3, Problem 17E Bookmark Show all steps: 0 ON Problem Write a program that uses a loop to print a list of 100 numbers consisting of alternating 1's and -1's, starting with 1.

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
ADVERTISEMENT