Question

In: Computer Science

You have written a JAVA program that creates Shoe object with three instance variables. You will...

You have written a JAVA program that creates Shoe object with three instance variables. You will need to use the exception you created to go along with it. So far you have been using my driver classes. Now it is time for you to create your own driver class that will implement an ArrayList of Shoe objects.

This assignment uses the Shoe.java and ShoeException.java to create the driver ShoeStore.Java

You will display a menu as follows:

  1. Add shoes
  2. Print all shoes of a given size
  3. Print all shoes of a given color
  4. Print all shoes
  5. End execution

The user will select an option. The program should loop and continue until the user selects 5 -End execution-.

You will be graded as follows

Resubmit your Shoe.java and your ShoeException.java (up to 50 points if properly working)

ShoeStore.java (200 points) this is the driver class

  1. Add shoes (50 points)
  2. Print all shoes of a given size (50 points)
  3. Print all shoes of a given color. Color is a number from 1 to 5,  (50 points)
  4. Print all shoes   (50 points)
  5. End execution

Remember to use try/catch. Your code should not crash at any time.   Code crashing -100 points

The program name should be ShoeStore.java if you use any other name you will get points deducted.

Up to 50 points may be given for following the java coding standards, indentation, comments, usability etc.

Students must always follow the JAVA Java coding standards for the class.

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// Shoe.java

public class Shoe {
   private String brand;
   private int size;
   private int color;

   /**
   * @param brand
   * @param size
   * @param color
   */
   public Shoe(String brand, int size, int color) {
       this.brand = brand;
       this.size = size;
       this.color = color;
   }

   /**
   * @return the brand
   */
   public String getBrand() {
       return brand;
   }

   /**
   * @param brand
   * the brand to set
   */
   public void setBrand(String brand) {
       this.brand = brand;
   }

   /**
   * @return the size
   */
   public int getSize() {
       return size;
   }

   /**
   * @param size
   * the size to set
   */
   public void setSize(int size) {
       this.size = size;
   }

   /**
   * @return the color
   */
   public String getColor() {
       String col = "";
       if (color == 1) {
           col = "red";
       } else if (color == 2) {
           col = "green";
       } else if (color == 3) {
           col = "blue";
       } else if (color == 4) {
           col = "black";
       } else if (color == 5) {
           col = "grey";
       }
       return col;
   }

   /**
   * @param color
   * the color to set
   */
   public void setColor(int color) {
       this.color = color;
   }

   public int getColorNum()
   {
       return color;
   }
   @Override
   public String toString() {
       return "Shoe : Brand :" + brand + ", Size :" + size + ", Color :"+ getColor();
   }
}
_____________________________

// ShoeException.java

public class ShoeException extends Exception {
   private String mesg;

   public ShoeException(String m) {

       setMesg(m);

   }

   /**
   * @return the mesg
   */
   public String getMesg() {
       return mesg;
   }

   /**
   * @param mesg
   * the mesg to set
   */
   public void setMesg(String mesg) {
       this.mesg = mesg;
   }

}
_________________________________

// Driver.java

import java.util.ArrayList;
import java.util.Scanner;

public class Driver {

   public static void main(String[] args) {
       int choice;
       ArrayList<Shoe> arl = new ArrayList<Shoe>();
       /*
       * Creating an Scanner class object which is used to get the inputs
       * entered by the user
       */
       Scanner sc = new Scanner(System.in);
       int size = 0;
       String brand = "";
       int color = 0;
       boolean exit = false;
       final int ASIZE = 3;
       Shoe sh = null;

       while (true) {
           System.out.println("\n1. Add shoes");
           System.out.println("2. Print all shoes of a given size");
           System.out.println("3. Print all shoes of a given color");
           System.out.println("4. Print all shoes");
           System.out.println("5. End execution");
           System.out.print("Enter Choice :");
           choice = sc.nextInt();

           switch (choice) {
           case 1: {
               while (true) {
                   sc.nextLine();
                   System.out.print("Enter shoe brand: ");
                   brand = sc.nextLine();

                   System.out.print("Enter size from 5 to 12: ");
                   size = sc.nextInt();

                   System.out.println("Enter color as a number from 1 to 5: ");
                   System.out.println("1.red\n2.green\n3.blue\n4.black\n5.grey");
                   System.out.print("color: ");
                   color = sc.nextInt();

                   try {
                       if (size < 5 || size > 12) {
                           throw new ShoeException(
                                   "** Size must be between 5-12 **");
                       } else if (color < 1 || color > 5) {
                           throw new ShoeException(
                                   "** Color must be between 1-5 **");
                       } else {
                           sh = new Shoe(brand, size, color);
                           arl.add(sh);
                           break;
                       }

                   } catch (ShoeException se) {
                       System.out.println("Error in creating the shoe");
                       System.out.println(se.getMesg());
                       continue;
                   }
               }

               continue;
           }
           case 2: {
               System.out.print("Enter size of the shoe :");
               size = sc.nextInt();
               for (int i = 0; i < arl.size(); i++) {
                   if (arl.get(i).getSize() == size) {
                       System.out.println(arl.get(i));
                   }
               }
               continue;
           }
           case 3: {
               System.out.print("Enter Color Number between 1-5 :");
               color = sc.nextInt();
               for (int i = 0; i < arl.size(); i++) {
                   if (arl.get(i).getColorNum() == color) {
                       System.out.println(arl.get(i));
                   }
               }
               continue;
           }
           case 4: {
               System.out.println("Displaying all Shoes :");
               for (int i = 0; i < arl.size(); i++) {

                   System.out.println(arl.get(i));

               }
               continue;
           }
           case 5: {
              
               break;
           }
           default: {
               System.out.println("** Invalid Choice **");
           }

           }

           break;
       }

   }

}
________________________________

Output:


1. Add shoes
2. Print all shoes of a given size
3. Print all shoes of a given color
4. Print all shoes
5. End execution
Enter Choice :1
Enter shoe brand: Nike
Enter size from 5 to 12: 3
Enter color as a number from 1 to 5:
1.red
2.green
3.blue
4.black
5.grey
color: 3
Error in creating the shoe
** Size must be between 5-12 **
Enter shoe brand: Nike
Enter size from 5 to 12: 7
Enter color as a number from 1 to 5:
1.red
2.green
3.blue
4.black
5.grey
color: 2

1. Add shoes
2. Print all shoes of a given size
3. Print all shoes of a given color
4. Print all shoes
5. End execution
Enter Choice :1
Enter shoe brand: Ajio
Enter size from 5 to 12: 8
Enter color as a number from 1 to 5:
1.red
2.green
3.blue
4.black
5.grey
color: 1

1. Add shoes
2. Print all shoes of a given size
3. Print all shoes of a given color
4. Print all shoes
5. End execution
Enter Choice :1
Enter shoe brand: LeeCooper
Enter size from 5 to 12: 8
Enter color as a number from 1 to 5:
1.red
2.green
3.blue
4.black
5.grey
color: 2

1. Add shoes
2. Print all shoes of a given size
3. Print all shoes of a given color
4. Print all shoes
5. End execution
Enter Choice :1
Enter shoe brand: WestSport
Enter size from 5 to 12: 7
Enter color as a number from 1 to 5:
1.red
2.green
3.blue
4.black
5.grey
color: 1

1. Add shoes
2. Print all shoes of a given size
3. Print all shoes of a given color
4. Print all shoes
5. End execution
Enter Choice :2
Enter size of the shoe :7
Shoe : Brand :Nike, Size :7, Color :green
Shoe : Brand :WestSport, Size :7, Color :red

1. Add shoes
2. Print all shoes of a given size
3. Print all shoes of a given color
4. Print all shoes
5. End execution
Enter Choice :3
Enter Color Number between 1-5 :1
Shoe : Brand :Ajio, Size :8, Color :red
Shoe : Brand :WestSport, Size :7, Color :red

1. Add shoes
2. Print all shoes of a given size
3. Print all shoes of a given color
4. Print all shoes
5. End execution
Enter Choice :4
Displaying all Shoes :
Shoe : Brand :Nike, Size :7, Color :green
Shoe : Brand :Ajio, Size :8, Color :red
Shoe : Brand :LeeCooper, Size :8, Color :green
Shoe : Brand :WestSport, Size :7, Color :red

1. Add shoes
2. Print all shoes of a given size
3. Print all shoes of a given color
4. Print all shoes
5. End execution
Enter Choice :5

_______________Could you plz rate me well.Thank You


Related Solutions

Purpose: To write an Object-Oriented application that creates a Java class with several instance variables, a...
Purpose: To write an Object-Oriented application that creates a Java class with several instance variables, a constructor to initialize the instance variables, several methods to access and update the instance variables’ values, along with other methods to perform calculations. Also, write a test class that instantiates the first class and tests the class’s constructor and methods. Details: Create a class called Rectangle containing the following: Two instance variables, An instance variable of type double used to hold the rectangle’s width....
Java - Write a test program that creates an Account object with an account number of...
Java - Write a test program that creates an Account object with an account number of AC1111, a balance of $25,000, and an annual interest rate of 3.5. Use the withdraw method to withdraw $3,500, use the deposit method to deposit $3,500, and print the balance, the monthly interest, and the date when this account was created.
JAVA - Write a program that creates an ArrayList and adds an Account object, a Date...
JAVA - Write a program that creates an ArrayList and adds an Account object, a Date object, a ClockWithAudio object, a BMI object, a Day object, and a FigurePane object. Then display all elements in the list. Assume that all classes (i.e. Date, Account, etc.) have their own no-argument constructor.
You need to make an AngryBear class.(In java) The AngryBear class must have 2 instance variables....
You need to make an AngryBear class.(In java) The AngryBear class must have 2 instance variables. The first instance variable will store the days the bear has been awake. The second instance variable will store the number of teeth for the bear. The AngryBear class will have 1 constructor that takes in values for days awake and number of teeth. The AngryBear class will have one method isAngry(); An AngryBear is angry if it has been awake for more than...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name (type String), a last name (type String) and a monthly salary (double). Provide a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value. Write a test app names EmployeeTest that demonstrates class EMLOYEE’s capabilities. Create two EMPLOYEE objects and display each object’s yearly...
Create a Java class named Trivia that contains three instance variables, question of type String that...
Create a Java class named Trivia that contains three instance variables, question of type String that stores the question of the trivia, answer of type String that stores the answer to the question, and points of type integer that stores the points’ value between 1 and 3 based on the difficulty of the question. Also create the following methods: getQuestion( ) – it will return the question. getAnswer( ) – it will return the answer. getPoints( ) – it will...
Write a program (in C, or Java, or C++, or C#) that creates three new threads...
Write a program (in C, or Java, or C++, or C#) that creates three new threads (besides the already existing main thread) and synchronizes them in such a way that each thread displays it's thread id in turn for 5 iterations. The output of the program should look like this: Thread 1 - iteration no. 1 Thread 2 - iteration no. 1 Thread 3 - iteration no. 1 Thread 1 - iteration no. 2 Thread 2 - iteration no. 2...
(java) Write a class called CoinFlip. The class should have two instance variables: an int named...
(java) Write a class called CoinFlip. The class should have two instance variables: an int named coin and an object of the class Random called r. Coin will have a value of 0 or 1 (corresponding to heads or tails respectively). The constructor should take a single parameter, an int that indicates whether the coin is currently heads (0) or tails (1). There is no need to error check the input. The constructor should initialize the coin instance variable to...
Program should be written in Java b) The computer program should prompt the user (You are...
Program should be written in Java b) The computer program should prompt the user (You are the user) to enter the answers to the following questions: What is your city of birth? What is your favorite sport? If you could live anywhere in the world, where would you like to live? What is your dream vacation? Take this information and create a short paragraph about the user and output this paragraph. You may use the Scanner class and the System.out...
Problem 3 Prototype object doubleQ A doubleQ object has 2 instance variables: firstQ and secondQ arrays...
Problem 3 Prototype object doubleQ A doubleQ object has 2 instance variables: firstQ and secondQ arrays that together implement a queue enqueue() instance method adds its argument to the end of this.secondQ dequeue() instance method removes and returns the element at the front of this.firstQ transfer() instance method removes the element from the front of this.secondQ, adds it to the end of this.firstQ If this.secondQ is empty, does nothing Test code is included in the file Download this file (with...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT