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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!