aboutme.txt
with the following information:
Your name: Your student ID: Your major: Your preferred email address: Check one: [ ] Undergraduate, [ ] Graduate, [ ] Open university Repeating the class? [ ] Yes, [ ] No Semester, instructor, and grade of your CS151 prerequisite: Time it took you to answer the question below: Did you ask anyone for help? [ ] Yes, [ ] No If adding: [ ] Section 3, [ ] Section 4, [ ] Either
hw1
, i.e. the files aboutme.txt
, Op.java
, Product.java
, Read.java
, and ExprTest2.java
. Make sure these files do not have package declarations. cayhorstmann
.CS152 Repoand the URL to your repo in the body of your message. Also be sure that I can tell who you are from your email. Ever so often, I get an email where the sender is identified as something like GandalfTheUltimate or WildWeasel1989. That's not the professional presentation that we want to see from our graduates. If in doubt, use your SJSU email.
cd /tmp git clone your repo studentrepo cd studentrepo/hw1 for f in Expr Const Function Sum Rand ExprTest ; do curl -O http://horstmann.com/sjsu/spring2018/cs152/hw1/$f.java ; done javac -cp .:path to JUnit4/\* -Xlint:unchecked *.java java -cp .:path to JUnit4/\* org.junit.runner.JUnitCore ExprTestMake sure that you pass all five tests.
hw1/screenshot.png
. (If you use the Lubuntu VM, you can run the scrot
command to get a screen shot.)Important: If you are currently enrolled in the class, you must turn in a complete or partial solution to this assignment by the deadline, or you may be dropped from the class. If you are trying to add the class, you will receive an add code after you have turned in the assignment and space becomes available.
You are given an interface Expr
to evaluate expressions, a class Const
that produces constant expressions, a class Rand
that produces random integers, and an interface Function
that defines a function with parameters and return value of type T
.
Op
that evaluates expressions of the form f(e1, ..., en):
public class Op<T> . . . { . . . @SafeVarargs public Op(Function<T> fun, Expr<T>... args) { . . . } . . . }An
Op<T>
is an Expr<T>
(because it can be evaluated) and has Expr<T>
(the arguments). Use the Composite design pattern. To evaluate the expression, invoke the function with a list of the arguments.Op
class is intended to be a superclass for operators such as Sum
and
public class Product . . . { @SafeVarargs public Product(Expr<Integer>... args) { . . . } }Implement
Product
without using streams. (Don't follow the implementation of Sum
.)Read
that reads a single integer from standard input. You don't have to implement error handling.
import java.util.Scanner; public class Read implements Expr<Integer> { private static Scanner in = new Scanner(System.in); . . . }
ExprTest2
with at least three new test cases.