top of page

Freestyle Coding: Youtube

  • Writer: Ruby Moley
    Ruby Moley
  • Nov 24, 2024
  • 3 min read

Updated: Dec 3, 2024

Published on 11 / 24 / 2024


Coding is hard. Really hard. It is for those whose brains are oriented in logic and creative solutions to complex problems. I encourage everyone to try coding once, if interested.


To learn coding best, I like to make programs that include variables and methods that are comedic or have emotional prominence. Therefore, when I am writing the code, I better recall how to implement the given methods and coding signatures.


This week, I was tasked with learning Polymorphism, ArrayLists, and Interfaces(fancy words, I know). While you may not understand everything in this code, it is apparent with codewords like "Youtube", "Subscribers", and prominent online figures' names that I tried to mimic Youtube's source code implementations! Coding is very creative, requiring lots of failure, problem-solving, and brainstorming. Below, you can scroll through my code!


/**
 * This class represents the website Youtube and its content creators.
 */

import java.util.*;
/**
 * @author rubym
 */
public class Youtube {

	public static void main(String[] args) {
		ArrayList<Youtuber> youtube = new ArrayList<>();
		
		// create youtubers
		Youtuber jerma = new Youtuber("Jerma985", 965000, true, false);
		Youtuber charlie = new Youtuber("MoistCr1tkal", 16200000, false, false);
		Youtuber markiplier = new Youtuber("markiplier", 37000000, false, false);
		Youtuber sinjin = new Youtuber("Sinjin Drowning", 847000, true, false);
		
		youtube.add(jerma);
		youtube.add(markiplier);
		youtube.add(charlie);
		youtube.add(sinjin);
		
		printList(youtube);
		
		if (youtube.contains(jerma)) {
			System.out.println(jerma.getName() + " is still on Youtube.");
		} else {
			System.out.println(jerma.getName() + " is no longer an existing channel.");
		}
		
		cancelMe(youtube, jerma, "Said a slur on stream.");
		
		if (youtube.contains(jerma)) {
			System.out.println(jerma.getName() + " is still on Youtube.");
		} else {
			System.out.println(jerma.getName() + " is no longer an existing channel.");
		}
		System.out.println(" - ⊹ ࣪ ˖ - - ⊹ ࣪ ˖ -  - ⊹ ࣪ ˖ - - ⊹ ࣪ ˖ - ");

		// sort the Youtube by subscribers
		Collections.sort(youtube);
		printList(youtube);
		System.out.println(" - ⊹ ࣪ ˖ - - ⊹ ࣪ ˖ -  - ⊹ ࣪ ˖ - - ⊹ ࣪ ˖ - ");

		// run Gold Check
		goldStatus(youtube);
		printList(youtube);
		
	}

	/**
	 * Print method for ArrayList
	 * @param ArrayList<Youtuber> 
	 */
	public static void printList (ArrayList<Youtuber> youtube) {
		for (Youtuber y : youtube) {
			System.out.println(y.getName() + ", " + y.getFollowers() + " subscribers, "
								+ printSubscribe(y) + ", has gold award: " + y.hasGoldAward());
		}
	}
	
	/**
	 * This method creates the string of the subscription status.
	 * @param y A youtuber object
	 * @return String A string describing the subscription status.
	 */
	public static String printSubscribe(Youtuber y) {
		if (y.isSubscribed() == true) {
			return("You are subscribed.");
		} else {
			return("You are not subscribed.");
		}
	}
	
	/**
	 * This method cancels a Youtuber because of controversy
	 * and removes their channel from youtube.
	 */
	public static void cancelMe(ArrayList<Youtuber> x, Youtuber y, String reason) {
		x.remove(y);
		System.out.println(y.getName() + " has been CANCELED! " + reason);
	}
	
	/**
	 * This method changes the Gold Award Status to 'true' if the given
	 * Youtuber has over 1 million subscribers.
	 * @return void
	 */
	public static void goldStatus(ArrayList<Youtuber> youtube) {
		Iterator<Youtuber> iter = youtube.iterator();
		while (iter.hasNext()) {
			Youtuber nextYoutuber = iter.next();
			if (nextYoutuber.getFollowers() >= 1000000) {
				nextYoutuber.setGoldAward(true);
			}
		}
	}
}
/**
 * This class represents a Youtuber object with the attributes
 * name, subscriber count, gold award status, and subscription status.
 * The class implements comparable, allowing users to sort Youtubers
 * by subscribers. 
 */

/**
 * @author rubym
 */
public class Youtuber implements Comparable<Youtuber>{
	private String name;
	private int followers;
	private boolean subscribed;
	private boolean goldAward;
	
	// getters
	public String getName() {
		return name;
	}
	public int getFollowers() {
		return followers;
	}
	public boolean isSubscribed() {
		return subscribed;
	}
	public boolean hasGoldAward() {
		return goldAward;
	}
	// setter
	public void setGoldAward(boolean goldAward) {
		this.goldAward = goldAward;
	}
	
	public Youtuber(String name, int followers, boolean subscribed, boolean goldAward) {
		super();
		this.name = name;
		this.followers = followers;
		this.subscribed = subscribed;
		this.goldAward = goldAward;
	}
	
	/**
	 * This method rewrites the equals method
	 * @return boolean True if the two are the same.
	 */
	@Override
	public boolean equals(Object obj) {
		Youtuber youtuber =(Youtuber)obj;
		return this.name.equalsIgnoreCase(youtuber.getName()) &&
			   this.followers == youtuber.getFollowers();
	}
	
	/**
	 * This method redefines the compareTo method in the Comparable interface,
	 * comparing if the given Youtuber has more subscribers than the other,
	 * in descending order.
	 * @param obj of type 'Obj'
	 * @return int 1, 0, or -1
	 */
	public int compareTo(Youtuber youtuber) {
		if (this.followers > youtuber.getFollowers()) {
			return -1;
		} else if (this.followers == youtuber.getFollowers()) {
			return 0;
		} else {
			return 1;
		}
	}
}

Thank you for reading this everyday blog post! Hope this interests you to try coding. If you want to see this code run, input in your coding program of choice.

 
 
 

Comments


file (18).png

Let's chat!!!

Thanks for submitting!

© 2035 by Annabelle. Wix

file (19).png
bottom of page