Carly’s Catering provides meals for parties and special events. Write a program that displays Carly’s motto, which is "Carly’s makes the food that makes it a party." Save the file as CarlysMotto.java. Create a second program that displays the motto surrounded by a border composed of asterisks. Save the file as CarlysMotto2.java.

Respuesta :

Answer:

Here is  code CarlysMotto.java

//import package

import java.util.*;

// class name

class CarlysMotto

{

// main method of class CarlysMotto

public static void main (String[] args) throws java.lang.Exception

{

   try{

    // string to hold the Carly's motto

       String motto="Carly’s makes the food that makes it a party.";

       System.out.println("Carly’s motto: ");

       // print the motto

       System.out.println(motto);

   }catch(Exception ex){

       return;}

}

}

Explanation:

Create a class named "CarlysMotto".In the main method, create a strint that holds the motto.In the new line print "Carly’s motto:".After that print the string that holds Carly’s motto in newline.

Here is next code CarlysMotto2.java

//import package

import java.util.*;

// class name

class CarlysMotto2

{

// main method of class CarlysMotto

public static void main (String[] args) throws java.lang.Exception

{

   try{

    // string to hold the Carly's motto

       String motto="Carly’s makes the food that makes it a party.";

       System.out.println("Carly’s motto: ");

// this will print a line of asterisks(*)    System.out.println("***********************************************************");

       // print the motto

       System.out.println(motto);

// this will print a line of asterisks(*)    System.out.println("***********************************************************");

   }catch(Exception ex){

       return;}

}

}

Explanation:

Create a class named "CarlysMotto".In the main method, create a strint that holds the motto.In the new line print "Carly’s motto:".Then print a line of asterisks (*).After  that print the string that holds Carly’s motto in newline.After then print a line of asterisks(*).

Output:

Here is the output of both the program.

Ver imagen SerenaBochenek
Ver imagen SerenaBochenek

Answer:

CarlysMotto.java

  1. public class Main {
  2.    public static void main(String[] args) {
  3.        System.out.println("Carly’s makes the food that makes it a party.");
  4. }

CarlysMotto2.java

  1. public class Main {
  2.    public static void main(String[] args) {
  3.        String motto = "Carly’s makes the food that makes it a party.";
  4.        for(int i=0; i < motto.length() + 2; i++){
  5.            System.out.print("*");
  6.        }
  7.        System.out.println();
  8.        System.out.print("*" + motto + "*");
  9.        System.out.println();
  10.        for(int i=0; i < motto.length() + 2; i++){
  11.            System.out.print("*");
  12.        }
  13.    }
  14. }

Explanation:

CarlysMotto.java

To display the motto, we can simply write a print statement using the println() method (Line 3).

CarlysMotto2.java

To print the "asterisks" border that surround the motto string, we need to estimate the number of asterisks needed to build the top and bottom borderline. The number of asterisks will be equal to the length of the motto string + 2.

Based on this understanding, we can create the for-loop by iterating motto length + 2 times to print the asterisks to form the top and bottom borders (Line 6 - 8 and Line 16 - 18).

In the middle, we can simply concatenate an asterisk with motto string and with a asterisk again (Line 12).

The output shall look like this:

*********************************************** ************

*Carly’s makes the food that makes it a party.*

***********************************************************