Assignemnt #121 and HighScore
Code
///Name: Daniel Tiffany-Appleton
///Period: 7
///Program Name: High Score
///File Name: HighScore
///Date Finished: 3/25/16
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class HighScore
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
PrintWriter fileOut;
String name;
int score;
System.out.println(" ");
System.out.println("You got a high score!!!!");
System.out.print("Please enter your score: ");
score = keyboard.nextInt();
System.out.print("Please enter your name: ");
name = keyboard.next();
System.out.println("Data stored into score.txt. Thank you, play again.");
System.out.println(" ");
try
{
fileOut = new PrintWriter("score.txt");
}
catch(IOException e)
{
System.out.println("Sorry, I can't open the file 'score.txt' for editing.");
System.out.println("Maybe the file exists and is read-only?");
fileOut = null;
System.exit(1);
}
fileOut.println("+-------------------------------------+");
fileOut.println("| High Score |");
fileOut.println("| |");
fileOut.println("| NAME: " + name + " |");
fileOut.println("| |");
fileOut.println("| SCORE: " + score + " |");
fileOut.println("| |");
fileOut.println("| |");
fileOut.println("| |");
fileOut.println("| |");
fileOut.println("+-------------------------------------+");
fileOut.close();
}
}
Picture of the output