SIGN IN YOUR ACCOUNT TO HAVE ACCESS TO DIFFERENT FEATURES

FORGOT YOUR PASSWORD?

FORGOT YOUR DETAILS?

AAH, WAIT, I REMEMBER NOW!
Openbaraza

Openbaraza

Openbaraza

Baraza is a Swahili word that means a deliberation meeting held by a collective group of people with wisdom.

T : +254 (20) 2243097 / 2227100
Email: info@openbaraza.org

OPENBARAZA
Dew CIS Solutions LTD Barclays Plaza, 12th Floor. Loita Street.

Open in Google Maps
  • Framework
  • Projects
    • Human Resource
      • Human Resource
      • Time Attendance
      • Project Planning
    • Finance Management
      • Business
      • Payroll
    • Investment Management
      • Banking
      • Chama
      • Sacco
    • Case Management
      • Judiciary
    • Real Estate Management
      • Property
    • Academic Management
      • UMIS
      • Schools
  • Forums
    • HCM HR Payroll
    • Business
    • Sacco
    • Banking
  • Blog & News
    • OpenBaraza Framework
    • Databases
    • Java Programming
    • Scrum
  • Contact Us
  • Home
  • Blog & News
  • Java Programming
  • 03. Operators
March 31, 2023

03. Operators

03. Operators

by dennis@dennis.me.ke / Thursday, 06 June 2019 / Published in Java Programming

OPERATORS : PYTHAGOREAN THEOREM

Java offers you endless possibilities, thus the use of operators is vast! There are so many of them out there, all doing different things. But for this blog, lets keep it classy and touch on them a bit by highlighting the Pythagorean Theorem. Such a scary name, right? Don’t sweat it though, there’s nothing to fear here.

Pythagorean Theorem

This is a basic geometric law that can be defined as:

In a right angled triangle: the square of the hypotenuse is equal to the sum of the squares of the other two sides.

It is represented as:

So let’s work on a case problem. Suppose a and c are given as 3 and 5 respectively. What is the value of b ?

Using a2 + b2 = c2 ,

32 + b2 = 52

b2 = 52 – 32

b2 = 16

b = 4

 

Now to help with this concept, we need to understand some other trigonometric basics. These will be useful in using angles and the sides of the triangle to derive unknowns, given the problem.

SOHCAHTOA

“SOHCAHTOA” is a helpful mnemonic for remembering the definitions of the trigonometric function sine, cosine, and tangent i.e., sine equals opposite over hypotenuse, cosine equals adjacent over hypotenuse, and tangent equals opposite over adjacent,

 

 

– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –LIVE A LITTLE:

 – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – 

 Having such a math problem we can now proceed to write our java code that solves it using the Pythagorean Theorem and using the trigonometric mnemonic to derive the other two angles of the triangle.

 

import java.lang.Math;

import static java.lang.Math.acos;

public class Pythagorean {

public static void main(String[] args) {

 double height=3, base, hypo=5, angleA, angleB, area, sineA;

base = Math.sqrt((hypo*hypo) – (height*height));
System.out.print(“\n” + “Base = ” + base);

area = (height*base)/2;
System.out.print(“\n” + “Area = ” + area);

sineA = height/hypo;
System.out.print(“\n” + “Sine of angle A = ” + sineA);

angleA = Math.asin(sineA);
angleA = Math.toDegrees(angleA);
System.out.print(“\n” + “Angle A = ” + angleA);

angleB = 180 – (90 + angleA);
System.out.print(“\n” + “Angle B = ” + angleB);

}

}

 

Explanations:

 

//declare and initiliaze variables as per the case problem

//using the “=” operator to assign values to the variables

 

double height=3, base, hypo=5, angleA, angleB, area,sineA;

 

//find the hypotenus using Pythagorean theorem

//using the “*” operator to multiply values.

//the “\” operator is used alongside “n” to start a new line

//the “+” can be used for addition of values and in this case it is used to add the variable to the output statement.

 

        base = Math.sqrt((hypo*hypo) – (height*height));
        System.out.print(“\n” + “Base = ” + base);

 

//find the area of the triangle using the formula (bh)/2

//the “/” operator is used to divide values or as “//” to indicate comments

        area = (height*base)/2;
        System.out.print(“\n” + “Area = ” + area);

//Calculating sine of angle using the formula sinx=height/hypotenuse

        sineA = height/hypo;
        System.out.print(“\n” + “Sine of angle A = ” + sineA);

//to find angle A find the inverse of sineA
angleA = Math.asin(sineA);
angleA = Math.toDegrees(angleA);
System.out.print(“\n” + “Angle A = ” + angleA);

//to find the other angle(B), find the difference between 180 and sum of 90 and angleA
        angleB = 180 – (90 + angleA);
        System.out.print(“\n” + “Angle B = ” + angleB);

 

 

 

The output is expected to look like this:

 

We’re sure that was quite the walk down the memory lane. Now you have some new skills added to you try out some other trigonometric concepts and enjoy the ride.

In summary, working with operators in Java requires one to follow the following steps.

  1. Understanding the Pythagorean theorem and “SOHCAHTOA” mnemonic to understand operators.
  2. Using a case problem to illustrate the theories.
  3. Writing a Java application to solve the case problem
  4. Explaining the Java code
0
  • Tweet

About dennis@dennis.me.ke

What you can read next

08. BODMAS IN JAVA
01. Learning Java in Windows
06. Classes: Store Student Details Using Json Format

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • 08. BODMAS IN JAVA

  • 07. JAVA ARRAYS: Store Student Details Using Arrays and List

  • 06. Classes: Store Student Details Using Json Format

  • 02. SPRINT RETROSPECTIVE

  • 01. SCRUM (DEMO)

Categories

  • Databases
  • Java Programming
  • OpenBaraza Framework
  • Scrum

QUICK LINKS

  • Home
  • Our Stories
  • Contact Us
  • Terms and Conditions
  • Our Policy

VISIT US

Open Baraza
Barclays Plaza, 12th Floor.
Loita Street, Nairobi.

Open in Google Maps

GET IN TOUCH

Tel: +254 (20) 2243097 / 2227100
     +254(726)209214, +254(738)819505
Email: info@openbaraza.org

Follow Us

over a year agoRT @dewcis: Manage your HR,Payroll and Time attendance with just a click of a button with our Easy to use Baraza Human Capital Management(H…
over a year agoInstalling Java Development Kit(JDK) Tutorial #Java #javascript" title="https://t.co/a2K2VzYhYq #Java #javascript" target="_blank">https://t.co/a2K2VzYhYq #Java #javascript
over a year agoNew Blog alert #java#arrays" title="https://t.co/EBDMlqL2Kq #java#arrays" target="_blank">https://t.co/EBDMlqL2Kq #java#arrays #classes
over a year agoAre you a fresh university graduate with a computer related degree and interested in being a software developer or… https://t.co/94CzteMjLq
over a year agoCheck out our new blog on operators #operators #codinglife" title="https://t.co/vOcebUw1xI #operators #codinglife" target="_blank">https://t.co/vOcebUw1xI #operators #codinglife
over a year agoLearning Java language on windows #Windows" title="https://t.co/HfsLDSWcVP #Windows" target="_blank">https://t.co/HfsLDSWcVP #Windows #Java #javascript #codinglife
over a year agoRT @dewcis: Fair Trade Software Foundation (FTSF) is venturing into a new cooperative enterprise named workpamoja. As part of the initiativ…
over a year agoWhat is SQL? Why SQL? SQLProcess? This are some the question our continuing database series article will be answeri… https://t.co/HgiUf3XwYz
over a year agoAs businesses grow, there is a need for the business owners to embrace emerging technologies. Check out our continu… https://t.co/Vq6gaF3n1o
over a year agoLike storage boxes, a database is an arranged chest of tables and columns that hold information. Check our our late… https://t.co/krRINpg03x
Follow @openbaraza
  • GET SOCIAL
Openbaraza

© All rights reserved | Open Baraza developed by DewCis Solutions.

TOP