o
Quadrilateral
) (Approval)(x1, y1) (point 1) (x2, y2) (point 2) ______________________ \ / \ / \________________/ (x4, y4) (point 4) (x3, y3) (point 3)
(Note the order of the points; that is the order in which they are input)
The class should contain the following:
Point
instance variables corresponding to the four points displayed above
liesInOneQuadrant
, that returns true if the quadrilateral is completely contained within
a single quadrant (i.e., all four points are inthe sme quadrant).
isParallelogram
: returns true of the quadrilateral is a parallelogram, i.e., opposite sides are equal
isRhombus
: returns true if the quadrilateral is a rhombus, i.e., all four sides are equal
toString
it should be the concatenation of the toString
of the four Point
instance variables
in the proper order.
I've supplied the Line
and Point
classes (both as source and class files; you might want to experiment with your IDE in how to add .class
files
to your project.
Point
s
Line
s
Point
objects (we discussed this in class).
Point
s.
Point
class … you have that from your instance variables
isRhombus
amd isParallelogram
methods require the length of the various sides, and length is a method of
the Line
class. You have a couple of options to get that from your four Point
instance variables:
side1
of type line
, side2
, etc (you can initialize them in the constructor
together with the four Point
instance variables (not recommended, don't need the Line
objects as instance variables; it's redundant.
Line
objects) in the above two method (i.e., when and where you need them).
length
method on the sides under being looked at.
isParallelogram
could also be defined by leveraging Line
's slope
method but would either fail, or require
special logic for the case of vetical sides (which have undefined slope). (After you get your class working, you might want to try using slope instead; it may give you
a chance to become a bit familiar with Java's NaN
(not-a-number) value.)
QuadrilateralApp
) (Approval)quadrilateral.data
1 1 2 1 2 2 1 2 1 -1 1 1 -2 1 -2 -1 0 0 1 0 1 1 0 2Sample Test Run
Here is a sample execution of the program. User input is in bold. Your program should replicate the prompts and output:
stdout
(1, 1) - (2, 1) / (2, 2) - (1, 2) (1, 1) Quadrant: Quadrant 1 (1) (2, 1) Quadrant: Quadrant 1 (1) (2, 2) Quadrant: Quadrant 1 (1) (1, 2) Quadrant: Quadrant 1 (1) Quadrilateral lies in one quadrant: true Rhombus (1, -1) - (1, 1) / (-2, 1) - (-2, -1) (1, -1) Quadrant: Quadrant 4 (4) (1, 1) Quadrant: Quadrant 1 (1) (-2, 1) Quadrant: Quadrant 2 (2) (-2, -1) Quadrant: Quadrant 3 (3) Quadrilateral lies in one quadrant: false Parallelogram (0, 0) - (1, 0) / (1, 1) - (0, 2) (0, 0) Quadrant: Origin (0) (1, 0) Quadrant: Positive x axis (5) (1, 1) Quadrant: Quadrant 1 (1) (0, 2) Quadrant: Positive y axis (6) Quadrilateral lies in one quadrant: false Simple quadrilateral
Line
s or Point
s
Phonebook
) (Approval)Phonebook
)last-name first-name phone-number
PhonebookApp
) (Approval)PhonebookEntry
class source file as well the Phonebook
file).
last-name first-name phone-number
sorted.text
stdin
l Arnow David r 456-789-0123 l Weiss Jerrold l Weiss Gerald r 111-123-4567 q
phonebook.text
Arnow David 123-456-7890 Harrow Keith 234-567-8901 Jones Jackie 345-678-9012 Augenstein Moshe 456-789-0123 Sokol Dina 567-890-1234 Tenenbaum Aaron 678-901-2345 Weiss Gerald 789-012-3456 Cox Jim 890-123-4567 Langsam Yedidyah 901-234-5678 Thurm Joseph 012-345-6789Sample Test Run
Here is a sample execution of the program. User input is in bold. Your program should replicate the prompts and output:
stdout
lookup, reverse-lookup, quit (l/r/q)? last name? first name? David Arnow's phone number is 123-456-7890 lookup, reverse-lookup, quit (l/r/q)? phone number (nnn-nnn-nnnn)? 456-789-0123 belongs to Augenstein, Moshe lookup, reverse-lookup, quit (l/r/q)? last name? first name? -- Name not found lookup, reverse-lookup, quit (l/r/q)? last name? first name? Gerald Weiss's phone number is 789-012-3456 lookup, reverse-lookup, quit (l/r/q)? phone number (nnn-nnn-nnnn)? -- Phone number not found lookup, reverse-lookup, quit (l/r/q)? 3 lookups performed 2 reverse lookups performedsorted.text
Arnow David 123-456-7890 Augenstein Moshe 456-789-0123 Cox Jim 890-123-4567 Harrow Keith 234-567-8901 Jones Jackie 345-678-9012 Langsam Yedidyah 901-234-5678 Sokol Dina 567-890-1234 Tenenbaum Aaron 678-901-2345 Thurm Joseph 012-345-6789 Weiss Gerald 789-012-3456
Container
) (Approval)Container
class from Lecture 2:
String
contains
: similar to find
except this method returns true
/false
instead of the position. You should assume the availability of find
and NOT repeat the search logic.
(See the note in explanation below).
set
: this method accepts an index and value, and assigns the value to the location specified by the index. For example:
set(values, size, 10, 14);assigns
14
to location 10
in the array.
set
is the counterpart to get
: the former returns the value at a location
in the container; the latter assigns (overwrites) an element in the container.
input file
A dog A cat F cat F cow F dog C cat C cow G 1 G 0 S 1 cow F cow F catSample Test Run
Here is a sample execution of the program. User input is in bold. Your program should replicate the prompts and output:
stdout
After adding dog: {dog} After adding cat: {dog, cat} cat is at position 1 of the container cow is not in the container dog is at position 0 of the container cat is in the container cow is not in the container The value at location 1 is cat The value at location 0 is dog After setting position 1 to cow: {dog, cow} cow is at position 1 of the container cat is not in the container
contains
using find
(as opposed to
recoding the search logic, or don't even understand what you're being asked to do, go look at my Lecture 12
(Techniques III) notes -- look for (Linear) Searching an Array; it shows you what I want. (But please
give it some thought first.
ContainerApp
))
CAPACITY
)
toString
find
to get this()
construct in constructors.
int
type provides the
same operations, and in a much more intuitive fashion. We introduce them for several reasons:
ImmutableInt
) (Approval)Immutable
, modelling integers, with the following state/behavior:
ImmutableInt add(ImmutableInt immutableInt)
ImmutableInt sub(ImmutableInt immutableInt)
ImmutableInt mul(ImmutableInt immutableInt)
ImmutableInt div(ImmutableInt immutableInt)
toString()
int
instance variable maintaining the integer value of the object
this(…)
construct)
div
… ImmutableInt i1 = new ImmutableInt(10); System.out.println("i1: " + i1); … System.out.println("i1.add(i2): " + i1.add(i2); …
stdout
i1: 10 i2: 20 i3: 0 i1.add(i2): 30 i1.sub(i2): -10 i1.mul(i2): 200 i1.div(i2): 0 i1: 10 i2: 20 i3: 0
ImmutableIntApp
) (Approval)
MutableInt
) (Approval)MutableInt
, modelling integers,with the following state/behavior:
MutableInt increaseBy(MutableInt immutableInt)
MutableInt decreaseBy(MutableInt immutableInt)
MutableInt multiplyBy(MutableInt immutableInt)
MutableInt divideBy(MutableInt immutableInt)
MutableInt reset()
toString()
int
instance variable maintaining the integer value of the object
this(…)
construct)
reset
sets the internal state variable to 0
divideBy
… MutableInt i0 = new MutableInt(); System.out.println("i0: " + i0); … System.out.println("i0.increaseBy(i1): " + i0.increaseBy(i1); …
stdout
===== Initial Values ===== i0: 0 i1: 10 i2: 5 i3: 20 i4: 25 i0.increaseBy(i1): 10 i0: 10 i1: 10 i2: 5 i3: 20 i4: 25 i0.decreaseBy(i2): 5 i0: 5 i1: 10 i2: 5 i3: 20 i4: 25 i0.multiplyBy(i3): 100 i0: 100 i1: 10 i2: 5 i3: 20 i4: 25 i0.divideBy(i4): 4 i0: 4 i1: 10 i2: 5 i3: 20 i4: 25 i0.reset(): 0 i0: 0 ===== Chaining ===== i0.increaseBy(i1).decreaseBy(i2).multiplyBy(i3).divideBy(i4): 4 i0: 4 i1: 10 i2: 5 i3: 20 i4: 25
ImmutableIntApp
) (Approval)