In: Computer Science
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:
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
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.
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