Create and Run Your First Java Application. Tasks

Author: Tatyana Milkina

Car Class

  1. Create three classes: Car in the com.company.vehicles package, Engine in the com.company.details package, and Driver in the com.company.professions package. All three classes are in different packages.
  2. In the main() method of the Car class, create objects of the Engine and Driver classes. When the Car program runs, it should print "I'm driving!" to the console. Compile and run the program.
  3. Use command-line arguments when running Car: the program should accept multiple arguments and print them in the following format:
    Value: arg1
    Value: arg2

Solution on Patreon.

Using the -cp Flag for Project Compilation

  1. Move the com.company.professions package to a separate project.
  2. Add object creation for the Engine and Driver classes in the Car class: Engine engine = new Engine(); Driver driver = new Driver(); We haven't covered object creation yet; this will be explained in future lessons. Here, the focus is on referencing other classes.
  3. Package the com.company.professions package into a JAR file and copy it to the lib directory.
  4. When compiling and running the Car class, specify the JAR file in the -cp option.

Solution on Patreon.

Курс 'Java для начинающих' на Udemy Курс 'Java для начинающих' на Udemy
Read also:
Comments