5385 Shares

Java program for Polar and Cartesian coordinates with inheritance: Key: inheritance and methods?

Java program for Polar and Cartesian coordinates with inheritance: Key: inheritance and methods? Topic: How to write an abstract class
November 21, 2019 / By Ackley
Question: I desperately need help. I feel really lost with the chapter on inheritance, etc. This is what I am supposed to do and after I will post the code I have so far. I am so so lost. The other programs I felt like I understood but I don't get how to do the inheritance stuff with scanning values in etc. I started writing my main method after I had done some with the other classes and got stuck but now I don't know if it is right or if I have to do that stuff I did at all. Please help with details -- I am so, so, so lost. I have an exam on Thursday and really hope to understand this stuff better. I am sorry it is so long. It is a super detailed program and I am getting really lost. I get that I have two have nested loops to get the main gist but help!Thank you for any details you can give me!! MAIN METHOD HERE::::::::::: import java.util. Scanner; public class CoordConversion { public static void main(String [] args) { Scanner scan = new Scanner(System.in); System.out.println("(p) Polar Coordinates (r, theta (degrees))"); System.out.println("(c) Cartesian Coordinates (x,y)"); System.out.println("(x) Exit Program \n"); System.out.print("What type of coordinates? "); String str = scan.next(); char coord = str.charAt(0); //int rad1, rad2, theta1, theta2; if (coord == 'p' || coord == 'P') { System.out.print("Coordinate 1 - Please enter the radius: "); double rad1 = scan.nextDouble(); System.out.print("Coordinate 1 - Please enter the theta (degrees): "); double rad2 = scan.nextDouble(); System.out.print("Coordinate 2 - Please enter the radius: "); double theta1 = scan.nextDouble(); System.out.print("Coordinate 2 - Please enter the theta (degrees): "); double theta2 = scan.nextDouble(); System.out.print("\n"); System.out.println("[1] Convert to Cartesian Coordinates: "); System.out.println("[2] Find the distance between the two points: "); System.out.println("[3] Find the slope of the line between the points: "); System.out.println("[4] Find the equation of the line between the points: "); System.out.println("[5] Return to main menu: \n"); System.out.println("What would you like to do? \n"); } else if (coord == 'c' || coord == 'C') { System.out.print("Coordinate 1 - Please enter x: "); double x1 = scan.nextDouble(); System.out.print("Coordinate 1 - Please enter y: "); double y1 = scan.nextDouble(); System.out.print("Coordinate 2 - Please enter x: "); double x2 = scan.nextDouble(); System.out.print("Coordinate 3 - Please enter y: "); double y2 = scan.nextDouble(); System.out.print("\n"); System.out.println("[1] Convert to Polar Coordinates: "); System.out.println("[2] Find the distance between the two points: "); System.out.println("[3] Find the slope of the line between the points: "); System.out.println("[4] Find the equation of the line between the points: "); System.out.println("[5] Return to main menu: \n"); System.out.println("What would you like to do? \n"); } else { return; } } //System.out.println("Thank you for using my program!"); } Here are all of the classes that go before/with the main method. I am so so sorry it is long. :( public abstract class Coordinate { protected static double value1, value2; public Coordinate(double val1, double val2) { value1 = val1; value2 = val2; } public double getValue1(){ return value1; } public double getValue2(){ return value2; } public abstract double getDistance(Coordinate c); // public abstract double getSlopeOfLine(Coordinate c); // // public abstract String getEquationOfLine(Coordinate c); } //import java.util.Scanner; public class PolarCoordinate extends Coordinate { //private double radius, theta; // Coordinate c1 = newPolarCoordinate(r1, t1); // Coordinate c2 = newPolarCoorindate(r2, t2); // double distance = c1.getDistance(c2); public PolarCoordinate(double value1, double value2){ super(value1, value2); } public CartesianCoordinate convert(){ double radius = this.getValue1(); double theta = this.getValue2();
Best Answer

Best Answers: Java program for Polar and Cartesian coordinates with inheritance: Key: inheritance and methods?

Stacia Stacia | 3 days ago
Code: import java.awt.*; public class Trigonometry { /** Class Trigonometry by Chris Clarke, February 2005 * Use it to convert Polar to Rectangular co-ordinates; * also to convert Degrees to Radians and vice versa. */ public double P2R_X(int hypotenuse, double angle) { /* Convert polar to rectangular co-ordinates sin(angle) = opposite/hypotenuse cos(angle) = adjacent/hypotenuse tan(angle) = opposite/adjacent therefore opposite = hypotenuse * sin(angle) and adjacent = hypotenuse * cos(angle) Note: angle is measured in Radians */ double x = hypotenuse * Math.cos(angle); return x; } public double P2R_Y(int hypotenuse, double angle) { // Note: angle is measured in Radians double y = hypotenuse * Math.sin(angle); return y; } public double Degree2Radian(double angle) { return angle*(Math.PI/180); } public double Radian2Degree(double angle) { return angle*(180/Math.PI); } public void drawLine(Graphics g, int x, int y, int length, double degrees) { // Draw line of given length at a given angle // Note: angle is in degrees, measured clockwise from the x-axis double radians = Degree2Radian(degrees); int xIncrement=(int) (P2R_X(length, radians)); int yIncrement=(int) (P2R_Y(length, radians)); g.drawLine(x, y, x+xIncrement, y+yIncrement); } }
👍 134 | 👎 3
Did you like the answer? Java program for Polar and Cartesian coordinates with inheritance: Key: inheritance and methods? Share with your friends

We found more questions related to the topic: How to write an abstract class


Stacia Originally Answered: Why is inheritance in java from only one class, rather than multiple?
The inventor of the language, James Gosling wanted Java to be "simple, object-oriented, and familiar." What he meant was that he wanted it to look like C++ without having the over-complexities of C++. To quote: "Primary characteristics of the Java programming language include a simple language that can be programmed without extensive programmer training while being attuned to current software practices. The fundamental concepts of Java technology are grasped quickly; programmers can be productive from the very beginning. [...] Even though C++ was rejected as an implementation language, keeping the Java programming language looking like C++ as far as possible results in it being a familiar language, while removing the unnecessary complexities of C++." Gosling felt that multiple-inheritance was an "unnecessary complexity" of C++. There's really no problems that multiple inheritance solves that can't be solved using interfaces, but multiple-inheritance IS complex, hard to understand, and causes more problems than it solves. Therefore, it was not included in Java. (NOTE: Operator overloading met the same fate.)
Stacia Originally Answered: Why is inheritance in java from only one class, rather than multiple?
As the white paper states, the Java design team strove to make Java: * Simple, object oriented, and familiar * Robust and secure * Architecture neutral and portable * High performance * Interpreted, threaded, and dynamic The reasons for omitting multiple inheritance from the Java language mostly stem from the "simple, object oriented, and familiar" goal. As a simple language, Java's creators wanted a language that most developers could grasp without extensive training. As multiple inheritance has those deadly diamond problems where deadlock occurs so its been decided by java makers to use interface that is "design by contract" concept borrowed from Objective C's protocol to overcome multiple inheritance. Hope this helps Cheers:)
Stacia Originally Answered: Why is inheritance in java from only one class, rather than multiple?
The question doesn't make any sense. You get methods of the base class from a parent class, and you can also let the class implement an interface (which is basically the same thing as inheritance actually), but inheritance doesn't make any sense for methods because the sole purpose for inheritance is polymorphy, which doesn't apply to methods.

Prissy Prissy
Inheritance is obvious within the bodily world. If we mannequin our programmble portions effortlessly, then we will mannequin actual world predicament without difficulty. Inheritance allows us to reuse the code designed in a single kind in derived courses. Did you be trained Java? Until what extent. Applets? We write our applet like public type xyz extends Applet you almost certainly can have compare applets existence cycle. You could additionally maximize, reduce like every other software. We might have written few strains however still many things we will do. How come all these grew to become feasible with our category. Since it inheritance lot of behaviours from Applet type. That's, the code associated written in Applet and its enormous publications is instantly on hand for our category additionally.
👍 50 | 👎 -4

Prissy Originally Answered: I have?'s about GIFT OF INHERITANCE?
I had a similar experience. My aunt died in 06 and left me some money. The law firm that was executor of the estate indicated that the estate had to "settle" in order for all the members of our family trust to be paid. Not trying to sound money hungry, either, though "needy" might have been a good choice of words, some of the family contacted the attorney's office. It took four years before we saw the money. There were times when some of us were contemplating having the law firm investigated as we felt they were sitting on a large sum of money in an interest bearing account and making use of the funds. They were holding the funds all the time. There were 19 people getting money from this and some who were closer relatives than I was were getting tons of money. I got a very nice check, but it wasn't in the hundreds of thousands or anything of that nature. This relative set up a charitable foundation with the rest of her millions. Her husband owned a business that was quite profitable and it was also "old money". I'm proud that my aunt, who had no children, set up animal shelters, built wings on hospitals, helped tons of needy people and chose to give some to family. She had the right idea, I think. Yes, it would have been great to inherit tons of money, but I think of the good she did and I am proud of her. RIP. I would contact the executor of the estate and query when the estate expects to settle. I know how it is to wait. We tried not to be greedy about it, but we had plans and hopes and were excited about this money coming to us. It's OK to want it, we wanted what we got too. I hope it comes soon and you get to enjoy it. One piece of advice is to save some of it. I blew some of it and wish I had been a little more careful.
Prissy Originally Answered: I have?'s about GIFT OF INHERITANCE?
First, it's not a gift. A gift is while granddad was still alive. This is a bequest or inheritance. Second, your husband got a notice that you were a beneficiary. Get that notice out and contact the executor. The IRS encourages estates to wind up affairs by 2 years, but it's not unheard of for things to be extended. There may be real estate to sell (even if your husband was to get stock). There may be debts that need to be paid first. The fact that the sisters have gotten money and the grandchildren haven't *is* confusing. Ask the executor about it. It's possibly that their money was to go directly to them and the grandchildren became beneficiaries of a trust--whose language doesn't have mandatory distributions.

If you have your own answer to the question how to write an abstract class, then you can write your own version, using the form below for an extended answer.
Libros PDF para descargar Una vida enmig del poble + dvd, The new herbal of 1543 Descargas gratuitas de libros electrónicos de Amazon para kindle, Descargar el libro de texto 978-0230439986 Direct to ielts class cd, Fina girbes nacher - Versos que van i vénen 978-8490262436 Descargar libros electrónicos gratuitos de eBay, El trabajo sin seres humanos PDF ePub por Yves clot 978-8493665579, Ebook descarga gratuita epub Manual del desarrollo sostenible, Medicina complementaria Descarga gratuita de libros y revistas El derecho a la tutela jurisdiccional, El temblor de la falsificación... EPUB DJVU mkt-0003302654, Montserrat cornelles Micro-secrets recull de micro-relats i fotografies 978-8594263315, O tempo sin saída mkt-0002366179 por Lois dieguez DJVU PDF Lois dieguez.