QuestionQuestion

Create a program that instantiates at least one Pet object.
Every time the program is opened, the status of the Pet is assessed and output to the console.
The user should be given options in handling their Pet (i.e. naming it, feeding it, grooming it, etc.).
You will be graded on the following:
- does the pet object and its properties persist on subsequent loads?
- do the actions the user takes change the pet's properties?
- is your program user friendly (clear instruction, error handling, etc.)?
Java allows you to serialize objects fairly easily as long as you plan ahead.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

public class Driver {

    public static void main(String[] args) {
       Pet pet = readFile();
       Scanner scanner = new Scanner(System.in);
       if (pet == null) {
            System.out.println("Create your new pet");
            System.out.print("Enter its name: ");
            String name = scanner.nextLine();
            pet = new Pet(name);
       }
       System.out.printf("One day of the virtual world is %.2f seconds in the real world%n",
                (double)Pet.PERIOD / 1000.0);
       String[] task = pet.getGrommingTasks();
       System.out.println("Current status of your "
                + pet.getName());
       System.out.println(pet.toString());
       int index;
       do {
            System.out.println("What do you want to do to your "
                   + pet.getName());
            for (int i = 0; i < task.length; i++) {
                System.out.printf("%d %s%n", i, task[i]);
            }
            System.out.printf("%d %s%n", task.length, "Nothing");
            System.out.print("Enter the index: ");
            try {
                index = Integer.parseInt(scanner.nextLine());
                if (index != task.length) {
                   pet.gromming(index);
                }
            } catch (Exception e) {
                System.err.println("Invalid input");
            }
            
            System.out.println("Current status of your "
                   + pet.getName());
            System.out.println(pet.toString());
            
            System.out.println("Do you want to continue? "
                   + " yes : 1 ; no : other number ");
            try {
                index = Integer.parseInt(scanner.nextLine());
            } catch (Exception e) {
                index = 0;
            }
       } while (index == 1);
       saveFile(pet);
    }...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

50% discount

Hours
Minutes
Seconds
$30.00 $15.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats