Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objective of lab is to create a java nitrogen soil simulator Supplied map: https://ufile.io/59rmx You will use the supplied map which represents the average elevation

Objective of lab is to create a java nitrogen soil simulator

Supplied map: https://ufile.io/59rmx

You will use the supplied map which represents the average elevation of each 100 by 100 metre cell. You will start off with a constant amount of nitrogen in each cell and calculate the remaining nitrogen in each cell every month for 100 years. Nitrogen leaves each cell as it washes away in direct proportion of the difference in elevation between the cell and its neighbours. Each metre of difference causes 0.001 percent of the nitrogen per mm of rain to wash into the adjoining cells of lower elevation.

Each cell starts with 500 kg of biological nitrogen and receives 16 kg of new nitrogen per metre of rainfall every year. I want you vary the rainfall every month of every year a little, but stay within 10 percent of the averages above. After you open your elevation map I want you to save it as a .txt (Tab Delimited) file from Open Office and load it into your Java program. Perform the 100 year simulation in your program and write out a 10 by 30 grid of remaining nitrogen values as a .csv (Comma Separated Value) file. Load that back into Open Office and colour the cells based on the following algorithm. The third of the cells with the most nitrogen colour dark gray, the middle third light gray, and the lowest third white. I want a printout for every 25 (that makes for 5 maps) years showing what (if any) changes happen.

The rain data in mm is presented as follows January 94.3, February 71.7, March 46.5, April 28.5, June 20.7, July 14.9, August 19.6, September 27.3, October 51.2, November 98.0, December 108.9.

Design project for UoT, I don't need the completed data, however I would like assistance on finishing this code...

import java.util.Scanner; import java.util.Arrays; import java.util.ArrayList; import java.io.FileNotFoundException; import java.io.File; import java.util.Random; public class ElevationSim { double [] raindata = {94.3, 71.7, 46.5, 28.5, 20.7, 14.9, 19.6, 27.3, 51.2, 89.0, 100.9}; double[] [] nMap= null; private final String eFileName = new String("/home/ford2/mycpsc110/elevations.csv"); ArrayList> eMap = new ArrayList>(); public static void main(String[] args) throws FileNotFoundException { ElevationSim es = new ElevationSim(); es.simulate(); } //eMap is get and size() //nMap is length and [] private void loadeMap(String filePath) throws FileNotFoundException { File file = new File(filePath); Scanner fin = new Scanner(file); while(fin.hasNextInt()) { ArrayListrows= new ArrayList(); String line = fin.nextLine(); String [] tokens = line.split("\\s+"); for(int i=0; i> nMap = new ArrayList>(); private void loadnMap () { nMap=new double [eMap.size()][eMap.get(0).size()]; for(int i=0; iEAST) if(eMap.get(i).get(j)>eMap.get(i).get(j+1)) { Double cN = nMap[i][j+1]; Double eDif = eMap.get(i).get(j)-eMap.get(i).get(j); Double nChange = cN*eDif*rain*(0.001/100.0); nMap[i][j+1] += nChange; nMap[i][j] -= nChange; } // south neighbor if(eMap.get(i).get(j)>eMap.get(i+1).get(j)) { Double cN = nMap[i+1][j]; Double eDif = eMap.get(i).get(j)-eMap.get(i).get(j); Double nChange = cN*eDif*rain*(0.001/100.0); nMap[i+1][j] += nChange; nMap[i][j] -= nChange; } } if(i==eMap.get(i).size()-1 && j==0) { System.out.print(" SW Corner"); // east neighbor (NORMAL->EAST) if(eMap.get(i).get(j)>eMap.get(i).get(j+1)) { Double cN = nMap[i][j+1]; Double eDif = eMap.get(i).get(j)-eMap.get(i).get(j); Double nChange = cN*eDif*rain*(0.001/100.0); nMap[i][j+1] += nChange; nMap[i][j] -= nChange; } // north neighbor if(eMap.get(i).get(j)>eMap.get(i-1).get(j)) { Double cN = nMap[i-1][j]; Double eDif = eMap.get(i).get(j)-eMap.get(i).get(j); Double nChange = cN*eDif*rain*(0.001/100.0); nMap[i-1][j] += nChange; nMap[i][j] -= nChange; } } if(i==eMap.get(i).size()-1 && j==eMap.get(j).size()-1) { System.out.print(" SE Corner"); // north neighbor if(eMap.get(i).get(j)>eMap.get(i-1).get(j)) { Double cN = nMap[i-1][j]; Double eDif = eMap.get(i).get(j)-eMap.get(i).get(j); Double nChange = cN*eDif*rain*(0.001/100.0); nMap[i-1][j] += nChange; nMap[i][j] -= nChange; } // west neighbor if(eMap.get(i).get(j)>eMap.get(i).get(j-1)) { Double cN = nMap[i][j-1]; Double eDif = eMap.get(i).get(j)-eMap.get(i).get(j); Double nChange = cN*eDif*rain*(0.001/100.0); nMap[i][j-1] += nChange; nMap[i][j] -= nChange; } } if(i==0 && j==eMap.get(j).size()-1) { System.out.print(" NE Corner"); // west neighbor if(eMap.get(i).get(j)>eMap.get(i).get(j-1)) { Double cN = nMap[i][j-1]; Double eDif = eMap.get(i).get(j)-eMap.get(i).get(j); Double nChange = cN*eDif*rain*(0.001/100.0); nMap[i][j-1] += nChange; nMap[i][j] -= nChange; } // south neighbor if(eMap.get(i).get(j)>eMap.get(i+1).get(j)) { Double cN = nMap[i+1][j]; Double eDif = eMap.get(i).get(j)-eMap.get(i).get(j); Double nChange = cN*eDif*rain*(0.001/100.0); nMap[i+1][j] += nChange; nMap[i][j] -= nChange; } } if(i==0 && j>0 && jEAST) if(eMap.get(i).get(j)>eMap.get(i).get(j+1)) { Double cN = nMap[i][j+1]; Double eDif = eMap.get(i).get(j)-eMap.get(i).get(j); Double nChange = cN*eDif*rain*(0.001/100.0); nMap[i][j+1] += nChange; nMap[i][j] -= nChange; } // west neighbor if(eMap.get(i).get(j)>eMap.get(i).get(j-1)) { Double cN = nMap[i][j-1]; Double eDif = eMap.get(i).get(j)-eMap.get(i).get(j); Double nChange = cN*eDif*rain*(0.001/100.0); nMap[i][j-1] += nChange; nMap[i][j] -= nChange; } // south neighbor if(eMap.get(i).get(j)>eMap.get(i+1).get(j)) { Double cN = nMap[i+1][j]; Double eDif = eMap.get(i).get(j)-eMap.get(i).get(j); Double nChange = cN*eDif*rain*(0.001/100.0); nMap[i+1][j] += nChange; nMap[i][j] -= nChange; } } if(i<0 && iEAST) if(eMap.get(i).get(j)>eMap.get(i).get(j+1)) { Double cN = nMap[i][j+1]; Double eDif = eMap.get(i).get(j)-eMap.get(i).get(j); Double nChange = cN*eDif*rain*(0.001/100.0); nMap[i][j+1] += nChange; nMap[i][j] -= nChange; } // north neighbor if(eMap.get(i).get(j)>eMap.get(i-1).get(j)) { Double cN = nMap[i-1][j]; Double eDif = eMap.get(i).get(j)-eMap.get(i).get(j); Double nChange = cN*eDif*rain*(0.001/100.0); nMap[i-1][j] += nChange; nMap[i][j] -= nChange; } // south neighbor if(eMap.get(i).get(j)>eMap.get(i+1).get(j)) { Double cN = nMap[i+1][j]; Double eDif = eMap.get(i).get(j)-eMap.get(i).get(j); Double nChange = cN*eDif*rain*(0.001/100.0); nMap[i+1][j] += nChange; nMap[i][j] -= nChange; } } if(i==eMap.get(i).size()-1 && j>0 && jeMap.get(i-1).get(j)) { Double cN = nMap[i-1][j]; Double eDif = eMap.get(i).get(j)-eMap.get(i).get(j); Double nChange = cN*eDif*rain*(0.001/100.0); nMap[i-1][j] += nChange; nMap[i][j] -= nChange; } // west neighbor if(eMap.get(i).get(j)>eMap.get(i).get(j-1)) { Double cN = nMap[i][j-1]; Double eDif = eMap.get(i).get(j)-eMap.get(i).get(j); Double nChange = cN*eDif*rain*(0.001/100.0); nMap[i][j-1] += nChange; nMap[i][j] -= nChange; } // south neighbor if(eMap.get(i).get(j)>eMap.get(i+1).get(j)) { Double cN = nMap[i+1][j]; Double eDif = eMap.get(i).get(j)-eMap.get(i).get(j); Double nChange = cN*eDif*rain*(0.001/100.0); nMap[i+1][j] += nChange; nMap[i][j] -= nChange; } } if(i>0 && iEAST) if(eMap.get(i).get(j)>eMap.get(i).get(j+1)) { Double cN = nMap[i][j+1]; Double eDif = eMap.get(i).get(j)-eMap.get(i).get(j); Double nChange = cN*eDif*rain*(0.001/100.0); nMap[i][j+1] += nChange; nMap[i][j] -= nChange; } // north neighbor if(eMap.get(i).get(j)>eMap.get(i-1).get(j)) { Double cN = nMap[i-1][j]; Double eDif = eMap.get(i).get(j)-eMap.get(i).get(j); Double nChange = cN*eDif*rain*(0.001/100.0); nMap[i-1][j] += nChange; nMap[i][j] -= nChange; } // west neighbor if(eMap.get(i).get(j)>eMap.get(i).get(j-1)) { Double cN = nMap[i][j-1]; Double eDif = eMap.get(i).get(j)-eMap.get(i).get(j); Double nChange = cN*eDif*rain*(0.001/100.0); nMap[i][j-1] += nChange; nMap[i][j] -= nChange; } } if(i>0 && i0 && jEAST) if(eMap.get(i).get(j)>eMap.get(i).get(j+1)) { Double cN = nMap[i][j+1]; Double eDif = eMap.get(i).get(j)-eMap.get(i).get(j); Double nChange = cN*eDif*rain*(0.001/100.0); nMap[i][j+1] += nChange; nMap[i][j] -= nChange; } // north neighbor if(eMap.get(i).get(j)>eMap.get(i-1).get(j)) { Double cN = nMap[i-1][j]; Double eDif = eMap.get(i).get(j)-eMap.get(i).get(j); Double nChange = cN*eDif*rain*(0.001/100.0); nMap[i-1][j] += nChange; nMap[i][j] -= nChange; } // west neighbor if(eMap.get(i).get(j)>eMap.get(i).get(j-1)) { Double cN = nMap[i][j-1]; Double eDif = eMap.get(i).get(j)-eMap.get(i).get(j); Double nChange = cN*eDif*rain*(0.001/100.0); nMap[i][j-1] += nChange; nMap[i][j] -= nChange; } // south neighbor if(eMap.get(i).get(j)>eMap.get(i+1).get(j)) { Double cN = nMap[i+1][j]; Double eDif = eMap.get(i).get(j)-eMap.get(i).get(j); Double nChange = cN*eDif*rain*(0.001/100.0); nMap[i+1][j] += nChange; nMap[i][j] -= nChange; } } } } } } } private double randomizeRain(double rain) { return rain; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

More Books

Students also viewed these Databases questions