Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
April 28th, 2013, 11:56 AM
 dsabol
Registered User

Join Date: Apr 2013
Posts: 1
Time spent in forums: 7 m 49 sec
Reputation Power: 0

I am working on the following:

To write a class that works with another programmer’s class.
This week, I’ll give you a class called TrigEssentials.java. TrigEssentials:
• Stores a double value for side A of a right triangle
• Stores a double value for side B of a right triangle
• Calculates a double value for the triangle’s hypotenuse
• Calculates a double value for angle a
• Calculates a double value for angle b
• Prints out results
Assignment:
• Create a TrigInteractor.java to work with TrigEssentials
• 2 methods:
o intro( )
o calculate( )
• Use while loop/s
• Use if statements and nested if statements
• Use try/catch

**Note** The right triangle that I drew with print statements has no relevance to the actual lengths being input for sides a and b. It will always be the same triangle pic, regardless of what the sides are (notice in the output that the side lengths don’t match the picture – that’s ok, and unimportant). What is important is that the 3 lengths are in accordance with Pythagorean Theorem.
Output:

(First Method – intro())
*****Welcome to the MSTU Trig Calculator*****
Question - Will you be using our calculator for class, or just for fun? (C / F): class
Sorry - we need a C or F: c
Great - High School or University (H / U): x
Sorry - We need an H or U: U
Our program addresses university level topics - enjoy!
(Second Method – calculate())
Calculate or Quit (C / Q): calculate Sorry, we need a C or Q: c
This Program:
* Finds the hypotenuse of a right triangle * Calculates angles a and b
Length of Side A: seven ***ERROR – INVALID INPUT***
Calculate Again or Quit (C / Q): C
This Program:
* Finds the hypotenuse of a right triangle * Calculates angles a and b
Length of Side A: 34.98 Length of Side B: 56.32
********************Results********************
Side a: 34.98
|\
|\
|\
|\
|B\
|\
|\
| \ Hypotenuse: 66.30 |\
|\
| \ |\ |____ \ ||\ |C|A\ |____|____________\
Side b: 56.32
Angle A is: 58.16 degrees
Angle B is: 31.84 degrees
Angle C is always 90.00 degrees (For right triangles) Total: 180.00 degrees
************************************************** Calculate Again or Quit (C / Q): quit
Sorry, we need a C or Q: q
Thank you
[FONT=Arial Black]
Here is the code I was given:

/**
* TrigUser.java
*
* This class:
* a) stores sideA and sideB of a right triangle (these I get from the user)
* b) calculates a hypotenuse based on sideA and sideB (my getHypotenuse() method calculates and returns this value)
* c) calculates angleA (my getAngleA() method calculates and returns this value)
* d) calculates angleB (my getAngleB() method calculates and returns this value)
* e) contains 2 methods that will print out results (printHypResults(), printAngleResults())
* f) uses the Math class
* g) uses the DecimalFormat class
*
*/
import java.lang.Math;
import java.text.DecimalFormat;
public class TrigEssentials
{
//declaring my istance variables
//double to hold a value for side a
private double sideA;
//double to hold a value for side b
private double sideB;
//double to hold a value for Hypotenuse
private double hypotenuse;
//double to hold a value for angle A
private double angleA;
//double to hold a value for angle B
private double angleB;
//variable to hold a DecimalFormat object
private DecimalFormat formatter;

/**
* Constructor for class TrigUser
* instance variables will get initialized here in the constructor
*/
public TrigEssentials()
{
sideA = 0;
sideB = 0;
hypotenuse = 0;
angleA = 0;
angleB = 0;
formatter = new DecimalFormat("#0.00");

}

/**
* Sets side a
* @param newSideA side a
*
* You'll need to get this from the user
*/
public void setSideA(double newSideA)
{
sideA = newSideA;
}

/**
* Sets side b
* @param newSideB side b
*
* You'll need to get this from the user
*/
public void setSideB(double newSideB)
{
sideB = newSideB;
}

/**
* Returns side a
* @return sideA side a
*/
public double getSideA()
{
return sideA;
}

/**
* Returns side b
* @return sideB side b
*/
public double getSideB()
{
return sideB;
}

/**
* Method to generate hypotenuse
* I'm using the Math.hypot method - no need for me to calculate it myself!
*
* @return hypotenuse hypotenuse
*/
public double getHypotenuse()
{
hypotenuse = Math.hypot(getSideA(), getSideB());
return hypotenuse;
}

/**
* Returns angle A
* @return angleA angle A
*
* The sine of an angle is equal to (opposite side / hypotenuse)
* So, the sine of angle A is (sideB / hypotenuse)
*
* The angle value is the inverse of the sine
* Math.asin is an inverse trig function to generate that value
* BUT - Math.asin brings back a value in radians, and
* I want a value in degrees, so that's why I'm using the Math.toDegrees method
*/
public double getAngleA()
{
double angleAInRadians = Math.asin(getSideB() / getHypotenuse());
return angleA;
}

/**
* Returns angle B
* @return angleB angle B
*
* The sine of an angle is equal to (opposite side / hypotenuse)
* So the sine of angle B is (sideA / hypotenuse)
*
* The angle value is the inverse of the sine
* Math.asin is an inverse trig function to generate that value
* BUT - Math.asin brings back a value in radians, and
* I want a value in degrees, so that's why I'm using the Math.toDegrees method
*/
public double getAngleB()
{
double angleBInRadians = Math.asin(getSideA() / getHypotenuse());
return angleB;
}

/**
* My 2 methods to print out results
*

/**
* Method #1 - method to:
* a) display a right triangle
* b) print out values for sideA, sideB, and hypotenuse
* c) values are formatted to 2 digits after the decimal point
*/
public void printHypResults()
{
System.out.println("\n********************Results********************");
System.out.println("\n\t\t|\\");
System.out.println("\t\t| \\");
System.out.println("\t\t|B \\");
System.out.println("\t\t| \\");
System.out.println("\t\t| \\");
System.out.println("\t\t| \\");
System.out.println("\t\t| \\");
System.out.println("\t\t| \\ Hypotenuse: " + formatter.format(getHypotenuse()));
System.out.println("\t\t| \\ ");
System.out.println("\t\t| \\");
System.out.println("Side a: " + formatter.format(getSideA()) + "\t| \\");
System.out.println("\t\t| \\");
System.out.println("\t\t|____ \\");
System.out.println("\t\t| | \\");
System.out.println("\t\t| C | A \\");
System.out.println("\t\t|____|__________\\");
System.out.println(" ");
System.out.println("\t\t Side b: " + formatter.format(getSideB()));

}

/**
* Method #2 - method to:
* a) print out angle calculations
* b) add up the angles in a right triangle (should add up to 180.0)
*/
public void printAngleResults()
{
System.out.println("\nAngle A is: " + formatter.format(getAngleA()) + " degrees");
System.out.println("Angle B is: " + formatter.format(getAngleB()) + " degrees");
System.out.println("Angle C is always 90.00 degrees (For right triangles)");
System.out.println("Total: " + formatter.format((90.00 + getAngleA() + getAngleB())) + " degrees");
System.out.println("\n**************************************************");
}

}

How do I create the class to work with this????

## Developer Shed Advertisers and Affiliates

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off
 View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox Forum Jump Please select one User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home -------------------- Programming Languages    PHP Development        PHP FAQs and Stickies    Perl Programming        Perl FAQs and Stickies    C Programming        C Programming FAQs and Stickies    Java Help        Java FAQs    Python Programming        Python Programming FAQs    Ruby Programming        Ruby Programming FAQs    Game Development        Game Development FAQs Programming Languages - More    ASP Programming        ASP Programming FAQs    .Net Development        .Net Development FAQs    Visual Basic Programming        Visual Basic Programming FAQs    Software Design        Software Design FAQs    ColdFusion Development        ColdFusion Development FAQs    Delphi Programming        Delphi Programming FAQs    Regex Programming        Regex Programming FAQs    XML Programming        XML Programming FAQs    Other Programming Languages        Other Programming Languages FAQs Web Design    HTML Programming        HTML Programming FAQs    JavaScript Development        JavaScript Development FAQs    CSS Help        CSS Help FAQs    Flash Help        Flash Help FAQs    Photoshop Help        Photoshop Help FAQs    Web Design Help        Web Design Help FAQs    Website Critiques        Website Critiques FAQs    Search Engine Optimization        Search Engine Optimization FAQs Mobile Programming    Mobile Programming        Mobile Programming FAQs    iPhone SDK Development        iPhone SDK Development FAQs    Android Development        Android Development FAQs    BlackBerry Development        BlackBerry Development FAQs Web Site Management    Business Help        Business Help FAQs    Development Software        Development Software FAQs    Scripts        Scripts FAQs Databases    Database Management        Database Management FAQs    DB2 Development        DB2 Development FAQs    MySQL Help        MySQL Help FAQs    PostgreSQL Help        PostgreSQL Help FAQs    Firebird SQL Development        Firebird SQL Development FAQs    MS SQL Development        MS SQL Development FAQs    Oracle Development        Oracle Development FAQs    LDAP Programming        LDAP Programming FAQs System Administration    Mail Server Help        Mail Server Help FAQs    Apache Development        Apache Development FAQs    Security and Cryptography        Security and Cryptography FAQs    Antivirus Protection        Antivirus Protection FAQs    DNS        DNS FAQs    IIS        IIS FAQs    Networking Help        Networking Help FAQs    FTP Help        FTP Help FAQs Operating Systems    BSD Help        BSD Help FAQs    Linux Help        Linux Help FAQs    UNIX Help        UNIX Help FAQs    Windows Help        Windows Help FAQs    Mac Help        Mac Help FAQs Web Hosting    Web Hosting        Web Hosting FAQs    Free Web Hosting        Free Web Hosting FAQs    Web Hosting Requests        Web Hosting Requests FAQs    Web Hosting Offers        Web Hosting Offers FAQs Computer Hardware    Computer Hardware    CPUs        CPUs FAQs    Cooling        Cooling FAQs    Embedded Programming        Embedded Programming FAQs    Motherboards        Motherboards FAQs    Multimedia Hardware        Multimedia Hardware FAQs Other    Dev Shed Lounge        Dev Shed Lounge FAQs    Development Articles        Development Articles FAQs    Beginner Programming        Beginner Programming FAQs    Hire A Programmer        Hire A Programmer FAQs    Project Help Wanted        Project Help Wanted FAQs Latest News Updated Hourly    Technology News    Business News    Science News Forum Information    Forum Rules/Guidelines        Forum Rules/Guidelines FAQs    Forum Announcements        Forum Announcements FAQs    Dev Shed Gaming Center        Go to the Dev Shed Battle Arena        Go to the Dev Shed Arcade Games        Go to the Legend of the Green Dragon    Suggestions & Feedback        Suggestions & Feedback FAQs

 Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |