CISC 3115 Final Exam
August 18, 2025
Name:
120 minutes, 100 points. Closed notes, closed computer, etc. Do not leave the room while
taking the ezam.
Question 1 (5 points)
Note: each part of this question is a continuation of the previous parts.
(a) Suppose we using the Linux command line, working in a newly-created directory. We
write a program consisting of a class named P in a file named P.java. The program,
which contains no errors, is designed to read some data from standard input (the
keyboard) and to print some data to standard output (the screen).
Write the command to compile (but not run) the program.
(b) Write what is printed on the screen if we now enter the 1s command.
(c) Suppose we now create two additional files, named in.txt and out.txt, in the current
directory.
Write the command to run the program, arranging matters so that the program’s input
comes from in.txt and the program’s output goes to out.txt.
(d) Write the command to make a copy of in.txt, naming the copy copy.txt.
(e) Write the command to move copy.txt to the parent of the current directory.
,Question 2 (6 points)
Suppose we have the following Point class.
public class Point {
private int x, y;
public Point(int x, int y) {
this.x = x;
this.y Yy
}
public Point(Point original) {
this.x = original.x;
this.y = original.y;
}
public void setX(int x) { this.x = x; }
public void setY(int y) { this.y = y; }
@Override
public String toString() { return "(" + x + ey o+ )N}
Write the output of each of the following programs.
(a) public class PointClientl {
public static void main(String[] args) {
Point pl = new Point (1, 2);
Point p2 = pi;
Point p3 = new Point(1l, 2);
System.out.println(pl == p2);
System.out.println(pl == p3);
System.out.println(pl.equals(p2));
System.out.println(pl.equals(p3));
}
Hint: here’s the equals method as written in the Object class:
public boolean equals(Object obj) {
return (this == obj);
b
, (b) public class PointClient2 {
public static void main(String[] args) {
Point p = new Point(1, 2);
mi(p);
System.out.println("after mi: " + p);
m2(p);
System.out.println("after m2: " + p);
}
private static void mi(Point p) {
p = new Point(3, 4);
System.out.println("in mi: " + p);
}
private static void m2(Point p) {
p.setX(5);
System.out.println("in m2: " + p);
(c) public class PointClient3 {
public static void main(String[] args) {
Point pl = new Point (1, 2);
Point p2 = pi;
pl.setX(3);
System.out.println(p2);
p2.setY (4);
System.out.println(pl);
August 18, 2025
Name:
120 minutes, 100 points. Closed notes, closed computer, etc. Do not leave the room while
taking the ezam.
Question 1 (5 points)
Note: each part of this question is a continuation of the previous parts.
(a) Suppose we using the Linux command line, working in a newly-created directory. We
write a program consisting of a class named P in a file named P.java. The program,
which contains no errors, is designed to read some data from standard input (the
keyboard) and to print some data to standard output (the screen).
Write the command to compile (but not run) the program.
(b) Write what is printed on the screen if we now enter the 1s command.
(c) Suppose we now create two additional files, named in.txt and out.txt, in the current
directory.
Write the command to run the program, arranging matters so that the program’s input
comes from in.txt and the program’s output goes to out.txt.
(d) Write the command to make a copy of in.txt, naming the copy copy.txt.
(e) Write the command to move copy.txt to the parent of the current directory.
,Question 2 (6 points)
Suppose we have the following Point class.
public class Point {
private int x, y;
public Point(int x, int y) {
this.x = x;
this.y Yy
}
public Point(Point original) {
this.x = original.x;
this.y = original.y;
}
public void setX(int x) { this.x = x; }
public void setY(int y) { this.y = y; }
@Override
public String toString() { return "(" + x + ey o+ )N}
Write the output of each of the following programs.
(a) public class PointClientl {
public static void main(String[] args) {
Point pl = new Point (1, 2);
Point p2 = pi;
Point p3 = new Point(1l, 2);
System.out.println(pl == p2);
System.out.println(pl == p3);
System.out.println(pl.equals(p2));
System.out.println(pl.equals(p3));
}
Hint: here’s the equals method as written in the Object class:
public boolean equals(Object obj) {
return (this == obj);
b
, (b) public class PointClient2 {
public static void main(String[] args) {
Point p = new Point(1, 2);
mi(p);
System.out.println("after mi: " + p);
m2(p);
System.out.println("after m2: " + p);
}
private static void mi(Point p) {
p = new Point(3, 4);
System.out.println("in mi: " + p);
}
private static void m2(Point p) {
p.setX(5);
System.out.println("in m2: " + p);
(c) public class PointClient3 {
public static void main(String[] args) {
Point pl = new Point (1, 2);
Point p2 = pi;
pl.setX(3);
System.out.println(p2);
p2.setY (4);
System.out.println(pl);