Assignment 121; HighScore
Code
// Donovan Rich
// Period 6
// High Score
// HighScore.java
// 6/6/2016
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class HighScore {
public static void main(String[] args) {
PrintWriter fileOut;
Scanner keyboard = new Scanner(System.in);
System.out.print("Congratulations! Your score was high enough to land you on the leaderboard!");
System.out.println("Your score: " );
int score = keyboard.nextInt();
System.out.println("Your initial: " );
String name = keyboard.next();
try{
fileOut = new PrintWriter("highscore.txt");
} catch(IOException e) {
System.out.println("Sorry, I can't open the file 'highschool.txt' for editing.");
System.out.println("Maybe the file exists and is read-only?");
fileOut = null;
System.exit(1);
}
fileOut.println( "Player " + name );
fileOut.println( "Score: " + score );
fileOut.close();
}
}
Picture of the output