Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8347695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:26:40+00:00 2026-06-09T07:26:40+00:00

I have an assignment for uni where I have to create a Java program

  • 0

I have an assignment for uni where I have to create a Java program that produces a random pairing customers and their transaction totals.

It comes in two parts where the first part produces the customers and their transactions like so:

Customer ID, Transaction Value
1, 74.36 
1, 44.98 
3, 6.44
0, 19.13
3, 59.44
2, 81.56
0, 87.21
4, 40.9
1, 42.11
3, 66.05

the second summarises the total number of transactions for each customer like so:

Customer: 1 Transactions: 3.0
Customer: 1 Transactions: 3.0
Customer: 3 Transactions: 3.0
Customer: 0 Transactions: 2.0
Customer: 3 Transactions: 3.0
Customer: 2 Transactions: 1.0
Customer: 0 Transactions: 2.0
Customer: 4 Transactions: 1.0
Customer: 1 Transactions: 3.0
Customer: 3 Transactions: 3.0

My problem is the second section should only produce each customer ID once i.e 1,3,0,2,4. I can only do this using int and double variables and without creating any other arrays or structures. My code can be found below.

 import java.util.*;

 public class Assignment3 {
   public static long studentNumber=1234567; 

   public static int customerID[];
   public static double transactionValue[];

   public static void initialiseData(int size) {
     customerID = new int[size];
     transactionValue = new double[size];

     Random rand = new Random(studentNumber);
     for (int i=0; i<size; i++) {
       customerID[i] = rand.nextInt(size / 2);
       transactionValue[i] = rand.nextInt(10000) / 100.0;
     }
   }

   public static void main(String args[]) {
     int size=10;

    initialiseData(size);

    // Your code should only be below this line
    double transaction = 0;
    int customer = 0;
    int customer_Total = 0;
    int count = 0;
    int customer_count = 0;
    double transaction_Total = 0;

    System.out.println("Customer ID, Transaction Value");

    for (size= 0; size < customerID.length; size++) {
    customer= customerID[size];
    transaction= transactionValue[size];
    System.out.println(customer + ", " + transaction);

    }

    System.out.println("");

    for(customer_count = 0; customer_count < customerID.length; customer_count++) {
      transaction_Total= 0;
      customer_Total = customerID[customer_count];
      count = customerID[customer_count];
      //System.out.println(count);

      for (int customer_count2 = 0;
           customer_count2 < customerID.length;
           customer_count2++) {                         
        if (customer_Total == customerID[customer_count2]) {
          transaction_Total++;

          //System.out.println(customer_count2);
        }
      }

      System.out.println("Customer: "+ customer_Total + " " +
                         "Transactions: " + transaction_Total); 
    }

    // Your code should not be below this line

  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T07:26:41+00:00Added an answer on June 9, 2026 at 7:26 am

    EDIT: in this code:

    for(customer_count = 0; customer_count < customerID.length; customer_count++) {
      transaction_Total= 0;
      customer_Total = customerID[customer_count];
      count = customerID[customer_count];
      //System.out.println(count);
    
      for (int customer_count2 = 0;
           customer_count2 < customerID.length;
           customer_count2++) {                         
        if (customer_Total == customerID[customer_count2]) {
          transaction_Total++;
    
          //System.out.println(customer_count2);
        }
      }
    
      System.out.println("Customer: "+ customer_Total + " " +
                         "Transactions: " + transaction_Total); 
    }
    

    add the following after ‘transaction_Total= 0;’:

    int wasBefore = 0; //are you allowed to use boolean variables?
    for (int customer_count3 = 0;
           customer_count3 < customer_count;
           customer_count3++) {                         
        if (customer_Total == customerID[customer_count3]) {
          wasBefore = 1;
        }
    }
    if (wasBefore==1) {continue;}
    

    In this way you still get random order of customers without repreating them

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an assignment to create a program that converts deci (-32,768 through 32,767)
I have an assignment to create a paint program in Java. I have managed
I have to program a simple threaded program with MFC/C++ for a uni assignment.
I have an assignment in which I need to create a function that tells
For my Uni assignment I have to create a fast action paced networked game
For a uni assignment I'm writing a java program which needs to save and
I'm working on an assignment for uni where I have to create a Breakout
This is uni assignment and I have already done some stuff. Please go to
so we're doing this assignment at Uni and i have a serious craving to
I have an assignment to create a GUI using MATLAB GUIDE and am having

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.