Module 4: Final project and assessment: Introduction to software development
Course quiz: Introduction to software development
Graded Assignment
1. To create an object myCar of class Car, which syntax is correct?
- myCar = new
- Car(); Car = new myCar();
- Car myCar = new Car();
- Car myCar();
2. You are creating a Java program to manage a fleet of vehicles. Each vehicle is represented by an object of the Vehicle class, which has a field named model. You want to display the model of a specific car that has been created as an instance of the Vehicle class. To retrieve the model field of an object car of class Vehicle, you use:
- car.model;
- Vehicle.model;
- model.car;
- car->model
3. Complete the sentence: In Java, a constructor…:
- Is only called once during the class definition.
- Is a method that can be overridden.
- Is used to initialize objects.
- Can return multiple values.
4. You are developing a Java application for a retail store. The application has a Customer class that stores customer information. You want to create objects of this class, allowing users to either specify customer details like name and ID or use default values if no specific details are provided. What should you do to create Customer objects with either specific data or default values?
- Avoid constructors and initialize data manually.
- Use static factory methods.
- Use only a default constructor.
- Define multiple constructors, including a no-arg constructor and parameterized constructor.
5. You are developing a TemperatureConverter class that includes a method to convert temperatures from Celsius to Fahrenheit. This method should be named celsiusToFahrenheit and take a single double argument representing the temperature in Celsius. It should return a double representing the temperature in Fahrenheit. What is the appropriate method signature for the celsiusToFahrenheit method in the TemperatureConverter class?
- double convert(double temperature)
- void celsiusToFahrenheit()
- double celsiusToFahrenheit(double temperature)
- void celsiusToFahrenheit(double temperature)
6. True or False: In Java, a class can have multiple constructors.
- False
- True
7. How would you use a for loop to iterate over an array of integers called numbers and print each element?
8. How would you use a do-while loop to calculate the factorial of a given positive integer n?
9. You are writing a Java program that needs to print numbers from 1 to 10. Which while loop correctly implements this?
10. You are writing a Java program that determines the eligibility of a person to vote. The program should check if the person's age is 18 or above. If their age is 18 or above, they are eligible; otherwise, they are not. Which if-else statement correctly checks for voting eligibility?
11. You are implementing a Java application that determines the type of day based on the day of the week. The days are represented as integers from 1 (Monday) to 7 (Sunday). The types of days are "Weekday" for Monday to Friday and "Weekend" for Saturday and Sunday. Which switch statement correctly categorizes the day type?
12. Which method should you use to determine the number of characters in a username String?
- length()
- count()
- size()
- getLength()
13. You are developing a Java application to calculate the total score in a game. You need to declare a variable to store the player's score and initialize it with a starting value. Fill in the blanks to declare and initialize a variable for the player's score: _____ score = ___;.
- int, 100
- 100, int
- score, int
- int, “100”
14. You are designing a Java application for a zoo management system. You decide to create a base class called Animal and a derived class called Mammal. Fill in the blank to declare a class Mammal that inherits from the Animal class:
- inherits
- implements
- super
- extends
15. You are debugging a Java program and find a field declared with the default (no modifier) access level.
True or false: A class member with default access (no explicit modifier) is accessible only within the class in which it is declared.
- False
- True