I am taking java for a course at school and my assignment is to write my code including the PrintWriter option and make it save to another file. I have written the code, it is running with no errors, but when it is all complete, the code is not being saved to the designated file. Any help is appreciated! Thanks in advance!
// allows message box to pop up
import javax.swing.JOptionPane;
// allows the use of random number generator
import java.util.Random;
// allows the print writer and the IO Exception
import java.io.*;
class PetFinal {
public static void main(String[] args) throws IOException
{
PrintWriter pet = new PrintWriter("I:\ComClasses\2013SP\gcharles\COM-152-SAS03\rchristensen\Assignment.txt");
// declaring the names for the integers in the loops
// random generator int to store the value
int rantimes;
// code for random number generator
Random randomnumbers = new Random();
// string for first user input loop
String timesstr;
// int for the user input loop
int times;
PetFinalTest p = new PetFinalTest();
// telling the code where to get the type, name, and age from
p.setType(JOptionPane.showInputDialog("What type of pet do you have?"));
// get pets name
p.setName(JOptionPane.showInputDialog("What is your pets name?"));
// Receive the pets age
p.setAge(JOptionPane.showInputDialog("How old is your pet?"));
// how many times the pet should be moving
timesstr =(JOptionPane.showInputDialog("How many times do you want " + p.getName() + " to be " + p.getMove()));
times =Integer.parseInt(timesstr);
//Output to the user telling them their pets name, type, and age
pet.println("My pet is a " + p.getType());
pet.println("The name of your pet is " + p.getName());
pet.println("He is " + p.getAge() + " years old");
pet.println("Your pet will move " + times + " times");
pet.println(p.getSound());
pet.println(p.getsit());
rantimes = randomnumbers.nextInt(10) + 1 ;
// loop controlled by user
do
{
pet.println(p.getMove());
// counts down to 0 so we do not have an infinite loop
times --;
}
while (times > 0);// stops at 0
pet.println("Your pet will move " + rantimes + " times");
// random number generator loop
do
{
pet.println(p.getMove());
rantimes = rantimes - 1;
}
while (rantimes > 0);
pet.close();
}
}