CSI 311L Lab 8, Spring 2012

American University of Science and Technology · Java Programming Laboratory · 3 pages · Dr. Saeed Raheel

All CSI 311L files
CSI 311L Lab 8, Spring 2012, page 1

Stuck on a question? A tutor can walk you through it.

CSI 311L Lab 8, Spring 2012, page 2 CSI 311L Lab 8, Spring 2012, page 3

More CSI 311L files

Show the text of this lab
American University of Science & Technology Department of Computer Science CSI 311L – Java Programming Lab Spring 2011/2012 Lab Work 8 Problem1: Trace the following java applications: import java.util.Scanner; public class Lab8 { public static void main( String a[] ) { Scanner s = new Scanner( System.in ); double g[][] = new double[20][3]; for( int i = 0; i < 20; i++ ) { System.out.println( "Student # " +(i+1) + " Grades" ); for( int j = 0; j < 3; j++ ) { System.out.print( "Enter grade: " ); g[i][j] = s.nextDouble(); } } int choice; System.out.println( "\nEnter:\n1 to calculate the average of each student\n" + "2 to calculate the average of each exam: " ); choice = s.nextInt(); if( choice == 1 ) avgStd( g ); else if( choice == 2 ) avgExam( g ); 1 } public static void avgStd( double g[][] ) { double sum = 0.0, average; for( int i = 0; i < 20; i++ ) { sum = 0.0; for( int j = 0; j < 3; j++ ) sum += g[i][j]; average = sum / 3; System.out.println( "Average of student # " +(i+1) + " = " +average ); } } public static void avgExam( double g[][] ) { double sum = 0.0, average; for( int j = 0; j < 3; j++ ) { sum = 0.0; for( int i = 0; i < 20; i++ ) sum += g[i][j]; average = sum / 20; System.out.println( "Average of exam # " +(j+1) + " = " +average ); } } } 2 Problem 2 : Write the Location class defined as follow:  A Location is defined by block, floor.  Provide a default constructor and all arguments constructor.  Provide set and get methods.  toString method Write a driver program to test the class functionality. Write the coordinator class defined as follow:  A coordinator is defined by id, Fname, and Lname.  Provide a default constructor and all arguments constructor.  Provide set and get methods.  toString method Write the Department class defined as follows:  A Department is defined to have a number, a name, a location and a coordinator.  Dept_count keeps track of the number of departments.  Provide constructor.  Provide set and get methods.  toString.  finalizer. Write a driver program to input data about N Departments and prompt the use to choose from the following menu: 1. List all departments’ locations. 2. List the coordinator data for a specific department. 3. Change a specific department location. 4. Exit 3