ECE 538 Assignment 3

Your submission should follow our general guidelines. Include a master index.html (in our standard format) that contains or links to all the problems. Use source-highlighting to display your code. Include source-code files and any required images.

  1. Write a program (you may use FileCopy.java as a model to read a textfile and generate an html file with < converted to &lt;, > converted to &gt; and & converted to &amp; Enclose the output in <pre> tags.
  2. Modify your resistance program from the last assignment to accept a single string from the console (stdin) or from JOptionPane. Use the String.split function to parse an input string such as “R1 1000 R2 2000 R3 2000” into an array of Strings, and then create the corresponding resistor objects. You should consider generating an appropriate Resistor constructor. See Parsing Strings with split for examples.
  3. The Java Tutorial on try-with-resources has an example writeToFileZipFileContents. Put that example into a Java program and demonstrate it with some zip file.
  4. Use the Jama package to solve the matrix equation A x = b where A = [3 -1 0; 4 2 1; -3 2 4]; in MATLAB notaton and b = [1.8; 1.6; -1.3];
  5. In the last assignment, you developed a Java class to represent a resistor. Design similar classes for capacitors and inductors. Create a base class object from which all three classes (R, C, and L) inherit.
  6. Write a program to calculate the greatest common divisor of two integers. This is used to reduce fractions such as 14/42 to standard form (i.e., 1/3). You can use Euclid's algorithm from rational.java. Put a debug print statement in the while loop to show intermediate values in the process.
  7. Write a class to represent a rational number. You may use rational.java as a starting point. Use int instead of long and static functions like static public Rational add(Rational a, Rational b) for operations instead of (or in addition to) member functions. Incorporate and demonstrate the following capabilities:
    1. System.out.println(" a = " + a); should work if a is a Rational object.
    2. a member function String latex() that outputs the LaTex representation of the object. You can use this in MATLAB documentation. See rational.m, which results in the following MATLAB document.
    3. a member function void draw(Graphics g, int x, int y) which generates a rational number on the screen centered at location (x, y), that looks like 1/4.

    Reference

    Michael J. Laszlo, Object-Oriented Programming featuring Graphical Applications in JAVA
    Addison-Wesley, 2002. ISBN 0-201-72627-0. Pages 161-169.


Maintained by John Loomis, last updated 6 February 2017