Uploaded by Daisuke Francis

JAVA Programming assignment

advertisement
Course: ECSE1209
Lecturer: Dr. Rakhee
Assignment 2
Instructions: You should submit only a single .java file that is titled id numberAssignment2.java (eg. 620123456-Assignment2.java). You should include all
complete programs in the same file and comment out the programs that you are not
running. The answers to the written questions should be done in comments above
the code you have written. Please also include your name and ID number in the
comments above the code. Failure to comply with these instructions will result in
immediate loss of marks. An example of the code format is shown below.
Course: ECSE1209
Lecturer: Dr. Rakhee
Assignment 2
Data Types, Variables and Constructors
1. What are primitive data types in Java?
2. What are the primitive data types supported by the Java programming language?
3. What are the 3 different scopes of variables in Java, and define each scope (state the
availability of the variable in each scope).
4. You are an engineer at a car dealership and your team is planning to release a new
feature on their web app. The purpose of the feature is to allow the users to get a
rough estimate as to the price of their vehicle. The value of the vehicle is calculated
according to the following formula:
• currentPrice = -200,000*ageOfVehicle + purchasePriceOfVehicle
As the primary backend engineer, you have been tasked with designing a demo of this
feature for the web app using Java. You must:
1. Declare an instance variable for the age of the vehicle in the main class, for the
purchase price of the vehicle and for the model name of the vehicle.
2. Create a constructor for the main class that takes the age of the vehicle, the
purchase price of the vehicle and the name of the model of the vehicle and
assigns them to constructor variables.
3. In the main function, prompt the user to enter the name of the model of their
vehicle, the age of their vehicle and the price at which they bought the vehicle.
4. Create an object of the class and assign the information from the user to the
class.
5. Using the object of the class, and its associated variables, calculate the current
price of the vehicle (according to the formula given above) and display the
result back to the user.
Example
Input
•
•
•
purchasePriceOfVehicle = 2000000.0
ageOfVehicle = 2
modelName = “2019 Subaru Legacy”
Output
•
The value of your 2019 Subaru Legacy now is $1600000.
Download