ChalaiDen.java
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.FGZBRACU
java
8 months ago
2.0 kB
12
Indexable
CSE111 Lab Quiz Codes
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]);
}
}
}
Editor is loading...
Leave a Comment