Skip to content
  • Home
  • News
  • Sample Code
  • How To
  • Tutorial
  • Assignment Help!

Student Assignment Help

Assignment Solution @ Assignment Help on Fiverr.com

  • Home
  • News
  • Sample Code
    • C/C++ Sample Code
      • C in Linux
        • Linux Kernel Module
      • C in Windows
    • Java Sample Code
    • Python Sample Code
    • New Jersey Standard ML (SML/NJ)
    • Oracle Sample Code
    • Database Analysis and Design Sample
  • How To
    • HTML-XML-CSS
    • Java
    • MySQL
    • Oracle
    • Linux RedHat
  • Tutorial
    • System Analysis and Design
    • Data Flow Diagram DFD
    • Database Analysis and Design
    • C/C++ Language
    • WordPress
      • WordPress Basic
      • WordPress Security
  • Assignment Help!

Sample Java Program for Triangle

Posted on 2017-03-032018-11-08 By Presto Bear No Comments on Sample Java Program for Triangle

Download Solution: Click to Download Solution
Solution File Name: JavaProgramTriangle.docx
Unzip Password: prestobear.com

Problem:
Sample Java Program for Triangle


1. GeometricObject.java

/*
 * This is the GeometricObject
 * This is the base class for the Triangle Class
 * This class provide basic methods for the Triangle class 
 */

public class GeometricObject {
	private String color = " white ";
	private boolean filled;
	private java.util.Date dateCreated;

	public GeometricObject() {
		dateCreated = new java.util.Date();
	}

	/*
	 * Create the shape with the color and filled
	 */
	public GeometricObject(String color, boolean filled) {

	}

	public String getColor() {
		return color;
	}

	public void setColor(String color) {
		this.color = color;
	}

	public boolean isFilled() {
		return filled;
	}

	public void setFilled(boolean filled) {
		this.filled = filled;
	}

	public java.util.Date getDateCreated() {
		return dateCreated;
	}

	public String toString() {
		return "Created on " + dateCreated + "\n color: " + color + " and filled ";                 
	}   
}

2. TestTriangle.java

import java.util.Scanner;

/*
 * This class is the clas to Test for the Triangle class
 */

public class TestTriangle  {

	public static void main(String[] args) {

	}
}

3. Triangle.java
/*
 * This Class is to take the Triangle parameter and compute
 * Design a class named Triangle that extends
 * GeometricObject. The class contains:
 * Three double data fields named side1, side2, and side3 with default
 * values 1.0 to denote three sides of the triangle.
 * A no-arg constructor that creates a default triangle.
 * A constructor that creates a triangle with the specified side1, side2, and
 * side3.
 * 
 * The accessor methods for all three data fields.
 * A method named getArea() that returns the area of this triangle.
 * A method named getPerimeter() that returns the perimeter of this triangle.
 * A method named toString() that returns a string description for the triangle.
 */

public class Triangle extends GeometricObject {
	private double side1 = 1.0;
	private double side2 = 1.0;
	private double side3 = 1.0;

	public Triangle() {
	}

	/*
	 * Constructor for the Triangle
	 */
	public Triangle(double side1, double side2, double side3) {
		this.side1 = side1;
		this.side2 = side2;
		this.side3 = side3;
	}

	public double setSide1() {
		return side1;
	}

	public double setSide2() {
		return side2;
	}

	public double setSide3() {
		return side3;
	}

	public void setSide1(double side1) {
		this.side1 = side1;
	}

	public void setSide2(double side2) {
		this.side2 = side2;
	}

	public void setSide3(double side3) {
		this.side3 = side2;
	}

	/*
	 * Compute the Area
	 */
	public double getArea() {
		return (side1 + side2 + side3) / 2;
	}

	/*
	 * Compute the Perimeter
	 */
	public double getPerimeter() {
		return side1 + side2 + side3;
	}

	public String toString() {
		return " Triangle: Side 1 = " + side1 + " Side 2 = " + side2
				+ " Side 3 = " + side3;
	}
}
Assignment Help!!!
Java Sample Code Tags:GeometricObject.java, Java Program, Java Triangle, Triangle Program, Triangle.java

Post navigation

Previous Post: Sample Java Program for Course Management
Next Post: Sample Java Program for Geometric Shape

Leave a Reply Cancel reply

You must be logged in to post a comment.

Assignment Help!!!

Key Posts

  • Chapter 5 – Crow’s Foot Notation
  • Sample Java Program for Triangle
  • [SOLVED] Could not find this item. This is no longer located
  • Chapter 4 – DFD Level Diagram Violation Rule
  • Using WireShark for IP Datagram, RIP 2, OSPF
Assignment Help!!!

Recent Posts

  • Windows 10: How to start Command Prompt as Admin and Terminate a process
  • Java How to Trust all Email Server
  • [Solved]: Windows 10 100% Disk Usage
  • Weddings, Parties, Everything Catering Services System
  • CSC/CPE 3350 Lab 4 Part 1 – Recursive File Search
  • Zayed University
  • Kitchen Gadgets
  • Food Ordering System
  • Investment bank XYZ Ltd
  • CSC/CPE 3350 Lab 3 – The Falcon Shell
  • CSC/CPE 3350 Lab 2
  • Analyzing Cost and Benefit: Campus Bikes
  • Emirates Top Auto Parts
  • Sports News
  • Workington Council
Assignment Help!!!

Copyright © 2022 Student Assignment Help.