Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with this program in java, here is the task thanks a lot! Inheritance and Interfaces. **I have written half of my program just

Need help with this program in java, here is the task

thanks a lot!

Inheritance and Interfaces. **I have written half of my program just wanted to confirm with an expert that what I have is correct or not** So please add necessary comments.

NOTICE: There are NO static variables allowed in this lab. The only class that a static method is allowed is in theTestDriver class. The only static method that you actually really need is main. All member variables must be private. Output statements should only be in the test class!

The purpose of this assignment is to practice developing classes, to use inheritance and interfaces, to develop a program to thoroughly test your classes and interfaces, and to generate official Javadoc documentation on all your classes.

Overview

You will be developing one interface, one base class that implements the interface, one derived class, and one test class. The interface and classes create a simple model of some basic electronic components and their behaviors. The basic formulas you will need to use to complete the model are explained and provided within this document. The following describes the interface and classes you must develop and test.

PowerDissipation Interface

This interface supports reporting the amount of power consumed by an electronic component given a currentvalue. If a component's power rating is exceeded it is expected to throw an Exception. This interface contains the following method:

double powerFromCurrent (double current) throws Exception;

Resistor Class

This class contains the primary electrical properties of a resistor. It has a resistance value in ohms which must be greater than 0, a tolerance value expressed as a number between 0 and 1 (not inclusive), and a power ratingexpressed as some number of watts greater than 0. This class implements the PowerDissipation interface.

The class has one constructor which takes values for the three properties and validates them. If any of the values are out of range, an Exception must be thrown containing a meaningful error message.

The class has one getter for the resistance value. It does not have setters. Once a Resistor object is created, it is immutable.

The class overrides the toString method. It returns a nicely formatted String reporting the values of the three properties.

It has the following two methods:

double minResistance( );

double maxResistance( );

These methods each return a value that is a function of the resistance property and the tolerance property. As an example, if the resistance is 10000, and the tolerance is 0.10, then:

Minimum resistance = 10000 * (1.0 - 0.10) = 9000

Maximum resistance = 10000 * (1.0 + 0.10) = 11000

It implements the method of the PowerDissipation interface. The following formula is needed to calculate the power dissipated by the resistor for a given current.

pd = current value * current value * maximum resistance value

If the calculated power dissipation exceeds the resistors power rating, then an exception must be thrown containing an appropriate error message.

VariableResistor Class

This class extends the Resistor class. It adds the ability to control the amount of resistance. It contains one additional property which is the control setting. The control setting can be varied from 0 to 1 inclusive. A setting of 0 means the resistance is effectively bypassed. A setting of 1 means 100% of the resistance is effectively seen.

The only constructor for this class takes 4 parameters. If any of the parameters are invalid an exception is thrown which contains a meaningful error message.

There is a setter for the control setting property. The setter must validate the parameter value. If it is out of range, it throws an IllegalArgumentException which contains a meaningful error message.

The base class methods for getResistance, minResistance, and maxResistance must be overridden to allow this class to apply the control setting as illustrated here:

baseClassMethod( ) * control setting value

For example, if the resistance value is 10000, and the control setting is 0.5, then this classs getResistancemethod would return 5000.

This class overrides the toString method of the base class. It adds the control setting value to the string from the base class.

This class overrides the base class method for the PowerDissipation interface. The code is basically the same as in the base class, but the maximum resistance value is different in this class than in the base class.

TestDriver Class

This class must contain test cases that thoroughly tests all aspects of the Resistor and VariableResistor classes. Itcontains the main method for the project. Each test case must be commented as to what is being tested. Each test case will generally include only a few lines of code, including an output statement that reports the result of that test.

Develop test cases for the Resistor class where all the inputs to the various class methods are valid.

Develop test cases for the VariableResistor class where all the inputs to the various class methods are valid.

Develop test cases for the PowerDissipation interface where all the inputs to the various interface methods are valid. Apply those test cases to both the Resistor object and the VariableResistor object.

Develop test cases for the Resistor class that cause all possible exceptions to be thrown. Test each boundary that can cause an exception to occur.

NOTE: When testing for an expected exception, a test case needs to be structured as follows:

try { // code that is supposed to cause an exception // output statement to report the test failed to generate the expected exception } catch ( Exception e) { // output statement to report the expected exception did occur }

Develop test cases for the VariableResistor class that cause all possible exceptions to be thrown. Test each boundary that can cause an exception to occur.

Develop test cases for the PowerDissipation interface that cause all possible exceptions to be thrown. Test each boundary that can cause an exception to occur. Apply these tests to a Resistor object and a VariableResistorobject.

Documentation

You must provide complete documentation for the PowerDissipation interface, and both the Resistor class and theVariableResistor class. Javadoc comments must be provided at the class and interface level that include the author plus an overview of the purpose of the interface or class. Javadoc comments must be provided for each method of the Resistor and VariableResistor classes. The method level comments must include parameter explanations, return explanations, and exception explanations. Any preconditions should be explained with the parameters and exceptions, and postconditions should be explained with the return.

The TestDriver class needs to have a class level Javadoc comment identifying the author, class section, professor, TA, and assignment. It should also explain the purpose of the TestDriver class.

Development Strategy

Develop things incrementally. Start with the Resistor class without implementing the PowerDissipation interface. When you have that set up, then write the test cases for that class. Once that class is tested, develop theVariableResistor class. Then write the test cases for that class. Then add the PowerDissipation interface. Implement that interface into the Resistor class. Add test cases for that. Finally override the PowerDissipationmethods from the Resistor class in the VariableResistor class. Then add the test cases for that.

Rubric (35 pts)

Use of any static variables will result in an automatic 25% point penalty. Use of static methods in any class other than the TestDriver class will result in an automatic 25% point penalty.

PowerDissipation Interface (3 pts)

Resistor Class (9)

Constructor with exception 1 getter min and max resistance toString Implements PowerDissipation interface

VariableResistor Class (10)

Properly uses inheritance from base class Constructor 1 setter with exception Overrides get, min, and max resistance Overrides toString Overrides PowerDissipation method

Test Class (9 pts)

Resistor class test cases for normal operation VariableResistor class test cases for normal operation PowerDissipation interface test cases for normal operation on both classes Resistor class test cases for exceptions VariableResistor class test cases for exceptions PowerDissipation interface test cases for exception on both classes Comments for every test case

Documentation (4 pts)

Class and method level Javadoc for Resistor class Class and method level Javadoc for VariableResistor class Interface level Javadoc for PowerDissipation interface. Class level Javadoc for TestDriver class.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Query Formulation And Administration Using Oracle And PostgreSQL

Authors: Michael Mannino

8th Edition

1948426951, 978-1948426954

More Books

Students also viewed these Databases questions

Question

Why would the CDC create a campaign involving the zombie?

Answered: 1 week ago

Question

Define Administration?

Answered: 1 week ago