Program.java Part 1: requires three files: Design and save your Motor class before you make Vehicle, so you can specify Motor as a Vehicle data attribute. Class Motor (make this class first because Motor is an attribute of class Vehicle) Attributes (all private) int cylinders int hp String type (possible values being gas, deisel, electric etc) Methods (all public) a constructor that can assign values to all attributes getters and for each attribute (setters not needed) a toString method that returns the status of a Motor instance, all attributes. Class Vehicle Attributes (all private) String make String model int year double price Motor motor (see below) Methods (public) a constructor that can assign values to all attributes a setter for the price a getter for the price a toString method that returns the status of a Vehicle instance, all attributes. Class TestVehicle This is the executable class. In the main method, make an arraylist of five or six Vehicle instances and then use a foreach loop to display them.
Program.java
Part 1: requires three files:
Design and save your Motor class before you make Vehicle, so you can specify Motor as a Vehicle data attribute.
Class Motor (make this class first because Motor is an attribute of class Vehicle)
Attributes (all private)
- int cylinders
- int hp
- String type (possible values being gas, deisel, electric etc)
Methods (all public)
- a constructor that can assign values to all attributes
- getters and for each attribute (setters not needed)
- a toString method that returns the status of a Motor instance, all attributes.
Class Vehicle
Attributes (all private)
- String make
- String model
- int year
- double price
- Motor motor (see below)
Methods (public)
- a constructor that can assign values to all attributes
- a setter for the price
- a getter for the price
- a toString method that returns the status of a Vehicle instance, all attributes.
Class TestVehicle
This is the executable class. In the main method, make an arraylist of five or six Vehicle instances and then use a foreach loop to display them.
Part 2
1. Write a Java program that prompts the user to enter a security code that matches a specific pattern. Your program must approve the user's entry. The pattern consists of these characters in this sequence:
A lower case character, two upper case characters, two or three digits, two lower case characters, an upper case character, 2 or 3 lower case characters, 2 digits.
Refer to Appendix H beginning on pages 1176.
Example Run
Enter the code pattern
bHT482haQmo82
Yes, bHT482haQmo82 matches the pattern
Recheck the requirements before you submit!
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 5 images