define a constructor as indicated. sample output for below program

Question 1

Question 2

A bag of cookies holds 40 cookies. The calorie information on the bag claims that there are 10 servings in the bag and that a serving equals 300 calories. Write a Java program that lets the user enter the number of cookies he or she actually ate and that then reports the number of total calories consumed.

Java is a high level programming language and computing platform developed by Sun Microsystems in 1995. JAVA is similar to the C programming language, but is more heavily typed in defining variables. JAVA has become a popular language because of its portability across platforms.

Question 3

Create an static method called addZZZ() that passes a String object into its arguments and returns the String object but with the characters zzz at the beginning and at the end of the String.

Modify the array so that it takes an array of Strings and returns an array of Strings. Add zzz to the beginning and end of each element in the array. The solution should include a class and main() method that has an appropriate method call to addZZZ().

In this program, we create a static method that takes a string as a parameter and returns a String with the characters zzz at the beginning and at the end of the String.

We use concat() method of String class for this.

If the original String is “Mango” then we use “zzz”.concat(“Mango”).concat(“zzz”)” to concatenation “zzz” at the beginning and end of the string.

In the main method first, we define an Array of original Sting. Using a for loop, we get each element of the array. Then we call addZZZ() function for each element and save the modified string to a new array.

At last, we print the new array.

Answer to question 1

I have uploaded the Images of the code,Typed code and Output of the Code.I have provided explanation using comments(read them for better understanding).

Question :Basic Constructor definition

Answer to question 2

Answer to question 3

Leave a Comment