NAME MONDAY TUESDAY WEDNESDAY THURSDAY
Kwame 20 25 25 30
Adwoa 10 10 40 35
Ama 30 32 32 42
TOTAL
The table above represents the sales of personnel’s in a company for a period of four days. As a programmer write a Java program to populate all sales as shown in the tables above and calculate the total sales made in each day by the sales personals.
b. Using code snippets briefly explain the difference between Implicit casting (type widening) and Explicit casting (type narrowing) in java programming.
solution:
a.
Java program:
public class Main
{
public static void main(String[] args)
{
int i, j, days = 4, salesPersonals = 3;
int sales[][] = {{20, 25, 25, 30}, {10, 10, 40, 35},
{30, 32, 32, 42}}; //sales data
int totalSales[] = new int[days]; //a new array to
store total sales on each day
for(i=0; i<days; i++) //lpop over all the
days
{
for(j=0; j<salesPersonals; j++) //loop over all the
sales personals
{
totalSales[i] += sales[j][i]; //add sales of each
sales personals
}
//uncomment below to print total sales for each
day
//System.out.println(totalSales[i]);
}
}
}
Screenshot:
b.
|
please give me thumb up
Get Answers For Free
Most questions answered within 1 hours.