Question

You will write a class called Shoe.java Shoe.java should have Three instance variables String brand (cannot...

You will write a class called Shoe.java

Shoe.java should have

Three instance variables

  • String brand (cannot be blank)
  • double size (from 5 to 12)
  • int color (a number from 1 to 5 representing one of 5 colors) This code is to control the amount of colors. the colors represented are as follows
    • 1. red
    • 2. green
    • 3. blue
    • 4. black
    • 5. grey

One constructor, one get method per instance variable, one set method per instance variable. You will need a toString method that will return a string with the shoe information.

  • Total for this class is 170 points + style 30 points = 200 points
  • constructor (25 points)
  • Each set method is 20 points
  • setBrand
  • setSize
  • setColor <--- uses an integer to set the color, must be like this: private void setColor(int color)
  • Each get Method is 20
  • getBrand
  • getSize
  • getColor <--- even when the color is a number the getColor may return a string or a number. Any way you decide to do it it should run properly with my code and with any other code that may use this class
  • The toString method is 25 points
  • toString <-- should spell the color. It should not print the color number.

Keep in mind that in order for this to work you will need to create ShoeException.java as well.

ShoeException.java

Total points for this class is 60 for the methods + 20 for style for a total of 80 points

  • constructor (20 points)
  • setMessage (20 points)
  • getMessage (20 points)

The code below can be used to test that your class works well. Copy and paste it into JGrasp in a file to be named ShoeStore.java The code below should run with your code. I have tested it with my own homework code and it works well. the last 40 points will be earned depending on how well your code interacts with the given code below.

import java.util.*;
public class ShoeStore{

   public static void main(String arg[ ]) throws Exception{

      Scanner sc = new Scanner(System.in);
      double size=0;
      String brand = "";
      int color=0;
      boolean exit = false;
      final int ASIZE = 3;
      Shoe sh = null;
    
      try{
         System.out.print("Enter shoe brand: ");
         brand = sc.nextLine( );
         sc = new Scanner(System.in); //resetting the scanner
         System.out.println();
         System.out.print("Enter size from 5 to 12: ");
         size = sc.nextDouble( );
         sc = new Scanner(System.in);
         System.out.println();
         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( );
         sc = new Scanner(System.in);
         System.out.println( );
         try{
            sh = new Shoe(brand, size, color);
         }
         catch(ShoeException se){
            System.out.println("Error in creating the shoe");
            System.out.println(se.getMessage( ));
            sc = new Scanner(System.in); //resetting the scanner
         }
      } //ends inner try
      catch(InputMismatchException ime){
         System.out.println("you did not enter a number for either size or color");
         sc = new Scanner(System.in);
      }
      System.out.println(sh.toString( ));
   } //main method
}   //class

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any problem with the code feel free to comment.

Program

import java.util.InputMismatchException;
import java.util.Scanner;

//exception class
class ShoeException extends Exception {
   private String message;

   //constructor
   public ShoeException(String message) {
       super(message);
       this.message = message;
   }

   //getters and setters
   public String getMessage() {
       return message;
   }

   public void setMessage(String message) {
       this.message = message;
   }
}

class Shoe {
   //instance variables
   private String brand;
   private double size;
   private int color;

   //constructor
   public Shoe(String brand, double size, int color) throws ShoeException {
       this.brand = brand;
       setSize(size);
       setColor(color);;
   }

   //all getters and setters
   public String getBrand() {
       return brand;
   }

   public void setBrand(String brand) {
       this.brand = brand;
   }

   public double getSize() {
       return size;
   }

   public void setSize(double size) throws ShoeException {
      
       if(size>=5 && size<=12 )
       this.size = size;
       else
           throw new ShoeException("Improper Size");//size exception
   }

   public String getColor() {
       switch (color) {
       case 1:
           return "red";
       case 2:
           return "green";
       case 3:
           return "blue";
       case 4:
           return "black";
       case 5:
           return "grey";
       }
       return "";
   }

   public void setColor(int color) throws ShoeException {
       switch (color) {
       case 1:
       case 2:
       case 3:
       case 4:
       case 5:
           this.color = color;
           break;
       default:
           throw new ShoeException("Improper color code");//color exceptions
       }
   }

   @Override
   public String toString() {
       return "Shoe [brand=" + brand + ", size=" + size + ", color=" + getColor() + "]";
   }

}

public class Test {//driver class for testing
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
   double size=0;
   String brand = "";
   int color=0;
   boolean exit = false;
   final int ASIZE = 3;
   Shoe sh = null;
  
   try{
   System.out.print("Enter shoe brand: ");
   brand = sc.nextLine( );
   sc = new Scanner(System.in); //resetting the scanner
   System.out.println();
   System.out.print("Enter size from 5 to 12: ");
   size = sc.nextDouble( );
   sc = new Scanner(System.in);
   System.out.println();
   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( );
   sc = new Scanner(System.in);
   System.out.println( );
   try{
   sh = new Shoe(brand, size, color);
   }
   catch(ShoeException se){
   System.out.println("Error in creating the shoe");
   System.out.println(se.getMessage( ));
   sc = new Scanner(System.in); //resetting the scanner
   }
   } //ends inner try
   catch(InputMismatchException ime){
   System.out.println("you did not enter a number for either size or color");
   sc = new Scanner(System.in);
   }
   System.out.println(sh.toString( ));
   }
}

Output

Add a comment
Know the answer?
Add Answer to:
You will write a class called Shoe.java Shoe.java should have Three instance variables String brand (cannot...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in...

    In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in 'Dog' : name (String type) age (int type) 2. declare the constructor for the 'Dog' class that takes two input parameters and uses these input parameters to initialize the instance variables 3. create another class called 'Driver' and inside the main method, declare two variables of type 'Dog' and call them 'myDog' and 'yourDog', then assign two variables to two instance of 'Dog' with...

  • import java.util.Scanner; public class TriangleMaker {    public static void main(String[] args) {        //...

    import java.util.Scanner; public class TriangleMaker {    public static void main(String[] args) {        // TODO Auto-generated method stub        System.out.println("Welcome to the Triangle Maker! Enter the size of the triangle.");        Scanner keyboard = new Scanner(System.in);    int size = keyboard.nextInt();    for (int i = 1; i <= size; i++)    {    for (int j = 0; j < i; j++)    {    System.out.print("*");    }    System.out.println();    }    for (int...

  • First you will need to write three classes: Game Shoe Assignment within each class you will...

    First you will need to write three classes: Game Shoe Assignment within each class you will add two fields and a constructor. For Game you will need to keep track of the name of the game (String) and the number of players (int). The constructor will be in the order (String, int). For Shoe you will need the shoe size (double) and the brand (String). The constructor will be in the order (double, String). For Assignment you will need the...

  • (Java with Netbeans) Programming. Please show modified programming code for already given Main class, and programming...

    (Java with Netbeans) Programming. Please show modified programming code for already given Main class, and programming for code for the new GameChanger class. // the code for Main class for step number 6 has already been given, please show modified progrraming for Main class and GameCHanger class, thank you. package .games; import java.util.Random; import java.util.Scanner; public class Main { public static void main(String args[]) { System.out.println("Welcome to the Number Guessing Game"); System.out.println(); Scanner sc = new Scanner(System.in); // Get upper...

  • public class Pet {    //Declaring instance variables    private String name;    private String species;...

    public class Pet {    //Declaring instance variables    private String name;    private String species;    private String parent;    private String birthday;    //Zero argumented constructor    public Pet() {    }    //Parameterized constructor    public Pet(String name, String species, String parent, String birthday) {        this.name = name;        this.species = species;        this.parent = parent;        this.birthday = birthday;    }    // getters and setters    public String getName() {        return name;   ...

  • Read through the code of the class Player, noting it has two instance variables, name and rank, which are of type String and three further instance variables won, drew and lost which are of type int....

    Read through the code of the class Player, noting it has two instance variables, name and rank, which are of type String and three further instance variables won, drew and lost which are of type int. There is also an attribute of the class, points, which does not have a corresponding instance variable. Also note the constructor and methods of the class and what they do. TournamentAdmin class code: public class RankAdmin {    /**     * Constructor for objects of class...

  • C# programming 50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (Strin...

    C# programming 50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (String) edition ( int) published year (int) Constructor that takes all of the above variables as input parameters. set/get methods ToString method// that return sting representation of Book object. 2-Create the sub class New_Book that is derived from the base class Book and has the following instance variables, constructor, and methods: title...

  • Programming Assignment 1 Write a class called Clock. Your class should have 3 instance variables, one...

    Programming Assignment 1 Write a class called Clock. Your class should have 3 instance variables, one for the hour, one for the minute and one for the second. Your class should have the following methods: A default constructor that takes no parameters (make sure this constructor assigns values to the instance variables) A constructor that takes 3 parameters, one for each instance variable A mutator method called setHour which takes a single integer parameter. This method sets the value of...

  • (How do I remove the STATIC ArrayList from the public class Accounts, and move it to...

    (How do I remove the STATIC ArrayList from the public class Accounts, and move it to the MAIN?) import java.util.ArrayList; import java.util.Scanner; public class Accounts { static ArrayList<String> accounts = new ArrayList<>(); static Scanner scanner = new Scanner(System.in);    public static void main(String[] args) { Scanner scanner = new Scanner(System.in);    int option = 0; do { System.out.println("0->quit\n1->add\n2->overwirte\n3->remove\n4->display"); System.out.println("Enter your option"); option = scanner.nextInt(); if (option == 0) { break; } else if (option == 1) { add(); } else...

  • Update your Assignment 4 as follows (Assignment 4 codes will be on the bottom) Create a...

    Update your Assignment 4 as follows (Assignment 4 codes will be on the bottom) Create a new method called displayAll, that takes an ArrayList (of your base class) as a parameter, and doesn't return anything [25 pts] The displayAll method will loop through the ArrayList, and call the display (or toString) method on each object   [25 pts] In the main method, create an ArrayList containing objects of both your base class and subclass. (You should have at least 4 objects)  [25...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT