From 52f359301f620771dcb91df832faaf008aea002c Mon Sep 17 00:00:00 2001 From: Tyler-FS Date: Sun, 11 Feb 2024 12:41:16 -0800 Subject: [PATCH] Complete Java Assignment 004 --- .idea/vcs.xml | 6 ++++++ Java-Assignment-004.iml | 1 + src/Multadd.java | 23 +++++++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 .idea/vcs.xml create mode 100644 src/Multadd.java diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Java-Assignment-004.iml b/Java-Assignment-004.iml index b46c0dd..7b67cbe 100644 --- a/Java-Assignment-004.iml +++ b/Java-Assignment-004.iml @@ -5,6 +5,7 @@ + \ No newline at end of file diff --git a/src/Multadd.java b/src/Multadd.java new file mode 100644 index 0000000..d36f37d --- /dev/null +++ b/src/Multadd.java @@ -0,0 +1,23 @@ +public class Multadd { + public static double multadd (double a, double b,double c) { + return a * b + c; + } + + public static double expSum (double x){ + //use multadd to calculate xe^(-x) + sqrt(1 - e^(-x)) + return multadd(x, Math.exp(-x), Math.sqrt(1 - Math.exp(-x))); + } + public static void main(String[] args) { + // test multadd by passing arguments a: 1.0, b: 2.0, c: 3.0 + System.out.println(multadd(1.0, 2.0, 3.0)); + + //Calculate sin(pi/4) + cos(pi/4)/2 using multadd + System.out.println(multadd(Math.cos(Math.PI / 4), 0.5, Math.sin(Math.PI / 4))); + + //Calculate log10(10) + log10(20) using multadd + System.out.println(multadd(1, Math.log10(10), Math.log10(20))); + + //Calculate xe^(-x) + sqrt(1 - e^(-x)) where x = 2.5 + System.out.println(expSum(2.5)); + } +} \ No newline at end of file