quiz حل الأسئلة الجامعية manage_search الأرشيف

تم الحل ✓
categoryبرمجة وتطوير البرمجيات schoolبكالوريوس event_available2026-07-13

السؤال

Transcribed Image Text:

1. Create a Java project called Lab7A and create a Java class called CarMain which includes the main method. Part A: a. Include a class called Car in the same Java file. This class has following instance variables and instance methods. Instance Variables Type: String Color: String Gas per mile: double Tank capacity: double Instance Methods Display car details Calculate number of miles can be travel from the gas in the full tank and return it. Calculate the cost per mile. The method takes the cost per gallon as the input parameter and return the cost per mile b. Create two objects of Car class in main method and assign the following values to each of the instance variables. Instance variables Type (String) Color (String) Gas per mile (double) Tank capacity (double) c1 c2 Ford Toyota Black Red 0.2 0.3 9.5 7.5 c. Call the three methods in the class separately using these two objects. Part B: d. Modify the Car class by adding a new constructor that takes initial values for all 4 instance variables as the input parameters and set the variables to them. e. Create another object of the Car class in main method using the new constructor with following values to instance variables. Instance variables Type (String) Color (String) c3 Nissan Yellow Gas per mile (double) 0.25 Tank capacity (double) 8.5 f. Call the three methods in the class separately using this new object. g. Correct the errors in previously defined objects by adding the default constructor to the Car class.

check_circle الجواب — حل مفصل خطوة بخطوة

hourglass_top