Need help formatting output and some code
Alright, what I need help with is converting some code. The basics are I am reading in a file and need to output that file to the terminal window formatted as described below.
First my terminal window output equals:
There are complex numbers in quadrant number 1.
1.0+2.0i
There are complex numbers in quadrant number 4.
4.0+-3.2i
There are complex numbers in quadrant number r-axis.
12.3+0.0i
There are complex numbers in quadrant number i-axis.
0.0+-1.9i
There are complex numbers in quadrant number 3.
-1.0+-1.0i
There are complex numbers in quadrant number 2.
-1.0+2.3i
There are complex numbers in quadrant number 1.
4.0+4.0i
WHILE MY OUTPUT REALLY NEEDS TO LOOK LIKE THIS:
There are 2 complex numbers in quadrant 1.
tabbed over--> 1 + 2i
tabbed over--> 4 + 4i
There is 1 complex number in quadrant 2.
tabbed over--> -1 + 2.3i
There is 1 complex numbers in quadrant 3.
tabbed over--> 1 + -1i
There is 1 complex numbers in quadrant 4.
tabbed over--> 4 + -3.2i
There is 1 complex number on the r-axis.
tabbed over--> 12.3 + 0i
There is 1 complex number on the i-axis.
tabbed over--> 0 + -1.9i
So basically what I need is help formatting the output so that mine looks exactly like the above output while using only one static void main and keeping the code simple.
So what I need help with is
1. setting up a function that counts the # of complex numbers on a particular quadrant
2. getting the output to be the in the correct order...example quadrant 1, quadrant 2, etc
3. getting the output sentences to have the correct grammar...example more than 1 complex number means I need "There are 2 complex numbers on the .... while when theres only 1 number I need "There is 1 complex number...
Here's my source code: ANY HELP WOULD BE GREATLY APPRECIATED
Code:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.lang.*;
import java.util.*;
import java.text.NumberFormat;
public class ComplexCatalog {
//data is read in from file...data contained in file is as follows:
// 7
// 1 + 2 i
// 4 + -3.2 i
// 12.3 + 0 i
// 0 + -1.9 i
// -1 + -1 i
// -1 + 2.3 i
//4 + 4 i
public static void main(String[] args) throws FileNotFoundException {
{
//
// Here Scanner is used to read the file content line-by-line.
//
Scanner s = new Scanner(new File("complex.txt"));
int complexCount;
complexCount=s.nextInt();
for (int index = 0; index < complexCount; index++)
{
double realValue = s.nextDouble();
String plusSign = s.next();
double imaginaryValue = s.nextDouble();
String imaginarySign = s.next();
String complexNumber = (realValue+plusSign+imaginaryValue+imaginarySign);
int count = 0;
int quadrantNumber = 0;
String axis = null;
System.out.print("There are " + ""+ "complex numbers in quadrant number " );
if (realValue > 0 && imaginaryValue > 0)
{
System.out.println(1+".");
}
else if (realValue < 0 && imaginaryValue > 0)
{
System.out.println(2+".");
}
else if (realValue < 0 && imaginaryValue < 0)
{
System.out.println(3+".");
}
else if (realValue > 0 && imaginaryValue < 0)
{
System.out.println(4+".");
}
else if (imaginaryValue == 0 && realValue != 0)
{
System.out.println("r-axis.");
}
else if(realValue == 0 && imaginaryValue != 0)
{
System.out.println("i-axis.");
}
{
System.out.println(complexNumber);
}{
System.out.println();
}
}
}
}
}
Edited by Fubarable: code tags added.