Java Code for Vector addition, subtraction and multiplication?
-
Hi, I needed to make a java program in which vectors will be either added, subtracted or multiplied, which the user will choose the method themselves. So far, this is what I've come up with and it has way too many errors. All I want is some suggestions and clues as in which area should I clean up the most. //Vector.java - performing multiplication, division, addition and subtraction import java.util.*; class vector { public static void main (String[] args) { int x, y, z; void read() System.out.println("Please enter number for x: " + x); System.out.println("Please enter number for y: " + y); System.out.println("Print enter number for z: " + z); } // For subtracting vectors { vector c; c.x=x-b.x; c.y=y-b.y; c.z=z-b.z; return c; } // For adding vectors { vector c; c.x=x+b.x; c.y=y+b.y; c.z=z+b.z; return c; } // For multiplying vectors by Scalar product { int prod; vector c; c.x=x*b.x; c.y=y*b.y; c.z=z*b.z; prod=c.x+c.y+c.z; System.out.println("\nScalar Product = " + prod); vector d; d.x=(y*b.z)-(z*b.y); d.y=(x*b.z)-(z*b.x); d.z=(x*b.y)-(y*b.x); return d; } void display() { System.out.println("i" + x + "j" + y + "k" + z); } void main() { vector v1,v2,v3; int choice,cont; do { clrscr(); System.out.println("\nEnter your choice : " + choice); switch(choice) { case 1 : System.out.println("\nEnter the Vector\n"); v1.read(); v3=v1-v2; System.out.println("Negation of the Vector : "); System.out.println("i" + x + "j" + y + "k" + z); break; case 2 :System.out.println("\n\nEnter the First Vector : "); v1.read(); System.out.println("\n\nEnter the Second Vector : "); v2.read(); v3=v1+v2; System.out.println("\n\nThe Sum of Vectors : "); v3.display(); break; case 3 : System.out.println("\n\nEnter the First Vector : "); v1.read(); System.out.println("\n\nEnter the Second Vector : "); v2.read(); v3=v1*v2; System.out.println("\n\nVector Product = "); v3.display(); break; } } }
-
Answer:
Clean up the input value to avoid the miscalculation of the vectors.... Good luck!
Anne at Yahoo! Answers Visit the source
Other answers
Clean up the input value to avoid the miscalculation of the vectors.... Good luck!
Related Q & A:
- How to Code Encryption Algorithm in Java?Best solution by code2learn.com
- how to close the applet in java code?Best solution by Stack Overflow
- how to Create a Java Package from MATLAB Code?Best solution by Stack Overflow
- What is the assembly program of multiplication table?Best solution by cs.unm.edu
- I need help with writing up the Java Code.Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.