COE318 Lab 7 (2017)

Simple resistive circuits

coe318 Lab 7

Simple Resistive Circuits

Objectives

Develop an application based on requirements.

Use JUnit for testing.

Duration: two weeks.

In this lab, you will model and solve simple DC circuits composed of any number of resistors and 

voltage sources.

Unlike previous labs, you are not given the design for this application. It is up to you to decide what 

classes, interfaces, methods, etc. that you will need.  The one exception is that you must have a class 

called 

UserMain

that has a 

main()

method that reads and interprets input from 

stdin

(by default, the

keyboard).

Overview

An electric circuit will be described by the user.  Each line will describe either a Resistor or a DC 

Voltage source or be a single word command.

The format for describing (for example) a 5.2 Ohm resistor connected between nodes 2 and 3 is:

r 2 3 5.2

The format for describing a 6.5 Volt source connected between nodes 1 and 2 (where the positive side 

of the source is connected to node 1) is:

v 1 2 6.5

A complete circuit could be described as follows:

v 1 0 2.0

r 1 2 0.25

v 2 0 3

r 2 3 0.5

r 3 0 1.0

end

To be correct, a circuit with 

nodes must name the nodes 0, 1,...

n-1

.  The order in which the 

components are described does not matter.  For non-polarized components (such as a resistor), the 

order in which the nodes are named does not matter.  For example,

r 1 2 0.25

is equivalent to:

r 2 1 0.25

Page 

1

of 

3

COE318 Lab 7 (2017)

Simple resistive circuits

For polarized components (such as a voltage source), the order does matter. Thus:

v 1 0 2.0

is equivalent to:

v 0 1 -2.0

In addition to lines describing the components of a circuit, there are 2 other single word commands that

can be entered: 

spice

and 

end

.

The 

end

is the simplest to understand and implement.  When the 

end

command is entered, the 

program should print

All Done

and terminate.

The 

spice

command should print the spice description of the circuit entered so far.  In the spice 

description, uppercase letters are used, components are numbered sequentially and 

DC

is used in the 

description of voltage sources.  An example session follows (the lines in bold denote output from the 

program; the non-bold lines are input):

v 1 0 2.0

r 1 2 0.25

v 2 0 3

r 2 3 0.5

r 3 0 1.0

spice

V1 1 0 DC 2.0

R1 1 2 0.25

V2 2 0 DC 3.0

R2 2 3 0.5

R3 3 0 1.0

end

All Done

Part 1: Create your project and implement the end command

1.

Create a Netbeans project called 

AnalogCircuit

which should be placed in a folder called 

lab7

(all lowercase and no spaces).  The 

lab7

folder should itself be in your 

coe318

folder.

2.

Create a class 

UserMain

with a 

main

method that reads 

stdin

and interprets the 

end

command.  This and all classes should be in a package called 

coe318.lab7.

Part 2: Interpret the circuit and Implement the spice command

You need to define classes that will allow you to model the circuit.  Include javadoc comments for all 

public methods, classes, interfaces and constructors. Once you can interpret circuit components, you 

should be able to implement the 

spice

command.

Page 

2

of 

3

COE318 Lab 7 (2017)

Simple resistive circuits

Part 3: Write unit tests for one of the classes

Write JUnit tests for testing at least two methods of one of the classes that you write. 

Finally: Submit your lab

1.

Submit your lab by zipping it to a file called 

lab7.zip

2.

Then use the command 

submit coe318 lab7 lab7.zip

to complete the submission.

Page 

3

of 

3

    • 9 years ago
    java file here
    NOT RATED

    Purchase the answer to view it

    blurred-text
    • attachment
      UserMain.zip