im working with a two class program. i have one for calculations and the other for the main method like so:

/**
 * Write a description of class CO2FromWaste here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class CO2FromWaste
{
    private int numberOfPeople;
    private int numPeople;
    private double grossWasteEmission;
    private boolean paper;
    private boolean paperRecycled;  
    private boolean plasticRecycled;  
    private boolean plastic;
    private boolean glassRecycled;
    private boolean glass;
    private boolean cansRecycled; 
    private boolean cans; 
    private double canReductions;
    private double glassReductions;
    private double plasticReductions;
    private double paperReductions; 
    private double netWasteReduction;
    private double total; 
    
    
    
    public CO2FromWaste(int numPeople, boolean paper, boolean plastic, boolean glass, boolean cans)
    {
        numPeople = numberOfPeople;
        paper = paperRecycled;
        plastic = plasticRecycled;
        glass = glassRecycled;
        cans = cansRecycled;
    
    
    }
    
    public double calcGrossWasteEmission(){
    grossWasteEmission = numPeople * 1018;
            return grossWasteEmission;
        }
        
    public double calcCanReductions() {
            double can = 165.8;
                if (cans){
                    canReductions  = (can * numPeople);
                }
                return canReductions;
            }
        
    public double calcGlassReductions() {
            double glassReduce = 46.6;
                if(glass){
                    glassReductions = (glassReduce * numPeople);
              
            }
            return glassReductions;
        }
        
            
    public double calcPlasticReductions() {   
             double plasticReduce = 25.6;
             if(plastic){
                plasticReductions = (plasticReduce * numPeople);
              }
            return plasticReductions;
        }
        
        
            
    public double calcPaperReductions() {   
               double paperReduce = 184.0;
               if(paper){
                    paperReductions = (paperReduce * numPeople);   
            }
        
        return paperReductions;
        
        }
        
    public double calcNetWasteReduction(){
             netWasteReduction = paperReductions + plasticReductions + glassReductions + canReductions;
             return netWasteReduction;
            }
            
    public double total(){
        total = grossWasteEmission - netWasteReduction;
        return total;
    }
}
/**
 * Write a description of class CO2FromWasteTester here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
import java.util.*; 
public class CO2FromWasteTester
{
    
       public static void main(String[] args){
           
       List<CO2FromWaste> CO2FromWaste = new ArrayList<CO2FromWaste>(); 
       CO2FromWaste.add(new CO2FromWaste(1, true, true, true, true));
       CO2FromWaste.add(new CO2FromWaste(3, true, false, true, true));
       CO2FromWaste.add(new CO2FromWaste(4, false, false, false, false));
       CO2FromWaste.add(new CO2FromWaste(1, true, true, true, true));
       CO2FromWaste.add(new CO2FromWaste(1, true, true, true, true));
       
       CO2FromWaste dataRecord;
       
       for(int index = 0; index < CO2FromWaste.size(); index++) 
       { 
            dataRecord = CO2FromWaste.get(index); 
            dataRecord.calcGrossWasteEmission(); 
            dataRecord.calcNetWasteReduction(); 
            dataRecord.total();
        }
       
      
           
      //print header
      System.out.println("                                                                                                            Pounds of CO2");
      System.out.println("                   Household Waste Recycled                Total                                                           Net");
      System.out.println(" Index    People    Paper    Plastic    Glass    Cans           Emissions            Reduction                       Emissions");
      
      for (int counter = 0; counter < CO2FromWaste.size(); counter++) {
          
          dataRecord = CO2FromWaste.get(counter);
          System.out.printf("%4.2f", dataRecord.calcGrossWasteEmission());
          System.out.printf("%4.2f", dataRecord.calcNetWasteReduction());
          System.out.printf("%4.2f", dataRecord.total());
          
        }
    }
           
  
           
        
}

i have almost everything except for the output working correctly. i have no idea how to get everything to output. i have my header, but i need it to be like be like

Index People Paper Plastic Glass Cans Emissions Reduction Emissions

under each thing like paper, plastic, glass, cans i output whether each thing is true or false. i have a picture of basically what i am trying to do. i attached it.

Hi,

Your constructor does something probably, but sure not what you want. It should be like this:

public CO2FromWaste(int numPeople, boolean paper, boolean plastic, boolean glass, boolean cans)
    {
        // replace
                // numPeople = numberOfPeople;
        // with
                // member = parameter passed to constructor
        numberOfPeople = numPeople;        // like this
        // paper = paperRecycled;
        paperRecycled = paper;
        // plastic = plasticRecycled;
        // ... and so on
        // glass = glassRecycled;       
        // cans = cansRecycled;   
        // you can call your methods to initialize the other members here and remove the -for- from your Tester class
        grossWasteEmission = numPeople * 1018; // like this, 
        // or
        grossWasteEmission = calcGrossWasteEmission(); 
        // and the method should look like the following
        // ... same for other values
    }

        public double calcGrossWasteEmission(){
            return numPeople * 1018;            
        }

To format your output you can use printf() I think (I've never used it but I know that exists :) )
or
System.out.prinlnt() with tab characters "\t" to indent your text in header. Tabs are more efficient than spaces, as far as I know.

You will probably need some getters for your CO2FromWaste class members, or a toString method like:

public String toString(){
        return numberOfPeople + "\t| " + paperRecycled +"\t| " // + ... other members
}

and call it to output your values

GL!

This article has been dead for over six months. Start a new discussion instead.