import java.util.Scanner; public class Slideshow{ //fields: public/statc type and vairable name public Sound [] sounds; public Image [] pictures; //constructor: same name as the class, no return type public Slideshow(){ sounds = new Sound[0]; pictures = new Image[0]; } public void addSlide(Image newImg, Sound newSound){ Sound[] copySound = new Sound[sounds.length+1]; Image[] copyImg = new Image[pictures.length+1]; copyImg[copyImg.length - 1] = newImg; copySound[copySound.length - 1] = newSound; for (int i = 0; i < this.pictures.length; ++i) { copyImg[i] = pictures[i]; } this.pictures = copyImg; for (int i = 0; i < this.sounds.length; ++i) { copySound[i] = sounds[i]; } this.sounds = copySound; } public void play(){ for(int i = 0; i < pictures.length; ++i){ //this shows the element of the specified index in the pictures array pictures[i].show(); //this shows the element of the specified index in the sounds array sounds[i].play(); //this pause the image, but keeps the music playing sounds[i].blockingPlay(); } } public static void main(String[] args){ Slideshow mySlideShow = new Slideshow(); //grabbing the files from its folder assigning a variable to that file Image img1 = new Image("res/cat.jpg"); Image img2 = new Image("res/dog.jpg"); Image img3 = new Image("res/bird.jpg"); Sound snd1 = new Sound("music/sound1.wav"); Sound snd2 = new Sound("music/sound2.wav"); Sound snd3 = new Sound("music/sound3.wav"); //uses the addSlide method on the created object of the class mySlideShow.addSlide(img1, snd1); mySlideShow.addSlide(img2, snd2); mySlideShow.addSlide(img3, snd3); //uses the play() method mySlideShow.play(); //this would initially ask the user if they want to replay the slideshow Scanner scnr = new Scanner(System.in); System.out.println("Would you like to replay the slides?"); String reply = scnr.nextLine(); //this loops would iterate over and over again if the user input yes while(reply.equals("yes")){ mySlideShow.play(); System.out.println("Would you like to replay the slides?"); reply = scnr.nextLine(); } //If the user enters anythign other then user, then the program would exit //from the following command System.exit(0); } }