0% found this document useful (0 votes)
41 views

Lab Practical 7

The document contains code for three Java programs. The first program prompts the user to input monthly rainfall amounts over 12 months and calculates the total rainfall, average rainfall, and months with the most and least rainfall. The second program prompts the user to input sales amounts for multiple salespeople and calculates their salaries, grouping them into salary ranges. The third program calculates the sum of prices in an array and displays prices less than 5.

Uploaded by

Yani
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Lab Practical 7

The document contains code for three Java programs. The first program prompts the user to input monthly rainfall amounts over 12 months and calculates the total rainfall, average rainfall, and months with the most and least rainfall. The second program prompts the user to input sales amounts for multiple salespeople and calculates their salaries, grouping them into salary ranges. The third program calculates the sum of prices in an array and displays prices less than 5.

Uploaded by

Yani
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Lab practical 7

1. public static void main (String[] args){


Scanner kenny = new Scanner(System.in);
double rain[]=new double[13];
double sum = 0;
double avg =0;
double most =0;
double least =0;

System.out.println("Your local weather man here getting paid to tell you the wrong weather!!");
System.out.println("");
System.out.println("Please enter in the following rainfall for the months ahead: ");
System.out.println("Month\tRainfall (In inches)");
System.out.print("January: ");
rain [0] = kenny.nextDouble();
System.out.print("February: ");
rain [1] = kenny.nextDouble();
System.out.print("March: ");
rain [2] = kenny.nextDouble();
System.out.print("April: ");
rain [4] = kenny.nextDouble();
System.out.print("May: ");
rain [5] = kenny.nextDouble();
System.out.print("June: ");
rain [6] = kenny.nextDouble();
System.out.print("July: ");
rain [7] = kenny.nextDouble();
System.out.print("August: ");
rain [8] = kenny.nextDouble();
System.out.print("September: ");
rain [9] = kenny.nextDouble();
System.out.print("October: ");
rain [10] = kenny.nextDouble();
System.out.print("November: ");
rain [11] = kenny.nextDouble();
System.out.print("December: ");
rain [12] = kenny.nextDouble();

//(Or rain[] = 1,2,3,4,5,6,7,8,9,10,11,12);

sum = rain[0] + rain[1] + rain[2] + rain[3] + rain[4] + rain[5] + rain[6] + rain[6] + rain[7] + rain[8] + rain[9] +
rain[10] + rain[11] + rain[12] ;
avg = (rain[0] + rain[1] + rain[2] + rain[3] + rain[4] + rain[5] + rain[6] + rain[6] + rain[7] + rain[8] + rain[9]
+ rain[10] + rain[11] + rain[12]) / 12;

System.out.println("The sum of all the rain is: " + sum);


System.out.println("The average rainfall was:" + avg + " inches");
System.out.print("The month with the most rain was: ");

}
private static void getMaxValue(double[] rain) {

getMaxValue(rain);
System.out.println(getMaxValue(rain));

System.out.println("The month with the least rain was: ");


}
private static void getMinValue(double[] rain) {

getMinValue(rain);
System.out.println(getMaxValue(rain));

}}

2. public static void main(String[] args)

{int index;

double salary;

int grossSales=1;

int[] salaryRange=new int[10];

Scanner in=new Scanner(System.in);

for(index = 0; index <10; index++)

salaryRange[index] = 0;

System.out.print("Enter the saleman's gross sales (<=0 to END): ");

grossSales=in.nextInt();

while(grossSales>0)

{salary=getSalary(grossSales);

setRange(salaryRange,salary);

System.out.print("Enter the saleman's gross sales (<=0 to END): ");


grossSales=in.nextInt();

for(index=0; index<8; index++)

System.out.println("$"+(index*100+200)+"-$"+((index+1)*100+200-1 )+": "+salaryRange[index]);

System.out.println("$1000 and over "+salaryRange[8]);

public static int getSalary(int grossSales)

{int salary;

salary=(int)(200+(grossSales*(9./100.)));

return salary;

public static void setRange(int salaryRange[],double salary)

{int index=(int)((salary/100)-2);

if(salary>1000)

salaryRange[8]+=1;

else

salaryRange[index]+=1;

3. public static void main(String[] args)


{

double[] prices = { 2.34, 7.89, 1.34, 10.29, 21.23, 13.50, 80.69, 56.79, 23.19, 10.99,

70.89, 41.26, 8.92, 3.56, 7.66, 9.55, 3.77, 24.90, 82.71,


2.81};

System.out.println("The sum is: "+ getSum(prices));

displayLessThanFive(prices);

public static double getSum(double[] array){

double sum = 0;

for(int i=0;i<array.length;i++){

sum+=array[i];

return sum;

public static void displayLessThanFive(double[] array){

System.out.println("Values lower than 5.00:");

for(int i = 0;i<array.length;i++){

if(array[i] < 5){

System.out.println(array[i]);

You might also like