Question

In: Computer Science

Can someone find what's wrong? If I don't use the last main method Netbeans says that...

Can someone find what's wrong? If I don't use the last main method Netbeans says that there is no main method. I can't figure out what's wrong.

This was the prompt:

Design a class named triangle that extends geometricObject. For this, you should have created a GeometricObject class first. The class contains:

  • Three double datafields named side1, side2, side3 with default value 1.0.
  • A no arg constructor that creates a default triangle.
  • A constructor that creates a triangle with specified side1, side2 and side3.
  • A method named getPerimeter() that returns the perimeter of a triangle.
  • A method name toString that returns the string description of a triangle.(including color and filled)

Your main method should create a triangle object and display it using toString()

This is my code:

package geometricobject;

/**
*
*
*/
public class GeometricObject {

/**
* @param args the command line arguments
*/
private String color = "white";
private boolean filled;
private java.util.Date dateCreated;

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

public GeometricObject(String color, boolean filled) {
dateCreated = new java.util.Date();
this.color = color;
this.filled = 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 + "\ncolor: " + color+ " and filled: " + filled;
}
  


public class triangle extends GeometricObject
{
private double side1;
private double side2;
private double side3;
  
public triangle() {
side1 = 1;
side2 = 1;
side3 = 1;
}
  
public triangle(double side1, double side2, double side3) {
this.side1 = side1;
this.side2 = side2;
this.side3 = side3;
}
public double getSide1() {
return side1;
}
public double getSide2() {
return side2;
}
public double getSide3() {
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 = side3;
}
public double getArea() {
double n = (side1+side2+side3) / 2.0;
return Math.sqrt(n*(n-side1)*(n-side2)*(n-side3));
}
public double getPerimeter() {
return side1 + side2 + side3;
}
  
@Override
public String toString() {
return super.toString() + "Triangle: side1 = " + side1 + " side2 = " + side2 + "side3 = " + side3 ;

}}}

Solutions

Expert Solution

Error details :

  • For testing triangle class need to write a driver class then only error will be resolved
  • need a main() method to in the class.

*****************************

NOTE :NO CHANGE MADE IN THE CLASS GeometricObject.java

triangle.java :

package geometricobject;

//Java class
public class triangle extends GeometricObject {
   //datafields
   private double side1;
   private double side2;
   private double side3;
   //no arg constructor
   public triangle() {
       this.side1 = 1.0;
       this.side2 = 1.0;
       this.side3 = 1.0;
   }
   //constructor with parameters
   public triangle(double side1, double side2, double side3) {
       this.side1 = side1;
       this.side2 = side2;
       this.side3 = side3;
   }

   public double getSide1() {
       return side1;
   }

   public double getSide2() {
       return side2;
   }

   public double getSide3() {
       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 = side3;
   }

   public double getArea() {
       double n = (side1 + side2 + side3) / 2.0;
       double area=n * (n - side1) * (n - side2) * (n - side3);
       double a=Math.sqrt(area);
       return a;
   }
   //A method named getPerimeter() that returns the perimeter of a triangle.
   public double getPerimeter() {
       return side1 + side2 + side3;
   }
   //A method name toString that returns the string description of a triangle.(including color and filled)
   @Override
   public String toString() {
       return super.toString() + "\nTriangle: side1 = " + side1 + " side2 = " + side2 + " side3 = " + side3;

   }
}
***********************************************'

triangleTest.java :

package geometricobject;

//Java class
public class triangleTest {
   // main() method
   public static void main(String[] args) {
       // Object of triangle class
       triangle t = new triangle(3.0, 5.0, 7.0);
       // call method to print area of triangle
       System.out.println("Area of triangle : " + t.getArea());
       // call method to print perimeter
       System.out.println("Perimeter of triangle : " + t.getPerimeter());
       System.out.println(t.toString());
   }

}
======================================

Output :


Related Solutions

Can someone explain this quote to me, Chares Taylor work, "What's Wrong With Negative Liberty" "If...
Can someone explain this quote to me, Chares Taylor work, "What's Wrong With Negative Liberty" "If we are free in the exercise of certain capacities, then we are not free, or less free when these capacities are in some way unfulfilled or blocked."
can someone tell me if i am wrong on any of these???? THANKS In order to...
can someone tell me if i am wrong on any of these???? THANKS In order to be able to deliver an effective persuasive speech, you need to be able to detect fallacies in your own as well as others’ speeches. The following statements of reasoning are all examples of the following fallacies: Hasty generalization, mistaken cause, invalid analogy, red herring, Ad hominem, false dilemma, bandwagon or slippery slope. 1. __________bandwagon fallacy_______ I don’t see any reason to wear a helmet...
I am currently working on this problem. It says it is wrong, and I was wondering...
I am currently working on this problem. It says it is wrong, and I was wondering if someone could correct my code to where its ouput is as followed. Expected Output: 6↵ 5↵ 4↵ 3↵ 2↵ 1 Actual Output: 9↵ 8↵ 7↵ 6↵ 5↵ 4↵ 3↵ 2↵ 1↵ 0↵ 9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments. The function should create a copy of the array, except that the element values...
Please can someone explain this to me. I am stuck at the last two questions Use...
Please can someone explain this to me. I am stuck at the last two questions Use the following information to calculate your answers to questions 10 through 14. Test scores of 10 individuals before and after a training program are shown below. Note: despite the sample size, assume that the sampling distribution of T+ can still be approximated by a normal distribution. Individual Score After the Program Score Before the Program 1 57 59 2 62 57 3 60 60...
/* What's wrong with this code? (nothing actually - but let's fix it to use a...
/* What's wrong with this code? (nothing actually - but let's fix it to use a repetition structure) Copy and paste this .txt file into jGrasp, then save it, compile it, run it. Modify it! Bring your code to class at the start of Week 8, with at least 2 output runs with different data. What the program should do is take orders(input) for three (3) octoberfest guests, using a "for" loop. (+1 pt.) Each guest will choose 1 or...
Okay, can someone please tell me what I am doing wrong?? I will show the code...
Okay, can someone please tell me what I am doing wrong?? I will show the code I submitted for the assignment. However, according to my instructor I did it incorrectly but I am not understanding why. I will show the instructor's comment after providing my original code for the assignment. Thank you in advance. * * * * * HourlyTest Class * * * * * import java.util.Scanner; public class HourlyTest {    public static void main(String[] args)     {        ...
in netbeans using Java Create a project and a class with a main method, TestCollectors. ☑...
in netbeans using Java Create a project and a class with a main method, TestCollectors. ☑ Add new class, Collector, which has an int instance variable collected, to keep track of how many of something they collected, another available, for how many of that thing exist, and a boolean completist, which is true if we want to collect every item available, or false if we don't care about having the complete set. ☑ Add a method addToCollection. In this method,...
I am getting 7 errors can someone fix and explain what I did wrong. My code...
I am getting 7 errors can someone fix and explain what I did wrong. My code is at the bottom. Welcome to the DeVry Bank Automated Teller Machine Check balance Make withdrawal Make deposit View account information View statement View bank information Exit          The result of choosing #1 will be the following:           Current balance is: $2439.45     The result of choosing #2 will be the following:           How much would you like to withdraw? $200.50      The...
Can someone please explain these problems, I don't understand, please and thank you!! The patients in...
Can someone please explain these problems, I don't understand, please and thank you!! The patients in the Digoxin trial dataset can be considered a population of people suffering from heart failure. These patients were examined before the drug trial began, and their heart rate and blood pressure were recorded. The mean and standard deviation of the variables are listed below. Each variable follows a normal distribution. Heart rate (beats/min)                          μ = 78.8            σ = 12.66 Systolic blood pressure (mmHg)             μ...
I don't know which one is wrong. Can you please check. Thank you QUESTION 1 In...
I don't know which one is wrong. Can you please check. Thank you QUESTION 1 In the following code, how many and which functions have been defined/declared? def powerNum(power): pNum = n ** power return pNum n = int(input("Enter a number whose power you want to calculate: ")) def main(): p = int(input("Enter the power number: ")) print ("Power of the number you entered is", powerNum (p)) main() 1 function: powerNum 1 function: powerNum 3 functions: powerNum, and main is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT