| | |
help with 2-dimensional array, please see code
![]() |
•
•
Join Date: Jun 2007
Posts: 5
Reputation:
Solved Threads: 0
here is the question. i have done half of it.
a company has 4 sales persons, who sell 5 different products, once a day each salesperson passes a slip for each product sold.
the slip contains: sales person no., product no., total cash value for the products sold that day. the salespersons passes between (0 and 5) slips per day. Assume htat the information from the last slips for last month (30) is available. write a program that will read all the information f and summarize ie., total sales by sales person by product. all total sales should be stored in 2-dimensional sales.
after processing all the information on last month, displaying the result in tabular with each column representing a particular salesperson and each row representing a particular product.
gross total each row to get the total sales of each product for last month. gross total each column to get the total sales per salesperson for last month.
(the part i cant do is getting the gross total and tabulating them).
here is the code so far.
import java.io.*;
public class SalesPerson {
int number;
Slip slips[];
Slip current;
InputStreamReader isr;
BufferedReader stdin;
public SalesPerson(int number_in){
number = number_in;
slips = new Slip[30];
isr = new InputStreamReader(System.in);
stdin = new BufferedReader(isr);
}
public void read(){
System.out.println("Information for person no. "+number);
System.out.println();
for(int i = 0; i < 3; i++){
System.out.println("Day "+(i+1));
current = new Slip(number);
for(int j = 0; j < 2; j++){
if(j == 0)
System.out.println("Enter product numbers");
else
System.out.println("Enter product cash values");
for(int k = 0; k < 5; k++){
try {
current.products[j][k] = Double.parseDouble(stdin.readLine());
}
catch(NumberFormatException ex) {
System.out.println(ex.getMessage());
}
catch(IOException ex) {
System.out.println(ex.getMessage());
}
}
}
slips[i] = current;
}
}
public void print(){
System.out.println("Information for person no. "+number);
System.out.println();
for(int i = 0; i < 3; i++){
current = slips[i];
System.out.println("Day "+(i+1));
for(int j = 0; j < 2; j++){
if(j == 0)
System.out.println("Product numbers");
else
System.out.println("Product cash values");
for(int k = 0; k < 5; k++){
System.out.print(current.products[j][k]+" ");
}
System.out.println();
}
System.out.println();
}
}
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
import java.io.*;
public class Slip {
int personNum;
double products[][];
public Slip(int pn) {
personNum = pn;
products = new double[2][5];
}
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
import java.io.*;
public class Test1 {
public static SalesPerson person1, person2, person3, person4;
public Test1(){
person1 = new SalesPerson(1);
person2 = new SalesPerson(2);
}
public static void main(String[] args){
Test1 test1 = new Test1();
person1.read();
person1.print();
}
}
a company has 4 sales persons, who sell 5 different products, once a day each salesperson passes a slip for each product sold.
the slip contains: sales person no., product no., total cash value for the products sold that day. the salespersons passes between (0 and 5) slips per day. Assume htat the information from the last slips for last month (30) is available. write a program that will read all the information f and summarize ie., total sales by sales person by product. all total sales should be stored in 2-dimensional sales.
after processing all the information on last month, displaying the result in tabular with each column representing a particular salesperson and each row representing a particular product.
gross total each row to get the total sales of each product for last month. gross total each column to get the total sales per salesperson for last month.
(the part i cant do is getting the gross total and tabulating them).
here is the code so far.
import java.io.*;
public class SalesPerson {
int number;
Slip slips[];
Slip current;
InputStreamReader isr;
BufferedReader stdin;
public SalesPerson(int number_in){
number = number_in;
slips = new Slip[30];
isr = new InputStreamReader(System.in);
stdin = new BufferedReader(isr);
}
public void read(){
System.out.println("Information for person no. "+number);
System.out.println();
for(int i = 0; i < 3; i++){
System.out.println("Day "+(i+1));
current = new Slip(number);
for(int j = 0; j < 2; j++){
if(j == 0)
System.out.println("Enter product numbers");
else
System.out.println("Enter product cash values");
for(int k = 0; k < 5; k++){
try {
current.products[j][k] = Double.parseDouble(stdin.readLine());
}
catch(NumberFormatException ex) {
System.out.println(ex.getMessage());
}
catch(IOException ex) {
System.out.println(ex.getMessage());
}
}
}
slips[i] = current;
}
}
public void print(){
System.out.println("Information for person no. "+number);
System.out.println();
for(int i = 0; i < 3; i++){
current = slips[i];
System.out.println("Day "+(i+1));
for(int j = 0; j < 2; j++){
if(j == 0)
System.out.println("Product numbers");
else
System.out.println("Product cash values");
for(int k = 0; k < 5; k++){
System.out.print(current.products[j][k]+" ");
}
System.out.println();
}
System.out.println();
}
}
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
import java.io.*;
public class Slip {
int personNum;
double products[][];
public Slip(int pn) {
personNum = pn;
products = new double[2][5];
}
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
import java.io.*;
public class Test1 {
public static SalesPerson person1, person2, person3, person4;
public Test1(){
person1 = new SalesPerson(1);
person2 = new SalesPerson(2);
}
public static void main(String[] args){
Test1 test1 = new Test1();
person1.read();
person1.print();
}
}
![]() |
Similar Threads
- Need Help With two-dimensional array (VB.NET)
- random numbers, and 2 dimensional array (C++)
- displaying two dimensional array in columns help (C++)
- Passing multi-dimensional array (C)
- 3d to 1d Array Conversion (C++)
- Validation with js of two dimensional array (JavaScript / DHTML / AJAX)
- three dimensional arrays (PHP)
- How to put the random integer between 1-100 into the 2 dimensions array (5x5 metrix) (C++)
- Need help passing a multi-dimensional array (C++)
- Help with a 2 Dimensional Array (C++)
Other Threads in the Java Forum
- Previous Thread: Gregorian Calender Problem
- Next Thread: Doctor online discussion form
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary blackberry block bluetooth character chat class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing test textfields threads time title tree tutorial-sample ubuntu update windows working





