Question
Answer the following questions using the Position class: public class Position { private int x; private int y; public int getX() { return x; }
Answer the following questions using the Position class:
public class Position
{
private int x;
private int y;
public int getX() { return x; }
public void setX(int x) { this.x = x; }
public int getY() { return y; }
public void setY(int y) { this.y = y; }
}
a). Write a statement that opens file in.txt for input. Use Scanner variable inFile.
b). Write a statement that opens file out.txt for output. Use Formatter variable outFile.
c). Write the statements needed to read a record from the in.txt (opened in question 11). Use the data to create an object of class Position. Each record contains 2 integers one for x and one for y
d). Write the statements needed to write a record to out.txt (opened in question 12). Use the data stored in a Position object named p.
e). Write a statement that opens file in.txt for input. Use ObjectInputStream variable inFile2 to wrap an InputStream object.
f). Write a statement that opens file out.txt for output. Use ObjectOutputStream variable outFile2 to wrap an OutputStream object.
g). Write the statements needed to read a record from the in.txt (opened in question 15). Use the data to create an object of class Position.
h). Write the statements needed to write a record to out.txt (opened in question 16). Use the data stored in a Position object named p.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started