CSE111 Lab Quiz Codes

 avatarFGZBRACU
Public10 months ago2 Snippets
Search
Language
Sort by
📅 Created Date
Order

Ektufy.java

java10 months ago
This Java class implements a basic playlist manager. You can add songs to the playlist and play them at normal speed or at a specified speed. It includes handling for a full playlist and checking if a song exists before playing it.
public class Ektufy {
    String [] playList = new String[3];
    int count = 0;
    String genre = "Default";

    public void addSong(String song) {
        if (count < playList.length) {
            playList[count] = song;
            count++;
            System.out.println("Added: " + song + " to the playlist.");
        } else {
            System.out.println("Playlist is full.");
        }
    }

    public void play(String songName) {
        for (int i = 0; i < count; i++) {
            if (playList[i].equals(songName)) {
                System.out.println("Playing: " + playList[i] + " in " + genre + " genre.");
                return;
            }
        }
        System.out.println("Song not found in the playlist.");
    }

    public void play(String songName, Double speed) {
        for (int i = 0; i < count; i++) {
            if (playList[i].equals(songName)) {
                System.out.println("Playing: " + playList[i] + " at " + speed + "x speed.");
                return;
            }
        }
        System.out.println("Song not found in the playlist.");
    }

    public void play(String songName, String language) {
        for (int i = 0; i < count; i++) {
            if (playList[i].equals(songName)) {
                System.out.println("Playing: " + playList[i] + " in " + language + " language.");
                return;
            }
        }
        System.out.println("Song not found in the playlist.");
    }

    public void displayPlaylist() {
        System.out.println("Genre: " + genre);
        System.out.println("Playlist:");
        if (count == 0) {
            System.out.println("No songs in the playlist.");
            return;
        }
        System.out.println("Total songs: " + count);
        for (int i = 0; i < count; i++) {
            System.out.println(playList[i]);
        }
    }
}

ChalaiDen.java

java10 months ago
This snippet demonstrates a simple Java class called 'ChalaiDen' that manages a list of slogans. It allows adding new slogans, checking if a slogan exists in the list, and repeating a slogan a specified number of times. It showcases basic object-oriented principles in Java.
public class ChalaiDen {
    String [] sloganList = new String[3];
    int count = 0;
    String vibe = "Crazy!";
    public void addSlogan(String slogan) {
        if (count < sloganList.length) {
            sloganList[count] = slogan;
            count++;
            System.out.println("Added " + slogan + " to the slogan list.");
        } else {
            System.out.println("No more slogan please!");
        }
    }

    public void sayIt(String slogan) {
        for (int i = 0; i < count; i++) {
            if (sloganList[i].equals(slogan)) {
                System.out.println("Chalaiden " + sloganList[i] + " at " + vibe + " vibe.");
                return;
            }
        }
        System.out.println("Slogan not found in the list.");
    }

    public void sayIt(String slogan, int repeatTimes) {
        for (int i = 0; i < count; i++) {
            if (sloganList[i].equals(slogan)) {
                for (int j = 0; j < repeatTimes; j++) {
                    sloganList[i] += " " + slogan;
                }
                System.out.println("Chalaiden " + sloganList[i]);
                return;
            }
        }
        System.out.println("Slogan not found in the list.");
    }

    public void sayIt(String slogan, String language) {
        for (int i = 0; i < count; i++) {
            if (sloganList[i].equals(slogan)) {
                System.out.println("Chalaiden " + sloganList[i] + " in " + language + " language.");
                return;
            }
        }
        System.out.println("Slogan not found in the list.");
    }

    public void displaySlogans() {
        System.out.println("Vibe: " + vibe);
        System.out.println("Slogan List:");
        if (count == 0) {
            System.out.println("No slogans added yet.");
            return;
        }
        System.out.println("Total slogans: " + count);
        for (int i = 0; i < count; i++) {
            System.out.println(sloganList[i]);
        }
    }
}

  • Total 2 snippets
  • 1