/** ~~~~~
* Created with the AppyBuilder Code Editor.
* This is a template for basic Extension.
* Modify this template to customize your extension.
*
* **** NOTE: DO NOT use a package name.
* **** The package name will be created for you automatically.
* **** Adding a package name will cause a compile error
*/
import android.content.Context;
import android.util.Log;
import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.runtime.*;
import com.google.appinventor.components.common.ComponentCategory;
@DesignerComponent(version = 1, description = "Calculates some basic geometrical shapes'areas." +
"Created with AppyBuilder. Create your own here:
https://editor.appybuilder.com
",
category = ComponentCategory.EXTENSION,
nonVisible = true, iconName = "https://lh3.googleusercontent.com/ogw/ADea4I42VqEybFK87QSOLCsJXghDvdf0uhA3Rya5Li0g=s32-c-mo")
@SimpleObject(external = true)
public class Maths extends AndroidNonvisibleComponent {
private ComponentContainer container;
/**
* @param container container, component will be placed in
*/
public Maths(ComponentContainer container) {
super(container.$form());
this.container = container;
}
@SimpleFunction(description = "Calculates the area of a square.")
public double AreaOfSquare (double side) {
return side * side;
}
@SimpleFunction(description = "Calculates the perimeter of a square.")
public double PerimeterOfSquare (double side) {
return side * side;
}
@SimpleFunction(description = "Calculates the perimeter of a rectangle.")
public double PerimeterOfRectangle (double length, double width) {
return length * width;
}
@SimpleFunction(description = "Calculates the area of a rectangle.")
public double AreaOfRectangle (double length, double width) {
return length * width;
}
@SimpleFunction(description = "Calculates the area of a triangle.")
public double AreaOfTriangle (double base, double height) {
return base * height / 2;
}
@SimpleFunction(description = "Calculates the perimeter of an isoceles triangle.")
public double PerimeterOfIsocelesTriangle (double leg, double base) {
return leg + leg + base;
}
@SimpleFunction(description = "Calculates the perimeter of an equilateral triangle.")
public double PerimeterOfEquilateralTriangle (double side) {
return side * 3;
}
@SimpleFunction(description = "Calculates the area of a right-angled triangle.")
public double AreaOfRightIscocelesTriangle (double side) {
return side * side / 2;
}
@SimpleFunction(description = "Calculates the area of a trapezium.")
public double AreaOfTrapezium (double upper, double lower, double height) {
return (upper + lower) * height / 2;
}
@SimpleFunction(description = "Calculates the area of a circle.")
public double AreaOfCircle (double radius) {
return radius * radius * 3.14;
}
@SimpleFunction(description = "Calculates the radius of a circle from a diameter.")
public double Radius (double diameter) {
return diameter / 2;
}
@SimpleFunction(description = "Calculates the diameter of a circle from a radius.")
public double Diameter (double radius) {
return radius * 2;
}
}