All pastes #453372 Raw Edit

Miscellany

public java v1 · immutable
·published 2007-04-22 23:16 UTC
rendered paste body
//This is my program that accesses the Rainfall classimport java.util.Scanner;public class ch8_1{	public static void main(String[] args)	{			int count;		double rainfall[], rainEntered;		rainfall = new double[12];			Scanner input = new Scanner(System.in);				Rainfall rain = new Rainfall();				for (count = 0; count < 12; count++)		{ 			do 			{ 				System.out.print("Enter the rainfall for month " + (count+1) + ": "); 				rainEntered = input.nextDouble(); 			} while (rainEntered < 0); 			 			rain.setRainfall(rainEntered, count); 		} 		 		System.out.println("The total rainfall is " + rain.getTotal()); 		System.out.println("The average rainfall is " + rain.getAverage()); 		//Sysyem.out.println("The month with the most rain is month " + rain.getMost()); 		//Sysyem.out.println("The month with the least rain is month " + rain.getLeast());	}}//This is my Rainfall class.public class Rainfall{ 	private double rainfall[]; 	private double total;  	private double average; 	private double most;  	private double least;  	private int count;   //This is my constructor   public Rainfall()   {   		this.rainfall = new double[12];   }//This is my mutator method   public void setRainfall(double monthRain, int n)   {		rainfall[n] = monthRain;   }//These are my accessor methods   public double getTotal()   {		for (count = 0; count < 12; count++)		{			total+=rainfall[count];		}		return total;   }   public double getAverage()   {		average = getTotal()/12;		return average;   }   public double getMost()   {		return most;   }   public double getLeast()   {		return least;   }}