Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By tamilarasi

Thread: I added an array and now the program provides no output, please help

  1. #1
    jjennings is offline Member
    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0

    Default I added an array and now the program provides no output, please help

    Hello,

    I am new to Java and creating a program that must do the following;

    The application will now compare the total annual compensation of at least two salespersons.

    It will calculate the additional amount of sales that each salesperson must achieve to match or exceed the higher of the two earners.

    The application should ask for the name of each salesperson being compared.

    I am required to use an array list for this project.

    I am using NetBeans IDE. The code runs successfully but there is no out put displayed. I am assuming it is a bracket issue but I am not sure. Please help.

    Here is my code;

    Java Code:
    package sales1;
    
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.Scanner;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    
    public class Sales1
    {
        public static void main(String[] args) 
        {
        }
    public class SalesPerson
    {
    public class SalesPersonArray
    {
    
    {
        
    BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Enter Sales Amount : ");
    int sales = 0;
                try {
                    sales = Integer.parseInt(in.readLine());
                } catch (IOException ex) {
                    Logger.getLogger(Sales1.class.getName()).log(Level.SEVERE, null, ex);
                }
    double comm = 0,pay = 0;
    
    if(sales<0)
    {
    System.out.println("The sales amount cannot be negative!");
    }
    if (sales>=96001 && sales<=120000) {
            comm=sales*0.05;
        }
    if (sales>=120001 && sales<=3000000) {
            comm=sales*0.0625;
        }
    
    pay=40000+comm;
    System.out.println("Salesperson's total annual compensation : "+pay);
    
    double projectedSales;
    double projectionCap;
    double projectedCommissions;
    double commissionRate;
    double projectedPay;
    
    projectionCap=sales*1.5;
    projectedSales=sales;
    commissionRate=0;
    
    while (projectedSales < projectionCap) {
    	projectedSales=projectedSales+5000;		
    	if (projectedSales>projectionCap) {
    		projectedSales=projectionCap;
    	}
    	if (projectedSales>=96001 && projectedSales<=120000) {
    		commissionRate=0.05;
     	} else if (projectedSales>=120001 && projectedSales<=3000000) {
    		commissionRate=0.0625;
    	}
    	projectedCommissions=projectedSales*commissionRate;
    	projectedPay=40000+projectedCommissions;
    	System.out.print("Sales of: " + projectedSales );
    	System.out.print("     Pays a Commission of: " + projectedCommissions );
    	System.out.print("     Total Compensation of: " + projectedPay );
    	System.out.println();
     //declare variables for array  
        String salesPerson1;  
        String salesPerson2;  
          
          
        //number of employees to compare, and initialize array  
      
             int[] aTotal = new int[2];  
               
             //new scanner input  
             Scanner keyboard = new Scanner(System.in);  
               
             //get salesperson1 name  
             System.out.println("Enter the salesperson's name?");  
             salesPerson1 =  keyboard.nextLine();  
               
             //get salesperson1 sales total  
             System.out.println("Enter the total sales for the year");  
             aTotal[0] = (int) keyboard.nextDouble();  
               
             //get salesperson2 name  
             System.out.println("Enter the salesperson's name?");  
             salesPerson2 = keyboard.nextLine();  
               
             //get salesperson2 sales total  
             System.out.println("Enter the total sales for the year");  
             aTotal[1] = (int) keyboard.nextDouble();  
               
             //This part of the array needs to rference back to the commission  
             // calcs to add data to the array  
               
             for (int counter=0; counter < aTotal.length; counter++)  
             {  
                 System.out.printf("Salesperson: Total", counter, aTotal[counter]);  
             }  
                        
            System.out.println("Salesperson" + "\t\t" + "Total");  
            System.out.println("--------------------------------");  
              
    
    }
    }
    }
    }
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,455
    Rep Power
    20

    Default Re: I added an array and now the program provides no output, please help

    Consistent indentation and bracing style helps to make code readable. I suggest you edit your post.
    Code Conventions for the Java Programming Language: Contents

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    tamilarasi is offline Member
    Join Date
    Nov 2012
    Location
    India
    Posts
    70
    Rep Power
    0

    Default Re: I added an array and now the program provides no output, please help

    you can't do anything because your main method is empty...

    Java Code:
    public static void main(String[] args)
        {
        }
    you call the methods and classes into your main method...
    Valerie10b likes this.
    Regards
    Android developer at Trinay Technology Solutions,http://www.trinaytech.com,5705750475

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,920
    Rep Power
    5

    Default Re: I added an array and now the program provides no output, please help

    Java Code:
    public class Sales1
    
    {
        public static void main(String[] args) 
        {
        }
    public class SalesPerson
    {
    public class SalesPersonArray
    {
     
    {
    You also have two inner classes. SalesPerson inside of Sales1 and SalesPersonArray inside of SalesPerson. And your SalesPersonArray class has an extra opening brace. And it looks like the SalesPersonArray class is all that is in your SalesPerson class. So you probably need to rethink your design.

    Since you are new to Java, I doubt that you want inner classes. You have several other options. Make any additional classes, regular and non public and you can put them in the same file as your Sales class. Or make them public which means they must reside in their own file, named just like the class name and suffixed with.java.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Not getting all output from program
    By neveser in forum New To Java
    Replies: 6
    Last Post: 12-08-2012, 08:45 PM
  2. Weird output from Array program
    By zniightmare in forum New To Java
    Replies: 2
    Last Post: 03-07-2012, 02:22 AM
  3. Array output
    By lowziqian in forum New To Java
    Replies: 1
    Last Post: 12-01-2011, 09:18 AM
  4. Output of the program
    By Sheenu Gupta in forum New To Java
    Replies: 1
    Last Post: 07-25-2011, 09:32 AM
  5. Help-would like JFRAME added to program
    By tigerfan2 in forum New To Java
    Replies: 1
    Last Post: 05-13-2008, 04:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •