QuestionQuestion

Simple Resistive Circuits


Objectives
 Develop an application based on requirements.
 Use JUnit for testing.
In this lab, you will model and solve simple DC circuits composed of any number of resistors and voltage sourced.
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
v20 3
r 2 3 0.5
r 3 0 1.0
end
To be correct, a circuit with n 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

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 v20 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.

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

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

package coe318.lab7;

import java.util.ArrayList;
import java.util.Scanner;

/**
*
* @author
*/
public class UserMain {

    public static void main(String[] args) {
       Scanner keyboard = new Scanner(System.in);

       ArrayList<Component> cs = new ArrayList<>();
       String input = "";
       do {
            input = keyboard.next();
            switch (input) {
                case "v":
                   cs.add(new Voltage(keyboard.nextInt(),
                            keyboard.nextInt(), keyboard.nextDouble()));
                   break;
                case "r":
                   cs.add(new Resistor(keyboard.nextInt(),
                            keyboard.nextInt(), keyboard.nextDouble()));...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$48.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats