I need help creating a
ULM Class Diagram,
please. I have included my 3 classes of code below (UserInput, Participant, and Exchange Results).
// Participant Class
class Participant
{
// Participants
private String name;
private int age;
public Participant(String name, int age)
{
this.name = name;
this.age = age;
}
// Name and Age Getters
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
// Name and Age Setters
public void setAge(int age)
{
this.age = age;
}
public void setName(String name)
{
this.name = name;
}
}
import java.util.Random;
// ExchangeResults Class
public class ExchangeResults
{
public static void main(String[] args)
{
// Input Participants From The User
UserInput userinput = new UserInput();
Participant[] participants = userinput.inputParticipants();
// Shuffle The Array Of Participants
shufflepParticipants(participants);
// Print Gifts Exchanged
System.out.println(" Christmas Gift Exchange Results");
System.out.println("~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~");
for (int i = 0; i < participants.length="" 2;="">
{
Participant p1 = participants[i];
Participant p2 = participants[participants.length - i - 1];
System.out.printf("%s (age: %d) will echange a gift with %s (age: %d)\n",
p1.getName(), p1.getAge(), p2.getName(), p2.getAge());
}
}
// Shuffle Array Of Participants
public static void shufflepParticipants(Participant[] participants)
{
Random rand = new Random();
Participant temp;
// Shuffle Array
for (int i = participants.length - 1; i > 0; i--)
{
int index = rand.nextInt(i + 1);
temp = participants[index];
participants[index] = participants[i];
participants[i] = temp;
}
}
}
// UserInput Class
import java.util.Scanner;
public class UserInput {
Scanner input = new Scanner(System.in);
Participant[] inputParticipants()
{
System.out.println("* * * * CHRISTMAS GIFT EXCHANGE * * * *");
// Input Number Of Participants
System.out.print("How many people are participating in the exchange? ");
int numParticipants = Integer.parseInt(input.nextLine());
System.out.println();
// While Number Of Participants Is Odd,
// Keep Inputting Number Of Participants
while (numParticipants % 2 == 1)
{
System.out.println();
System.out.println("There must be an even number of people participating.");
System.out.println("(Add an 'ELF' if needed.)");
System.out.println();
System.out.print("How many people are participating in the exchange? ");
numParticipants = Integer.parseInt(input.nextLine());
System.out.println();
}
// Initialize Array Of Participants
Participant[] participants = new Participant[numParticipants];
// Input All Particicpants
for (int i = 0; i < participants.length;="">
{
System.out.printf("Participant #%d", i + 1);
System.out.print("\n-------------------------\n");
// Input Name And Age
System.out.print("Name: ");
String name = input.nextLine();
System.out.print("Age: ");
int age = Integer.parseInt(input.nextLine());
participants[i] = new Participant(name, age);
System.out.println();
}
// Return Array Of Participants
return participants;
}
}