Java, some questions about to write the code. Hi, I would like to have more mark
ID: 3891291 • Letter: J
Question
Java, some questions about to write the code.
Hi, I would like to have more marks for these questions compared to my answers.
Any help would be appriciated, Thank you.
Question 3 (File I/O) Total: 20 marks Write a Java class called ReadAndPrintScores that has a main method that opens a file called scores.dat, which contains a series of integers (i.e. scores) that are separated by a blank space. Your program should print the scores read to the console, one on each line. It should also catch and handle a FileNotFoundException by printing the error message to the console in the case where scores.dat is not in the current directory from where your program is run. Question 4 (Class) Total: 20 marks/ Write a public Java class called Point2d that has the following specifications: two private attributes, both decimal, called x and y. three constructors: (i) accepts two arguments and sets x and y to the value of these arguments; (ii) a default constructor that sets both x and y to 0.0; and (iii) a copy constructor that accepts a Point2d object as the only argument. has a pair of accessor and mutator methods for each ofx and y respectively. . a method called distanceFrom that accepts a Point2d object as the only argument, and returns the distance between this object and the Point2d object of the argument (N.B. the distance formula looks like: d I(x2-r). + (y2-y1)' where (x1.y) and (x2.y2) are the two points). a method called distanceFromOrigin that returns the distance between this object and the origin at a toString method that returns a String representation of this object of the form "(x.y)" .Explanation / Answer
Question 3:
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class ReadAndPrintScores{
public static void main(String args[]) {
try {
BufferedReader b;
String line = "";
b = new BufferedReader(new FileReader("data.txt"));
while((line = b.readLine()) != null) {
String[] numbers = line.split(" ");
for(int j = 0; j < numbers.length; j++)
System.out.println(numbers[j]);
}
}
catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Question 4: is a big one. I will update the solution in 30 mins.
**Comment for any further queries.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.