(derived from CISC191ObjOrientedDesign)
Java Test Driven Development (TDD) project to program Java classes with unit testing ( with JUnit )
Programming challenges for San Diego Community College CISC 191 Intermediate Java classes.
Created by
- Professor Dr. Tasha Frankie
- and Professor Allan Schougaard, San Diego Mesa College.
With contributions from:
- Dom David,
- Dan Sullivan
Object-oriented programming (OOP) is a programming paradigm that is widely used in Java. OOP is a programming style that emphasizes the use of objects, which are instances of classes, to represent data and methods that operate on that data. OOP provides a clear structure for programs, making them easier to maintain, modify, and debug. It also helps to keep the code DRY (Don’t Repeat Yourself) by reducing the repetition of code. OOP makes it possible to create full reusable applications with less code and shorter development time. Java’s OOP features include classes, objects, inheritance, encapsulation, and polymorphism.
Interfaces and abstract classes are important in Java OOP for several reasons. Both of these concepts allow developers to create more flexible and modular code that can be easily extended and reused. Interfaces are used to define a set of methods that a class must implement. They provide a way to achieve abstraction in Java, which is one of the key features of OOP. Interfaces are useful when you want to define a contract that must be followed by any class that implements it. They also allow you to create code that is more loosely coupled, which makes it easier to maintain and modify. For example, you can define an interface for a database connection and then have multiple classes implement that interface to connect to different types of databases.
Abstract classes are similar to interfaces, but they can also include implemented methods. Abstract classes are used to provide a base class for concrete subclasses to inherit from. They allow you to define a set of methods that must be implemented by any subclass, while also providing some default behavior that can be inherited by those subclasses. Abstract classes are useful when you want to create a class hierarchy that shares some common functionality, but also has some unique behavior in each subclass.
By using interfaces and abstract classes, developers can create code that is more scalable and easier to maintain over time.
- From the <> Code dropdown link in the repository (above), download the Zip file to your computer.
- Extract the files to your working folder
- Open Eclipse and import the project.
- You can use File>Import menu item or right-click in the Package Manager and choose Import.
- select General>Projects from Folder or Archive
- navigate into the project until you see the
binandsrcfolders, and choose open
- Expand the project in the package explorer and find the .java files below the src folder.
The layout of this project is similar to the the java classes lab. You will implement the logic of several java classes and interfaces..
testVehicle
- Open the Vehicle class and include the missing elements. Use the diagram to help guide you. What you see in the diagrams above shows information regarding the method headers. For example, getManufacturname is the name of one of the methods and returns a String.
- The only weird part about this one is the last parameter of the constructor. It requires an Option type. Create a blank Option class now so that you can use it as a type. Note that the instance variable for this will be an array of options.
- Other than the Option class, the rest of the tests are strictly getters to check that the instance variables of a Vehicle object are being set properly.
testOptions
It's time to expand on the Option class. You will see that an option will keep track of a String to describe the option.- Add the missing instance variable
- Add the constructor so that can create an Option object with a given String (the "option").
- Add the getter, but the getter must be specifically called getDetails
- At this point, if you missed the fact that the Vehicle must have an array of Option objects then go back to Vehicle and make sure one of the instance variables is an array of Option objects. Your constructor's parameter list should match this change.
- Add the getOptions method in Vehicle which returns the array of Option objects.
testCar
- Add the Car class. What class does it extend? Make sure your class header reflects the proper relationship.
- You'll notice that the constructor has an additional parameter in the parameter list. What might this be? Add the corresponding instance variable for it.
- Add the constructor. Make sure to call the super constructor here.
- Add the missing method from the diagram.
testPickUpTruck
- Create the PickUpTruck class
- Look at the diagram to figure out what instance variable is unique to a PickUpTruck
- Did you extend the right class based on the diagram?
- Add the missing constructor. You may need to add an additional parameter in the parameter list to account for the instance variable in PickUpTruck. This is similar to what you had to do for Car.
- Add the missing method. What instance variable does it return?
testGasCar
- Create the necessary class and make sure it extends the correct class per the diagram.
- This one does not have a lot to it because it inherits a lot of the behaviors of its superclasses in the multi-level inheritance as shown in the diagram. (not the same as multiple inheritance)
testCarIsCombustible
- Per the diagram, Combustible is an interface that will be used by the GasCar and the HybridCar classes. Create the interface.
- Add the method headers. Remember the methods do not have bodies in interfaces. They describe the desired behavior only.
testCarIsChargeable
- Create the corresponding Interface
- Add the method headers. Remember, interfaces do not implement the body of the methods.
Others
There are things repeated in this lab. Testers not mentioned would follow the same testing methodology.- Run and add the code to the src folder until the tests are successful.
- Uncomment each test case in the Test file, one at a time. Do not modify the content in this file except to uncomment the tests. Add and modify class files as needed for the tests to pass.
- Review and refactor any of the code as needed:
- be sure your code follows good coding practices and coding style and standards.
- update the javadoc comments at the top of the file to add your name as author
- update the comments for each method in the file.
- Export the project as a zip file and submit your work.
this repository is a subset of the CISC191 exercises. It is derived from the CISC191ProgrammingChallenges activity hosted by Professor Allan Schougaard, San Diego Mesa College, and not a direct fork.
This project is to decompose that repository into git submodules

