20% D Tue Mar 219 27 54 PM aR E Chrome File Edit View History Bookmarks People W
ID: 3801920 • Letter: 2
Question
20% D Tue Mar 219 27 54 PM aR E Chrome File Edit View History Bookmarks People Window Help Assignments Posting f Facebook Zelda BotW Hidden Shrine A08.pd ksuweb.kennesaw.edu a hhaddad/Spring2017/CS1301/A08.pd Apps k D cs 130 LIowlLink-Online Ca CompTIA A+ Certifi PlayStation Program YouTube home nbox king 199@s Vue A08..pdf output using escape characters. Program #2 (10 points Design and implement a Java program for programming exercise 6.15, page 237, from the textbook (name it TaxTable). Design the program to print out separate tables for filing status (Single, Married Joint or Qualifying Widow(er), Married Separate, and Head of house). Document your code, and organize the outputs use escape characters. Program #3 11o points: Design and implement two Java programs for programming exercise 6.19, page 238. The first program (called MyTriangle) is to implement the specified methods. The second program (called TestMyTriangle) is to test the first program methods. Program TestMyTriangle is used to compute the area of a triangle if the input is valid. Notice that method isvalid s used to validate the input before attempting to compute the area. See listings10 and 11 (page 24) on how to write 2 programs (main program and test program). Design the test program main method such that it allows the user to re-run the program with different inputs ((i e., use a loop structure). Document your code and organize the outputs properly using escape. Save both programs in the same folder. Program #4 10 points: Design and implement a Java program for programming exercise 6.30, page 241 from the textbook (name it CrapsGame). Rolling a dice is simply generating a random integer number betweenExplanation / Answer
MyTriangle.java
public class MyTriangle {
//Declaring instance variables
private double side1;
private double side2;
private double side3;
//Zero argumented constructor
public MyTriangle() {
super();
}
/* This method is used to calculate
* the area of the triangle using Herons formula
*/
public static double area(double side1,double side2,double side3)
{
double p=(side1+side2+side3)/2;
double area=Math.sqrt(p*(p-side1)*(p-side2)*(p-side3));
return area;
}
/* This method is used to check whether
* the three sides are valid sides of the triangle
*/
public static boolean isValid(double side1,double side2,double side3)
{
if(side1+side2>side3 && side1+side3>side2 && side2+side3>side1)
return true;
else
return false;
}
}
_____________________
Test.java
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
// declaring variables
double side1, side2, side3;
// Scanner object is used to get the inputs entered by the user
Scanner sc = new Scanner(System.in);
// Getting the 3s ides of the triangle
System.out.print("Enter Length of side 1:");
side1 = sc.nextDouble();
System.out.print("Enter Length of side 2:");
side2 = sc.nextDouble();
System.out.print("Enter Length of side 3:");
side3 = sc.nextDouble();
// Checking whether the three sides are valid or not
boolean bool = MyTriangle.isValid(side1, side2, side3);
/*
* if valid find area of triangle If not,display Error message
*/
if (bool)
System.out.println("Area of Triangle :"+ MyTriangle.area(side1, side2, side3));
else
System.out.println("** Input is Invalid **");
}
}
_________________
Output:
Enter Length of side 1:7
Enter Length of side 2:2
Enter Length of side 3:2
** Input is Invalid **
_______________
Output#2:
Enter Length of side 1:3
Enter Length of side 2:4
Enter Length of side 3:5
Area of Triangle :6.0
_______________Thank You
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.