QuestionQuestion

• Create a Java reference data type:
o Create a class. Call it Recipe. Save it to a file (Recipe.java) with the same name as the class (Recipe).
o Add a String variable to hold the name of the recipe.
o Add a String array to store ingredients. Set the size of the array to 20.
o Add a String array to store instructions. Set the size of the array to 20.
o Add other attributes as needed.
o Set the accessibility of all attributes to private.
o Add a method to add one ingredient at a time (use a single String variable as the parameter. Do not pass it an array).
o Add a method to add one instruction at a time (use a single String variable as the parameter. Do not pass it an array).
o Add a default constructor (a default constructor has no parameters). Inside the constructor initialize all elements of both arrays to an empty String. Intialize the name to an empty String. Initialize all other variables.
o Add a method to display the name, ingredients, and instructions. Make sure it is readable.
o Do not add a main method to the class. You will be able to compile the code but not execute it.
o Compile your code.
o Submit your source code as a plain text file with a .java extension. Make sure it compiles without error before submitting it.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

public class Recipe {
   
    // o Set the accessibility of all attributes to private
    private String name;
    private String [] ingredients;
    private String [] instructions;
    private int ingredientsNum;
    private int instructionsNum;
   
    /**
    * o Add a default constructor (a default constructor has no parameters).
    * Inside the constructor initialize all elements of both arrays to
    * an empty String.
    * Intialize the name to an empty String.
    * Initialize all other variables.
    */
    public Recipe() {
       this.name = "";
       this.ingredients = new String[20];
       this.instructions = new String[20];
       this.ingredientsNum = 0;
       this.instructionsNum = 0;
    }...
$13.00 for this solution

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