How to call delegate methods from other class in Swift?

How do I call methods in my program? I need to fill methods in the areas with comments labeled?

  • import java.util.Scanner; import java.lang.Math; public class LucVincentGeometry { public static void printMenu() { System.out.print("This is a geometry calculator. "); System.out.println("Choose what would you like to calculate: "); System.out.println("1. Find the area of a circle "); System.out.println("2. Find the area of a rectangle "); System.out.println("3. Find the area of a triangle "); System.out.println("4. Find the circumference of a circle "); System.out.println("5. Find the perimeter of a rectangle "); System.out.println("6. Find the perimeter of a triangle "); System.out.println("Enter the number of your choice "); } public static double circleArea( double radius ) { return Math.PI*radius*radius; } public static double rectangleArea( double length, double width ) { return length*width; } public static double triangleArea( double base, double height ) { return 0.5*base*height; } public static double circleCircumference( double radius ) { return 2*Math.PI*radius; } public static double rectanglePerimeter( double length, double width ) { return (2*length + 2*width); } public static double trianglePerimeter( double side1, double side2, double side3 ) { return side1 + side2 + side3; } public static void main (String [] args) { int choice; //the user's choice double value = 0; //the value returned from the method char letter; //the Y or N from the user's decision to exit double radius; //the radius of the circle double length; //the length of the rectangle double width; //the width of the rectangle double height; //the height of the triangle double base; //the base of the triangle double side1; //the first side of the triangle double side2; //the second side of the triangle double side3; //the third side of the triangle //create a scanner object to read from the keyboard Scanner keyboard = new Scanner (System.in); //do loop was chosen to allow the menu to be displayed first do { System.out.println(); //call the printMenu method printMenu(); choice = keyboard.nextInt(); switch (choice) { case 1: System.out.print("Enter the radius of the circle: "); radius = keyboard.nextDouble(); //call the circleArea method and store the result in the value variable System.out.println("The area of the circle is " + value); break; case 2: System.out.print("Enter the length of the rectangle: "); length = keyboard.nextDouble(); System.out.print("Enter the width of the rectangle: "); width = keyboard.nextDouble(); //call the rectangleArea method and store the result in the value variable System.out.println("The area of the rectangle is " + value); break; case 3: System.out.print("Enter the height of the triangle: "); height = keyboard.nextDouble(); System.out.print("Enter the base of the triangle: "); base = keyboard.nextDouble(); //call the triangleArea method and store the result in the value variable System.out.println("The area of the triangle is " + value); break; case 4: System.out.print("Enter the radius of the circle: "); radius = keyboard.nextDouble(); //call the circumference method and store the result in the value variable System.out.println("The circumference of the circle is " + value); break; case 5: System.out.print("Enter the length of the rectangle: "); length = keyboard.nextDouble(); System.out.print("Enter the width of the rectangle: "); width = keyboard.nextDouble(); //call the perimeter method and store the result in the value variable System.out.println("The perimeter of the rectangle is " + value); break; case 6: System.out.print("Enter the length of side 1 of the triangle: "); side1 = keyboard.nextDouble(); System.out.print("Enter the length of side 2 of the triangle: "); side2 = keyboard.nextDouble(); System.out.print("Enter the length of side 3 of the triangle: "); side3 = keyboard.nextDouble(); //call the perimeter method and store the result in the value variable System.out.println("The perimeter of the triangle is " + value); break; default: System.out.println("You did not enter a valid choice."); } keyboard.nextLine(); //consumes the new line character after the number System.out.println("Do you want to exit the program (Y/N)?: "); String answer = keyboard.nextLine(); letter = answer.charAt(0); }while (letter != &#3

  • Answer:

    A method is declared using syntax that resembles the following form: [modifiers] [name]([type 1] [argument 1],[type 2] [argument 2][etc]) { [code block] } Given that declaration, you call the method inside any code block by using syntax resembling the following form: name([expression of type 1],[expression of type 2][etc]) If the method call stands alone, it must also be terminated by a semicolon. This is not required if the call is part of another expression (although whole instructions must also be terminated by semicolons).

Vincent at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.