Please help with java program. I am in cs1 so nothing to complicated. I will pos
ID: 3556021 • Letter: P
Question
Please help with java program. I am in cs1 so nothing to complicated. I will post twice so you can recieve double points please help need by friday.
Specifications
Circuits for the program will be specified using an input file format. An input file defines a single
circuit, which may have subcircuits, which in turn may have more subcircuits. Three circuit types may
be used, namely
1. A simple resistor, defined by the keyword "resistor", followed by the resistance
2. A circuit wired in series, which consists of the keyword "series" followed by a commaseparated
list of subcircuits enclosed within curly braces {}.
3. A circuit wired in parallel, which consists of the keyword "parallel" followed by a commaseparated
list of subcircuits enclosed within curly braces {}.
Note that the subcircuits of a series or parallel circuit can themselves be series or parallel circuits. This
makes the file format "recursive". Comments are also allowed in files. The "pound sign", #, indicates
that the remainder of the line should be considered a comment. An example input file is given as
follows:
# circuit specification
series # series circuit
{
parallel # parallel circuit
{
resistor 3.2, # simple resistor
resistor 4.1
},
series
{
resistor 1.0,
parallel
{
resistor 1.0,
resistor 2.0
},
series
{
resistor 3.2,
resistor 4.0
}
}
}
Your goal in this program is to read in a circuit from a file, given the name of the file on the command
line. Once your program has done this, it should print out an XML version of the input file with the
resistance of each series or parallel circuit indicated as an attribute of the element. Your program must
also format the output, indenting lines properly, even if the input is not properly indented.
Example input 1:
# Circuit specification
series
{ resistor 1, # improper format
resistor 2,
resistor 3
}
Example Output 1:
<series resistance="6.0">
<resistor resistance="1.0" />
<resistor resistance="2.0" />
<resistor resistance="3.0" />
</series>
import java.util.Scanner;
public abstract class Circuit
{
/**
* Get the resistance of the circuit
* @return the resistance of the circuit.
*/
public abstract double getResistance();
/**
* Loads the circuit from a scanner. It is assumed
* that it may call this recursively.
* @param scan the input stream
*/
public abstract void loadCircuit(Scanner scan);
/**
* Prints the circuit in a hierarchical fashion in XML, giving
* the resistance of each piece.
* @param indent indentation string for each line of the output.
*/
public abstract void printHierarchical(String indent);
}
2. Define the following subclasses of Circuit in individual files:
1. "Resistor", representing a single resistor.
2. "SerialCircuit" that can store any number of circuits in series using ArrayList<Circuit>
3. "ParallelCircuit" that can store any number of circuits in parallel using ArrayList<Circuit>.
3. Fill in the code for these three classes. Make sure to follow the class coding guidelines, and
include a block comment at the top of each one.
4. Write a main program class that will load a circuit and write out the output as defined in the
"specification" section above.
Explanation / Answer
NOTE : To change the "coloring words" into "colors", i tried using colour codes like "#FF0000- Will give you the red color", This worked for me but i cannot say if it will work for you. I am trying other ways also.
By the way thank you for the good question
Rate if you think its worth it
Best Regards
Kobir
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.