Question: Please edit my java code to match the following description...please use ArrayList as we don't know how many components the user is going to enter:
Please edit my java code to match the following description...please use ArrayList as we don't know how many components the user is going to enter:
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
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
-----------------------------------------------------------------------------------------------------------------------------------------------------
UserMain Class
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package coe318; import java.util.*; /** * * @author Asus */ public class UserMain { public static void main(String[] args){ ArrayList
}
------------------------------------------------------------------------------------------------------------------------------------------------------
Circuit Class
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package coe318;
import java.util.ArrayList;
/** * * @author Asus */ public class Circuit { private Resistor resist; private Voltage volts; private ArrayList
--------------------------------------------------------------------------------------------------------------------------------------------------------
Resistor class
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package coe318;
import java.util.ArrayList;
/** * * @author Asus */ public class Resistor { private Node node; private static int resistorID = 0; private ArrayList
// for(int resist : rID){ // s = "r"+ resist + s + node +s+ + RC; // } return s; } }
-------------------------------------------------------------------------------------------------------------------------------------------------------
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package coe318;
import java.util.ArrayList;
/** * * @author Asus */ public class Voltage { private Node node; private static int voltsID = 0; private ArrayList
--------------------------------------------------------------------------------------------------------------------------------------------------------
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package coe318;
import java.util.ArrayList;
/** * * @author Asus */ public class Node { private int n1,n2; private static int nodeID; private ArrayList
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
