kotlin – Multi-dimensional arrays exercise: Introduce married couples to each other

Following idea: There a three married couples and they have to be introduced another.

I have implemented this solution:

val couples = arrayOf(
    arrayOf("Michael", "Sandy"),
    arrayOf("Frank", "Claudia"),
    arrayOf("Andrew", "Michelle")
)

for (i in 0 until couples.size) {
    for (j in 0 until couples(0).size) {
        var currentPerson = couples(i)(j)

        for (k in i + 1 until couples.size) {
           for (l in 0 until couples(0).size) {
               println("$currentPerson, this is ${couples(k)(l)}.")
           }
        }
     }
 }

Results in:

Michael, this is Frank.
Michael, this is Claudia.
Michael, this is Andrew.
Michael, this is Michelle.
Sandy, this is Frank.
Sandy, this is Claudia.
Sandy, this is Andrew.
Sandy, this is Michelle.
Frank, this is Andrew.
Frank, this is Michelle.
Claudia, this is Andrew.
Claudia, this is Michelle.

So I guess it’s formally correct. But using that many loops isn’t great.

Is there a way to reduce the amount of loops? Or is there a completely different approach to solve the problem?

Introduce My Self "Tuan M Sallay"

Dear all,

Greetings…!!!

Hope all doing well and im a newbie to this forum. i have gone through few forums and Beermoney as well. this looks pretty cool. keep up good work Mr. B

In the meantime thanks for accepting and thanks for time to read this.

Have a great day ahead…!!!
Cheers…!!!

Thanks & Kind Regards
Tuan M Sallay

Sample Breakout Game to introduce students who have covered the AP CS A syllabus to Java Graphics:

I am an AP CS A teacher but as the syllabus does not include Graphics this is really my first time in using Java graphics. I am looking to produce a project not far above the realms of the AP CS A syllabus (classes, inheritance, interfaces, abstract) that will give students an insight into how to produce their own simple games using Java graphics.

I have seen many tutorials on the net but so far nothing as simple as this that I can get my head round and actually truly understand.

Any suggestions on how I could improve the code below without getting too complicated?

Notes:
I am not particularly happy with the infinite loops for example.

Any suggestions would be appreciated.

public class GameTest{
    public static void main(String() args) {
        Game pg = new Game();
    }
}
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import java.awt.event.KeyListener;

public class Game extends JFrame implements KeyListener{

    private final int gWidth = 500;
    private final int gHeight = 400;
    private Dimension screenSize;
        
    private Image dbImage;
    private Graphics dbGraphics;
    
    private Ball ball;
    private Brick()() bricks;
    private Paddle paddle;
    
    private Thread ballThread;
    private Thread paddleThread;
    
    public Game() {
        screenSize = new Dimension(gWidth, gHeight);
        this.setTitle("Let's Play Game!");
        this.setSize(screenSize);
        this.setResizable(false);
        this.setVisible(true);
        this.setBackground(Color.BLACK);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        addKeyListener(this);
        
        bricks = new Brick(2)(10);
        for (int row = 0; row < bricks.length ; row++) {
            for (int col = 0; col < bricks(0).length ; col++) {
                bricks(row)(col) = new Brick((col*50), (100 + (row * 20)));
            }
        }
        
        paddle = new Paddle(450, 390);
        
        ball = new Ball(250, 200, bricks, paddle);
        ballThread = new Thread(ball);
        ballThread.start();
        paddleThread = new Thread(paddle);
        paddleThread.start();
    }
    
    public void paint(Graphics g) {
        dbImage = createImage(getWidth(), getHeight());
        dbGraphics = dbImage.getGraphics();
        draw(dbGraphics);
        g.drawImage(dbImage, 0, 0, this);
    }
        
    public void draw(Graphics g) {
        ball.draw(g);
        paddle.draw(g);
        
        boolean allBricksGone = true;
        for ( Brick() row : bricks ) {
            for (Brick brick : row ) {
                if (brick.getActive()) {
                    brick.draw(g);
                    allBricksGone = false;
                }
            }
        }
        
        if (allBricksGone)
            System.exit(0);
        
        g.setColor(Color.WHITE);
        
        repaint();
    }   
    
    public void keyPressed(KeyEvent e) {
        paddle.keyPressed(e);
    }
        
    public void keyReleased(KeyEvent e) {
        paddle.keyReleased(e);
    }
    
    public void keyTyped(KeyEvent e) {}
}
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.Random;

public class Ball implements Runnable {
    
    private int xDirection, yDirection;
    
    private Paddle paddle;
    
    private Brick()() bricks;

    private Rectangle ballRect;
    
    public Ball(int x, int y, Brick()() bricks, Paddle paddle){
        Random r = new Random();
        
        int rXDir = r.nextInt(1);  
        if (rXDir == 0)
            rXDir--;
            
        setXDirection(rXDir);
            
        int rYDir = r.nextInt(1);
            
        if (rYDir == 0)
            rYDir--;
                    
        setYDirection(rYDir);
        
        ballRect = new Rectangle(x, y, 15, 15);
        
        this.bricks = bricks;
        
        this.paddle = paddle;
    }
    
    public void setXDirection(int xDir){
        xDirection = xDir;
    }
    
    public void setYDirection(int yDir){
        yDirection = yDir;
    }
    
    public void draw(Graphics g) {
        g.setColor(Color.PINK);
        g.fillRect(ballRect.x, ballRect.y, ballRect.width, ballRect.height);
    }
    
    public void collision(){
        if(ballRect.intersects(paddle.getpaddleRect()))
            setYDirection(-1);
            
        for (int row = 0; row < bricks.length ; row++) {
            for (int col = 0; col < bricks(0).length ; col++) {
                if(bricks(row)(col).getActive() && ballRect.intersects(bricks(row)(col).getbrickRect())) {
                    bricks(row)(col).setInactive();
                    setYDirection(-yDirection);
                    break;
                }
            }
        }
    }
                
    public void move() {
        ballRect.x += xDirection;
        ballRect.y += yDirection;
            
        if (ballRect.x <= 5)
            setXDirection(+1);
            
        if (ballRect.x >= 480)
            setXDirection(-1);
        
        if (ballRect.y <= 30)
            setYDirection(+1);
        
        if (ballRect.y >= 385)
            setYDirection(-1);
    }
    
    public void run() {
        try {
            while(true) {
                move();
                collision();
                Thread.sleep(4);
            }
        }
        catch(Exception e) { 
            System.err.println(e.getMessage()); 
        }
    }
}
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;


public class Paddle implements Runnable{

    private int xDirection;

    private Rectangle paddleRect;

    public Paddle(int x, int y){
        paddleRect = new Rectangle(x, y, 50, 10);
    }
    
    public Rectangle getpaddleRect(){
        return paddleRect;
    }

    public void keyPressed(KeyEvent e) {
        if(e.getKeyCode() == KeyEvent.VK_LEFT)
            setXDirection(-1);
                
        if(e.getKeyCode() == KeyEvent.VK_RIGHT)
            setXDirection(1);
    }
    
    public void keyReleased(KeyEvent e) {
        if(e.getKeyCode() == KeyEvent.VK_LEFT || e.getKeyCode() == KeyEvent.VK_RIGHT)
            setXDirection(0);
    }

    public void setXDirection(int xDir) {
        xDirection = xDir;
    }
    
    public void move() {
        paddleRect.x += xDirection;
        if (paddleRect.x <= 10)
            paddleRect.x = 10;
        if (paddleRect.x >= 440)
            paddleRect.x = 440;
    }
    
    public void draw(Graphics g) {
        g.setColor(Color.CYAN);
        g.fillRect(paddleRect.x, paddleRect.y, paddleRect.width, paddleRect.height);
    }
        
    public void run() {
        try {
            while(true) {
                move();
                Thread.sleep(2);
            }
        }
        catch(Exception e) { 
            System.err.println(e.getMessage()); 
        }
    }
}
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;

public class Brick {
    
    private int x, y;

    private boolean active;

    private Rectangle brickRect;


    public Brick(int xVal, int yVal){
        x = xVal;
        y = yVal;
        brickRect = new Rectangle(x, y, 45, 15);
        active = true;
    }
    
    public boolean getActive(){
        return active;
    }

    public Rectangle getbrickRect(){
        return brickRect;
    }

    public void setInactive(){
        active = false;
    }
    
    public void draw(Graphics g) {
        g.setColor(Color.WHITE);
        g.fillRect(brickRect.x, brickRect.y, brickRect.width, brickRect.height);
    }
}

forms – how to introduce control in a process divided into different screens / sections?

We need to introduce some control in a very extensive process that is completed in different days.

Today these processes are divided into different sections / modules. Each section is a screen on a web page.

We need to group all those screens in a main section that contains the different sections and screens corresponding to that flow. (like creating a large flow but in different modules).

Some of the sections cannot be executed, without the previous one being completed. How can we keep track of that process?

Is it a good practice to lock points in the menu and unlock them as the previous points have been completed?

Is it better to unify all modules in one wizard with more than 12 steps?

I Introduce Myself

 

new players – When and how should I introduce my kids to RPGs?

There’s only a very short time I believe that it’s too early to begin playing with your kids. When’s the first time you picked them up and had them pretend they were an airplane while you swung them around?

I know, not quite a roleplaying game. However, very early on you build the foundation of playing games with your child, and there’s absolutely no reason ‘Let’s pretend’ can’t be a huge part of that. At 3-4 when your kids are pretending to shoot bows and arrows, play with him/her. Dice aren’t even neccessary. At that point, you’re roleplaying. Your child the bit of an archer, and you of whatever else. Maybe you’re both pretending to shoot deer as my nephew and his father did.

Move on from there as they’re ready. You can introduce settings, creatures, let them play out and pretend they’re in their favorite Disney movies or the like. Can introduce the concept of not -always- succeeding, show them how in the movies that it’s more exciting when the hero isn’t perfect. Sure he always wins, but, there’s usually a hold up. If he rescue’d the princess right off, there wouldn’t be much entertaining about it would there? Aladdin never would have met the genie if he could have just hooked up with the princess, for example. Still don’t need dice, or character sheets, at this point in time, use a coin, or play rock paper scissors.

When they’re ready, you can start introducing the concept of statistics, when you pretend you’re ‘blah’, he’s -really- strong, right? So, when he tries to do things that require alot of strength, he has an easier time, right? …

I could probably babble on the better half of a novel, but, I think the point is well on the way to leading to many more possibilities. Hope this helps!

Let me introduce myself

Hello everyone here, I am glad to be a member of this global network. My name is Azra Djulic. I am from Bosnia and Herzegovina. As a bachelor of law and master of international relations and diplomacy, I am passionate about responding to legal inquiries and helping people solve their everyday legal issues. I provide legal consultancy services to my clients with regard to international law. I am here to gain new experience and meet new friends worldwide.

dnd 5e – How do I introduce my BBEG’s power without my pcs rushing in to fight them?

I made a homebrew creature that’s supposed to be impossible for them to fight at the moment as that creature is the BBEG. I wanted to show the strength gap between the pcs start and how strong they will have gotten at the end, but I doubt that they will back away from fighting the creature.

How do I introduce my BBEG’s power without my pcs rushing in to fight them?

python 3.x – Image shows normally on simple program, but appears blank when I introduce it to mine (Tkinter)

I am trying to show a graph on the screen that I just plotted using matplotlib on python.
Basically, my program receives a bunch of parameters and then makes a graph, that should be displayed on screen.
Since I am new to tkinter, I made a simple program to see if the code worked:

from tkinter import *
from PIL import ImageTk, Image
root=Tk()

my_img1=ImageTk.PhotoImage(Image.open("plot.png"))   
my_label=Label(image=my_img1)
my_label.grid(row=0,column=0,columnspan=3)

mainloop()  

This works just fine.

However, when I introduce it into my actual program:

def graficar_fracciones():
    
    lista_de_ERRtotal=()
    for i in range(1,50):
        agregar=ERR_total(i)
        if agregar <0:
            lista_de_ERRtotal.append(0)
        else:
            lista_de_ERRtotal.append(agregar)
    plt.figure(figsize=(1.5,1))
    plt.plot(lista_de_ERRtotal)
    plt.xlabel("Cantidad de fracciones")
    plt.ylabel('ERR Total')
    plt.savefig('plot.png', dpi=300, bbox_inches='tight')
    my_img1=ImageTk.PhotoImage(Image.open("plot.png"))   
    my_label=Label(image=my_img1)
    my_label.grid(row=0,column=0,columnspan=3) 
    return

This function graphs the plot, then saves it. Then I open that plot and try to show it on screen, but it just shows blank.
Why could this be happening? I have checked some similar posts, but haven’t been able to find an answer.

Please allow me to introduce myself.

Hello dear friends,
SEMrush

My name is Daniel, I’m 37 and live in Spain.

I start making websites back in 98 on Tripod, love to design UI and hand code static web sites don’t know to program yet because I didn’t need to, but I am learning now so try to understand the basics right now, I “fighting” with JS and php. In the era of flash I did a lot of work with Macromedia’s program but when Apple destroy the technology I felt like some part of me died.

I never worked as a full time web designer till I was 30 or so, always had my normal job and make website as a hobby and some times for money, for obvious reasons like the lack of conviction, determination and initiative. Wen the economical crisis hit Spain and I found my self with economical problems and had to search for an alternative so I study psychology for a while then I fund anther job and quit the to study.

The thing is that I quit the job as a construction worker and got into the graphic design academy, here in my home town, to be a professional designer, but because health problems I had to quit the school and can’t work and study as the same time I guess (only in my case, my brother manage to finish the university and work at the same time)

After 4 hard years I created with a colleague a small design firm in Valencia, but it did not work quite well, we discuss all the time about projects an how we distribute the work. I did not learn very much in the school, have learned a lot from books and video tutorials like udemy and lynda.com. So after the epic fail with my work project, I changed the job for a place in a factory and worked as a mechanic and wood worker till about two years ago when the factory closed and fired all the workers because o economical problems. After that I had become unemployed and searching for a job actively till I found another design school here in Valencia.

So I had pass the exam ant start the product design career, but didn’t last to much either because I can’t maintained the pace with the more scientific courses, but I manege to learn how to design in Blender, AutoCad, Solidworks, Fusion360 and other CAD and PC modelling software.

Well here I am still unemployed without any higher studies neither some kind of real and profession. I saw by accident a video YouTube made by a designer which canal is called “living with pixels”. And inspiration struck, he spoke about a web design business formula in which you design websites with Elementor in WordPress. So here I’m learning how to use Elementor and WordPress, I already know HTML and CSS, currently learning to program with JavaScript ans php.

My intentions with this community is to make friends, learn a lot, and also collaborate actively in the forum, but for know I will retire in silence and take a look on the forum before ask questions and present my doubts.

I love metal, al genres of metal but not the symphonic or black/death, because I love to listen to the words of the son and understand it. Video games, rpg, isometric turn-based ones, stealth games and 4X. I also play board games like Scythe and Descent 2 and have two army of Age of Sigmar by GW, and air-soft too, have two MP5 a M4A1, and a 1911 hybrid. Love Italian food and motorcycles specially the cafe racer ones.

If you want to know more things about me, please just ask.

Thanks an have a nice day!

See you soon and hope we have fun!