- String [] names = {"Kojo"," Ama", "Randall", "Abraham", "Rockson", "Adwoa", "Akua", "Lydia", "Mohammed", "Madyou", "Tsidi", "Mary", "Simone", "Chelsea", "Billy", "Khalid", "Kendrick", "Jermaine", "Hailey", "Naima"};
- int[] ages = new int[20];
- float[] heights = new float[20];
- void setup() {
- size(600, 600); // Increased canvas size
- generateData();
- displayData();
- }
- void generateData() {
- // Populate arrays with random data
- for (int i = 0; i < 20; i++) {
- ages[i] = int(random(1, 101)); // Generate random age between 1 and 100
- heights[i] = random(1.0, 2.0); // Generate random height between 1 and 2 meters
- }
- }
- void displayData() {
- // Display data in a tabular format
- background(255);
- textAlign(CENTER, CENTER);
- textSize(16);
- // Headers
- fill(0);
- text("Names", 100, 50);
- text("Age (years)", 300, 50);
- text("Height (meters)", 500, 50);
- // Draw grid lines and display data
- stroke(0);
- for (int i = 0; i < 20; i++) {
- float y = 80 + i * 25;
- line(50, y, 550, y); // Horizontal lines
- if (i < 19) {
- line(50, y + 25, 550, y + 25); // Extra horizontal line
- }
- text(names[i], 100, y + 12); // Index
- text(ages[i], 300, y + 12); // Age
- text(heights[i], 500, y + 12); // Height
- }
- // Vertical lines
- line(50, 50, 50, 575); // Index
- line(250, 50, 250, 575); // Age
- line(450, 50, 450, 575); // Height
- line(550, 50, 550, 575); // End of the table
- save("Assignment6_part1.png");
- }