Lab Report #11: Using 2-Dimensional Arrays in Java, Study Guides, Projects, Research of C programming

Object-oriented programming (OOP) refers to a type of computer programming (software design) in which programmers define the data type of a data structure, and also the types of operations (functions) that can be applied to the data structure.

Typology: Study Guides, Projects, Research

2019/2020

Uploaded on 01/11/2020

samia-khan-2
samia-khan-2 🇵🇸

4.8

(4)

11 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
LAB REPORT: #11
SUBJECT: Using 2-dimensional
arrays
SUBMITTED BY: SAMIA
REG. NO: 17JZBCS0022
DEPARTMENT: CS&IT
TITLE: More practice writing
classes that represent objects
pf3
pf4

Partial preview of the text

Download Lab Report #11: Using 2-Dimensional Arrays in Java and more Study Guides, Projects, Research C programming in PDF only on Docsity!

LAB REPORT:

SUBJECT : Using 2-dimensional

arrays

SUBMITTED BY: SAMIA

REG. NO: 17JZBCS

DEPARTMENT: CS&IT

TITLE: More practice writing

classes that represent objects

Exercise 1:

  • In BlueJ, create a new project called Lab
  • Create a class called SalesDemo with a sta9c method called checkSales
  • In checkSales , create a 2-dimensional integer array (5 by 10) called sales.
  • This array will hold the number of products sold for 5 salespeople and 10 products (say, for a given month)

SOLUTION:

Exercise 2:

  • Fill the sales array with random numbers between 0 and 499 Representing the sales:
  • Create a Random object (don't forget to import the class).
  • Use nested for loops to store a random value for each person and product
  • Don't use literals like 5 or 10 in the loops – use the length of a row or column.

SOLUTION:

Exercise 3:

  • After filling the array, write another nested loop that prints the

Exercise 6:

  • In the SalesDemo class, after printing the sales table you created, create a SalesAnalyzer object using that table.
  • Then, calling the totalForPerson method, print the sales total for the sales people at index 2 and index 4: The total sales for sales person 2 is xxx The total sales for sales person 4 is xxx

SOLUTION:

Exercise 7:

  • Add another method in the SalesAnalyzer class called totalForProduct that accepts a product index and returns the total sales for that product.
  • This will sum a column instead of a row.
  • Add a call to totalForProduct in SalesDemo showing the total sales for the product at index 8. The total sales of product 8 is xxx

SOLUTION: