# Output of names and sales not formatted properly.

• 03-20-2012, 05:55 AM
edd21
Output of names and sales not formatted properly.
Hello,

I have completed all the required calculations however I am a bit stuck as how to format them for proper output. Since my loops are contained in their own method I cannot iterate through them one by one. The output should resemble:

John Doe 23% 13%
Jane Doe 32% 47%

However my output resembles:

John Doe
Jane Doe
.............23%
.............32%
...................13%
...................47%

(Spaces replace the periods shown in this example)

Any help would be greatly appreciated.

Code:

```package list2; import java.util.Scanner; import java.io.*; public class NewTestSalesReport {         SortedListOfSalesperson list = new SortedListOfSalesperson();                 static int sales;         static float expenses;         static int salesTotal;   static float expensesTotal;         static String name;         static float salesPer;                 // Scanner based constructor.         public NewTestSalesReport(Scanner inFile)         {                 SalesPerson person;                                           while(inFile.hasNext())                 {                         name = inFile.next();                         name += " " + inFile.next();                         sales = inFile.nextInt();                         expenses = inFile.nextFloat();                         person = new SalesPerson(name, sales, expenses);                         list.add(person);                         salesTotal = salesTotal + sales;                         expensesTotal = expensesTotal + expenses;                 }         }         public String printName()         {                 while (list.hasNext())                         {                                 System.out.println(list.next().getName());                         }                         list.resetList();                         return (name);         }         public int printSales()         {                 float salesPer = 0;                 while (list.hasNext())                 {                         salesPer = (list.next().getSales());                         salesPer = salesPer/salesTotal*100;                         System.out.println("        " + salesPer + "%");                 }                 list.resetList();                 return (sales);         }         public float printExpenses()         {                 float expensePer = 0;                 while (list.hasNext())                 {                         expensePer = (list.next().getExpenses());                         expensePer = expensePer / expensesTotal*100;                         expensePer = (int)expensePer;                         System.out.println("                " + expensePer + "%");                 }                 return (expenses);         }                public void PrintReport()         {                 printName();                 printSales();                 printExpenses();         }         public static void main(String[] args) throws IOException         {                 NewTestSalesReport salesReport;                 Scanner inFile = new Scanner(new FileReader("sales.txt"));                 salesReport = new NewTestSalesReport(inFile);                                 System.out.println("Total Sales: " + "Total Expenses: ");                 System.out.println(salesTotal + "                " + expensesTotal);                 salesReport.PrintReport();         } }```