about summary refs log tree commit diff stats
path: root/example1.mu
blob: aebf22ba75026cf1bda75529f481d411eff4ed69 (plain) (blame)
1
2
3
4
5
def example1 [
  local-scope
  a:num <- add 2, 2
  a <- multiply a, 3
]
dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#import "/template.typ": *
#show: A => apply(A)
#set raw(lang: "java-new")
#set par(leading: 0.6em)

#assignment(13)[
  Write a program to create a class `Shape` with 4 methods to calculate the areas of triangle, rectangle, square, and circle using method overloading.
]

#scos("ShapeAreaCalculations")

=== Discussion

#skind[Classes and methods implemented in the program]

- The `Shape` class provides static methods for calculating the area of different geometric shapes:
  - `static double area(double a, double b, double c)`: Calculates the area of a triangle using its side lengths.
  - `static int area(int length, int width)`: Calculates the area of a rectangle using its length and width.
  - `static int area(int sideLength)`: Calculates the area of a square using its side length.
  - `static double area(double radius)`: Calculates the area of a circle using its radius.

- The `ShapeAreaCalculations` class contains the main program for calculating the area of geometric shapes based on user input through a menu-driven interface:
  - `static void menu()`: Displays a menu of shape choices.
  - `public static void main(String[])`: Implements a menu-driven program for calculating the area of different shapes (_i.e._ triangle, rectangle, square, or circle) based on user input.

  
#signature()