Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

output format

Posted on 2008-06-26
3
Medium Priority
?
207 Views
Last Modified: 2010-03-30
please help me to display double type output. I know it round off, but i don't know now to fix it. Thanks.
import java.util.*;
import java.io.*;
import java.text.DecimalFormat;
import java.text.NumberFormat;
 
// calculate value of x, y, z
class Calculation
{
	double a, b,  c,  d;
	double t;
 
	public double findPoint ()
	{
		if( a == 0 && b ==0 )       //return z
		{
			t = -d/c;
 
			NumberFormat formatter = new DecimalFormat("##");
			String s = formatter.format(t);
			System.out.print("z is " + s + "\n");
 
			return(t);
		}
		else if( a == 0 && c ==0 )  //return y
		{	t = -d/b;
 
			NumberFormat formatter = new DecimalFormat("##");
			String s = formatter.format(t);
			System.out.print("y is " + s + "\n");
 
			return(t);
		}
		else                        //if( b == 0 && c ==0 )  // return x
		{
			t= -d/a;
 
			NumberFormat formatter = new DecimalFormat("##");
			String s = formatter.format(t);
			System.out.print("x is " + s + "\n");
 
			return(t);
		}
	}
 
	void assignValue (double first, double second, double third, double fourth)
	{
		a = first;
		b = second;
		c = third;
		d = fourth;
	}
}
 
class Demo
{
	public static void main ( String[] args)
	{
 
		double a, b, c, d;
		double x, y, z;
 
		Calculation item1 = new Calculation();
 
		// supposed plane equation is 0.3x + 0.5y + 0.7z + 0.9 = 0
		//                              a      b      c      d
 
		item1.assignValue(0.3,0.0,0.0,0.9); // get x => y = z = 0
		x = item1.findPoint();              //x = -3
 
		item1.assignValue(0.0,0.5,0.0,0.9); // get y => x = z = 0
		y = item1.findPoint();              // y= -1.8
 
		item1.assignValue(0.0,0.0,0.7,0.9); // get z => x = y = 0
		z = item1.findPoint();				// z= -1.2858
 
	}
}

Open in new window

0
Comment
Question by:valleytech
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 2000 total points
ID: 21878018
Do you want 2 decimal places? If so:
        public double findPoint2() {
                if ((a == 0) && (b == 0)) //return z
                 {
                        t = -d / c;
 
                        System.out.printf("z is %.2f  n", t);
 
                        return (t);
                } else if ((a == 0) && (c == 0)) //return y
                 {
                        t = -d / b;
                        System.out.printf("y is %.2f  n", t);
 
                        return (t);
                } else //if( b == 0 && c ==0 )  // return x
                 {
                        t = -d / a;
                        System.out.printf("x is %.2f  n", t);
 
                        return (t);
                }
        }

Open in new window

0
 

Author Comment

by:valleytech
ID: 21878058
go it. Thanks for quick response.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 21878179
:-)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question