Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can anyone help, please: You have decided to use a specialized toy company to pu

ID: 3671124 • Letter: C

Question

Can anyone help, please:

You have decided to use a specialized toy company to purchase birthday gifts for young children of your friends and relatives. The available toys are divided into three categories: plushies, blocks, and books. In addition, you can add a card and/or a balloon with each gift.

You must utilize the provided Toy class for this project, without making any changes to it (study and review the class carefully.) The class will keep a total cost for one toy and determine if the toy is age-appropriate for the child. Assume that the user enters the name and age of the child correctly.

Your program must print a title and a list to the console of all the gifts, with a total for each gift, and the total amount of the order. Then your program must generate a random five-digit order number as an order number.

·       All input items and messages will use dialog boxes (JOptionPane). Only the title, list of gifts, total, and order number are printed on the console. (See sample output.)

·       Ask for the name of the child.

·       Ask for the age of the child. . (A child should be under 18? You decide)

·       Ask for the toy choice and validate the input choicePrint out a message if the toy is not age appropriate and ask if a different toy is desired. Otherwise, print the message "Good Choice!"

·       If the user does not want a different toy, process the toy requested. Otherwise, repeat the steps for a new toy choice.

·       Ask if a card or balloon should be added to the gift.

·       If a card is added, capture the card message

·       Display on the console the name, age, “gift card” message and the total for gift.

·       Ask if another gift is desired. If yes, repeat the steps starting with the name of the child.

·       If no, display on the console the total amount of the order and the random five-digit order number.

·       Any amount should be displayed (on the console) as US currency format (e.g. $15.43).

·       Name your driver class Birthday

·       Input validations are expected

·       Javadoc should be generated

·       UML class diagram(s) must be created

import java.text.DecimalFormat;

* The Toy class will keep the cost for one of three different toys:
* a plushie, a book, and blocks.
* It will determine if the toy is age-appropriate for a child.

public class Toy
{       
   /** cost for the plushie */
   final double PLUSHIE = 25.0;
     
      /** cost for the book */
   final double BOOK = 15.0;
     
      /** cost for blocks */
   final double BLOCKS = 20.0;
     
      /** cost for a card */
   final double CARD = 2.95;
     
      /** cost for a balloon */
   final double BALLOON = 6.0;
     
   private String toy;       // the toy to purchase
   private double cost;   // the cost of the entire toy purchase
   private int age;       // the age of the child
  
   DecimalFormat dollar = new DecimalFormat("#,##0.00");   //format cost
  
       /** no-arg constructor */
   public Toy()
   {
       toy = "";
       cost = 0;
       age = 0;
   }
  
       /** constructor initializes toy and age to values input from the user,
       * cost to appropriate constant
       *
       * @param t the toy requested
       * @param a the age of the child
       * @param c the cost to the cost of the toy requested
       */
   public Toy(String t, int a)
   {
       setToy(t);
       setAge(a);
       setCost(t);
   }
  
      /** change the toy to be used
   *
   * @param t Change the toy
   */
public void setToy(String t)
{
   if (t.toLowerCase().equals("plushie"))
    toy = "plushie";    
    else if (t.toLowerCase().equals("book"))
        toy = "book";
else if (t.toLowerCase().equals("blocks"))
       toy = "blocks";   
else
   toy = "";
}
  
    /** change the age of the child
   *
   * @param a the age of the child to receive the toy
   */
public void setAge(int a)
{
   age = a;
}
  
   /** change the cost to the cost of only the gift with no add-ons
   * @param t the original cost of the toy
   */
public void setCost(String t)
{
   if (t.toLowerCase().equals("plushie"))
       cost = PLUSHIE;
        else if (t.toLowerCase().equals("book"))
           cost = BOOK;
        else if (t.toLowerCase().equals("blocks"))
            cost = BLOCKS;
        else
            cost = 0;
}
  
   /** get the string representing the toy
   *
   * @return the name of the toy requested
   */
public String getToy()
{
   return toy;
}
  
   /** get the age of the child that corresponds to the toy
   *
   * @return the age of the child
   */
public int getAge()
{
   return age;
}
  
   /** get the cost of the toy requested (may include add-ons)
   *
   * @return the cost of the toy
   */
public double getCost()
{
   return cost;
}
  
       /** determines age-appropriate for the toy:
       * plushie: 0 to 2 years
       * book: 4 to 7 years
       * blocks: 3 to 5 years
       * @return true if toy matches age range and false otherwise.
       */
public boolean ageOK()
{
   if (toy.equalsIgnoreCase("plushie") && (age >= 0 && age <= 2))
       return true;
   else if(toy.equalsIgnoreCase("blocks") && (age >= 3 && age <= 5))
       return true;
   else if(toy.equalsIgnoreCase("book") && (age >= 4 && age <= 7))
       return true;
   else
       return false;
}
  
       /** add a card to the gift
       * update the cost of the gift
       * @param s
       */
   public void addCard(String s)
   {
   if(s.equalsIgnoreCase("yes"))
       addCost(CARD);
   }
  
       /**add a balloon to the gift
       * update the cost of the gift
       * @param s
       */
   public void addBalloon(String s)
   {
   if (s.equalsIgnoreCase("yes"))
       addCost(BALLOON);
   }
  
       /** change the cost of the gift when a card or balloon is added
       *
       * @param c cost of card or balloon
       */
   public void addCost(double c)
   {
   cost += c;
   }
  
       /** gives a string representation of the instance variables
       *    @return the instance variables as a string with cost formatted for currency
       */
public String toString()
{
   return " " + age + " years old is " + toy + " $" + dollar.format(getCost());
}
}

I just need the class and driver

Explanation / Answer

Solution for the Given Problem

I written this below TestToy Driver class to test the given java program called Toy with sample plushie..
And it is working fine with the below code and i tested also.

public class TestToy
{
   public static void main(String[] args)
   {
       Toy obj = new Toy("plushie",2);
       boolean flag = obj.ageOK();
       obj.addCard("yes");
       obj.addBalloon("yes");
       System.out.println(obj);
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote