Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Getting "null" in my output
New Posts  All Forums:Forum Nav:

Getting "null" in my output

post #1 of 3
Thread Starter 
I'm working on this assignment and for the life of me I can not determine why I am getting a null in my output. I included my code below and would really appreciate some help and any criticism on my code.

Thanks!
Code:
import javax.swing.*;

public class Rental {
  public static void main(String[] args) {
    process();
  }//end main method
  public static void process(){
    String output = "";
    String input = "";

    int count = 0;

    input = JOptionPane.showInputDialog("Enter the number of houses that will be looked at: ");
    count = Integer.parseInt(input);    

    String[] address = new String[count];
    String[] city = new String[count];
    String[] state = new String[count];
    String[] property = new String[count];

    int[] zip = new int[count];
    int[] location = new int[count];

    double[] inspectionCost = new double[count]; 
    double[] repairCost = new double[count];
    double[] totalCost = new double[count];

    double totalExpense = 0;

    int waterfront = 0;
    int nonWaterfront = 0;

    for(int i = 0; count > i; i++){  
      address[i] = JOptionPane.showInputDialog("Enter the street address: ");

      city[i] = JOptionPane.showInputDialog("Enter the city: ");

      state[i] = JOptionPane.showInputDialog("Enter the state: ");

      input = JOptionPane.showInputDialog("Enter the zip code: ");  zip[i] = Integer.parseInt(input);

      input = JOptionPane.showInputDialog("Enter the cost of the inspection fee: \nWaterfront: 1 \nOther: 2");  location[i] = Integer.parseInt(input);

      switch(location[i]){
        case 1: inspectionCost[i] = 100; waterfront++; break;
        case 2: inspectionCost[i] = 50; nonWaterfront++; break;
      }//end switch statement

      input = JOptionPane.showInputDialog("Enter the cost of repairs for the property: ");  repairCost[i] = Double.parseDouble(input);
      
      totalCost[i] = inspectionCost[i] + repairCost[i];

      property[i] += address[i] + "\n" + city[i] + ", " + state[i] + " " + zip[i]  + "\nTotal Cost of Rental Property: " + totalCost[i] + "\n\n";
      
      output += property[i];

      totalExpense += totalCost[i];

    }//end for loop

    output += "Total expected from all owners " + totalExpense + "\nNumber of waterfront rentals: " + waterfront + "\nNumber of non-waterfront rentals: " + nonWaterfront;

    JOptionPane.showMessageDialog(null, output);

  }//end process method
}//end Rental Class
My 1st Build
(13 items)
 
  
CPUMotherboardGraphicsRAM
AMD 5600+ @ 2.8GHz ASUS Crosshair eVGA 8800GTS 640MB Corsair XMS2 DDR2 800 4GB(2X2GB) Cas 5 
Hard DriveOptical DriveOSMonitor
160GB OS Drive + 500GB x4 = 1.5TB RAID 5 Lite-On SATA Burner Windows Vista Ultimate (64-Bit) Dual 20" Dell Widescreen's 
KeyboardPowerCaseMouse
Saitek Eclipse Antec Earthwatts 500W Thermaltake Armor Logitech MX518 
Mouse Pad
None 
  hide details  
Reply
My 1st Build
(13 items)
 
  
CPUMotherboardGraphicsRAM
AMD 5600+ @ 2.8GHz ASUS Crosshair eVGA 8800GTS 640MB Corsair XMS2 DDR2 800 4GB(2X2GB) Cas 5 
Hard DriveOptical DriveOSMonitor
160GB OS Drive + 500GB x4 = 1.5TB RAID 5 Lite-On SATA Burner Windows Vista Ultimate (64-Bit) Dual 20" Dell Widescreen's 
KeyboardPowerCaseMouse
Saitek Eclipse Antec Earthwatts 500W Thermaltake Armor Logitech MX518 
Mouse Pad
None 
  hide details  
Reply
post #2 of 3
Changing this line:
Code:
property[i] += address[i] + "\n" + city[i] + ", " + state[i] + " " + zip[i]  + "\nTotal Cost of Rental Property: " + totalCost[i] + "\n\n";

to this:
Code:
property[i] = address[i] + "\n" + city[i] + ", " + state[i] + " " + zip[i]  + "\nTotal Cost of Rental Property: " + totalCost[i] + "\n\n";

Will fix that null output
First Build
(17 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k @4.5Ghz Gigabyte Z68X-UD7 B3 MSI 6950 G.Skill Sniper 2x4GB 
Hard DriveHard DriveHard DriveCooling
Crucial M4 64GB Samsung SpinPoint 250GB Hitachi 1TB Noctua NH-D14 
OSMonitorMonitorKeyboard
Windows Server 2012 Samsung S22B300 22' ViewSonic VA703B 17" CM Quickfire TK 
PowerCaseMouse
Corsair HX850 NZXT Phantom Mionix Naos 3200 
  hide details  
Reply
First Build
(17 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k @4.5Ghz Gigabyte Z68X-UD7 B3 MSI 6950 G.Skill Sniper 2x4GB 
Hard DriveHard DriveHard DriveCooling
Crucial M4 64GB Samsung SpinPoint 250GB Hitachi 1TB Noctua NH-D14 
OSMonitorMonitorKeyboard
Windows Server 2012 Samsung S22B300 22' ViewSonic VA703B 17" CM Quickfire TK 
PowerCaseMouse
Corsair HX850 NZXT Phantom Mionix Naos 3200 
  hide details  
Reply
post #3 of 3
EDIT: Nvm, Serious brain fart.
Edited by randomizer - 9/8/12 at 12:53am
    
CPUMotherboardGraphicsRAM
i7 920 D0 MSI X58 Pro-E GTX 560 Ti 448 3x2GB G.Skill DDR3-1333 9-9-9-24 
Hard DriveHard DriveOptical DriveOS
OCZ Vertex Caviar Black ASUS DVD-RW Windows 8 Pro x64 
MonitorMonitorKeyboardPower
Dell U2713HM Dell U2311H Turbo-Trak (Google it :D) Corsair HX-520 
CaseMouseMouse PadAudio
CM690 Dogitech G5 Everglide Titan Sennheiser HD201 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
i7 920 D0 MSI X58 Pro-E GTX 560 Ti 448 3x2GB G.Skill DDR3-1333 9-9-9-24 
Hard DriveHard DriveOptical DriveOS
OCZ Vertex Caviar Black ASUS DVD-RW Windows 8 Pro x64 
MonitorMonitorKeyboardPower
Dell U2713HM Dell U2311H Turbo-Trak (Google it :D) Corsair HX-520 
CaseMouseMouse PadAudio
CM690 Dogitech G5 Everglide Titan Sennheiser HD201 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Getting "null" in my output