- Make sure you are in Workspace not QuizSpace
- Create a project called L8 in Eclipse.
- Create a class called L8 in the project L8 with a main method.
- Copy the L8.java file from the Progress tab
into the L8 project source (~/workspace/L8/src).
- Copy the data.txt file from the Progress tab
into the L8 project (~/workspace/L8).
- Write the rest of your code in the main method, below the code shown.
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
public class L8 {
public static void main(String[] args) {
// Declare variables
int int0=0, int1=0;
double real0=0.0, real1=0.0;
char char0=' ', char1=' ', char2=' ';
String string0="", string1="", string2="";
try {
// Open input stream
Scanner scan = new Scanner(new File("data.txt"));
// Read contents
string0 = scan.nextLine();
string1 = scan.nextLine();
string2 = scan.nextLine();
char0 = scan.next().charAt(0);
char1 = scan.next().charAt(0);
char2 = scan.next().charAt(0);
int0 = scan.nextInt();
int1 = scan.nextInt();
real0 = scan.nextDouble();
real1 = scan.nextDouble();
// Close input stream
scan.close();
} catch (IOException e) {
System.out.println("Cannot read file: data.txt");
System.exit(0);
}
// PUT CODE HERE!
}
}
- We are going to kind of treat this like a programming quiz, except the TA will actually answer your questions!
- You may edit the data file to test with different values.
- Make sure your L8.java compiles and produces exactly 9 lines of output.
- Show your lab to the TA for credit, as usual.