< Sales.java >
public class Sales {
public int PERSON = 4;
public int ITEM = 6;
private int matrix[][] = new int[PERSON+1][ITEM+1];
public Sales(){
for(int person = 0;person<this.PERSON;person++)
matrix[person][0]= person+1;
}/*
public void personsale(){
for(int person =0;person<this.PERSON;person++)
for(int item = 1;item<this.ITEM;item++)
matrix[person][item] = 10;
}*/
public void PersonSale(int person ,int item ,int ammount){
matrix[person][item] = ammount;
}
public void salesPersonTotal(){
for(int person =0 ; person<4 ; person++)
for(int item = 1; item < 6 ; item++)
{
matrix[person][6] = matrix[person][6]+matrix[person][item];
}
}
public void salesItemTotal(){
for(int i=1;i<=this.ITEM;i++)
for(int j=0;j<=this.PERSON-1;j++)
matrix[4][i]=matrix[4][i]+matrix[j][i];
}
public void display(){
this.salesPersonTotal();
this.salesItemTotal();
System.out.println("PERSON\tI1\tI2\tI3\tI4\tI5\ttotal");
for(int person = 0; person<5 ; person++ )
{
for(int row = 0;row<7;row++){
System.out.printf("%d\t",matrix[person][row]);
}
System.out.println();
}
}
}
< SalesTest.java >
import java.util.Scanner;
public class SalesTest {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Sales sales = new Sales();
while(true)
{
System.out.println("Enter person ID (1-4):");
int person = input.nextInt();
if(person<=0||person>sales.PERSON)
break;
System.out.println("Enter Item ID (1-5):");
int item = input.nextInt();
if(item<=0||item>sales.ITEM)
break;
System.out.println("Enter item ammount :");
int ammount = input.nextInt();
sales.PersonSale(person-1, item, ammount);
}
sales.display();
}
}
< OUTPUT >
PRSN I1 I2 I3 I4 I5 total
1 12 15 0 0 0 27
2 0 15 0 0 0 15
3 0 0 0 0 0 0
4 0 0 0 0 0 0
0 12 30 0 0 0 42
No comments:
Post a Comment