Facebook
From Adjowa Asamoah, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 137
  1. String [] names = {"Kojo"," Ama", "Randall", "Abraham", "Rockson", "Adwoa", "Akua", "Lydia", "Mohammed", "Madyou", "Tsidi", "Mary", "Simone", "Chelsea", "Billy", "Khalid", "Kendrick", "Jermaine", "Hailey", "Naima"};
  2. int[] ages = new int[20];
  3. float[] heights = new float[20];
  4.  
  5. void setup() {
  6.   size(600, 600); // Increased canvas size
  7.   generateData();
  8.   displayData();
  9. }
  10.  
  11. void generateData() {
  12.   // Populate arrays with random data
  13.   for (int i = 0; i < 20; i++) {
  14.     ages[i] = int(random(1, 101)); // Generate random age between 1 and 100
  15.     heights[i] = random(1.0, 2.0); // Generate random height between 1 and 2 meters
  16.   }
  17. }
  18.  
  19. void displayData() {
  20.   // Display data in a tabular format
  21.   background(255);
  22.   textAlign(CENTER, CENTER);
  23.   textSize(16);
  24.  
  25.   // Headers
  26.   fill(0);
  27.   text("Names", 100, 50);
  28.   text("Age (years)", 300, 50);
  29.   text("Height (meters)", 500, 50);
  30.  
  31.   // Draw grid lines and display data
  32.   stroke(0);
  33.   for (int i = 0; i < 20; i++) {
  34.     float y = 80 + i * 25;
  35.     line(50, y, 550, y); // Horizontal lines
  36.     if (i < 19) {
  37.       line(50, y + 25, 550, y + 25); // Extra horizontal line
  38.     }
  39.     text(names[i], 100, y + 12); // Index
  40.     text(ages[i], 300, y + 12); // Age
  41.     text(heights[i], 500, y + 12); // Height
  42.   }
  43.  
  44.   // Vertical lines
  45.   line(50, 50, 50, 575); // Index
  46.   line(250, 50, 250, 575); // Age
  47.   line(450, 50, 450, 575); // Height
  48.   line(550, 50, 550, 575); // End of the table
  49.  
  50.   save("Assignment6_part1.png");
  51. }