Uploaded July 2024 | Updated September 2026, 1 week ago
This Python number guessing game for beginners will help us gain experience with using loops and random numbers. Code for this video can be found in the comments section.
This Python number guessing game for beginners will help us gain experience with using loops and random numbers. Code for this video can be found in the comments section.



![Lets code an alarm clock with Java! โฐ
#java #javatutorial #javacourse
This is a beginners project to help us learn and understand Object Oriented Programming and Threading. We will only be using topics we have discussed in past videos in this series.
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// JAVA ALARM CLOCK
Scanner scanner = new Scanner(System.in);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(HH:mm:ss);
LocalTime alarmTime = null;
String filePath = A Caring Friend.wav;
while(alarmTime null){
try{
System.out.print(Enter an alarm time (HH:MM:SS): );
String inputTime = scanner.nextLine();
alarmTime = LocalTime.parse(inputTime, formatter);
System.out.println(Alarm set for + alarmTime);
}
catch(DateTimeParseException e){
System.out.println(Invalid format. Please use HH:MM:SS);
}
}
AlarmClock alarmClock = new AlarmClock(alarmTime, filePath, scanner);
Thread alarmThread = new Thread(alarmClock);
alarmThread.start();
}
}
import javax.sound.sampled.*;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.time.LocalTime;
import java.util.Scanner;
public class AlarmClock implements Runnable{
private final LocalTime alarmTime;
private final String filePath;
private final Scanner scanner;
AlarmClock(LocalTime alarmTime, String filePath, Scanner scanner){
this.alarmTime = alarmTime;
this.filePath = filePath;
this.scanner = scanner;
}
@Override
public void run(){
while(LocalTime.now().isBefore(alarmTime)){
try {
Thread.sleep(1000);
LocalTime now = LocalTime.now();
System.out.printf(r%02d:%02d:%02d,
now.getHour(),
now.getMinute(),
now.getSecond());
}
catch (InterruptedException e) {
System.out.println(Thread was interrupted);
}
}
System.out.println(n*ALARM NOISES*);
playSound(filePath);
}
private void playSound(String filePath){
File audioFile = new File(filePath);
try(AudioInputStream audioStream = AudioSystem.getAudioInputStream(audioFile)){
Clip clip = AudioSystem.getClip();
clip.open(audioStream);
clip.start();
System.out.print(Press *Enter* to stop the alarm: );
scanner.nextLine();
clip.stop();
scanner.close();
}
catch(UnsupportedAudioFileException e){
System.out.println(Audio file format is not supported);
}
catch(LineUnavailableException e){
System.out.println(Audio is unavailable);
}
catch(IOException e){
System.out.println(Error reading audio file);
}
}
} Lets code an alarm clock with Java! โฐ](https://i.ytimg.com/vi/lGG0LAJf0uE/mqdefault.jpg)




![Java printf() is really useful! ๐จ๏ธ
#java #javatutorial #javacourse
public class Main {
public static void main(String[] args) {
// printf() is a method used to format output
// % [flags] [width] [.precision] [specifier-character]
// [specifier-character]
String name = Spongebob;
char firstLetter = S;
int age = 30;
double height = 60.5;
boolean isEmployed = true;
System.out.printf(Hello %sn, name);
System.out.printf(Your name starts with a %cn, firstLetter);
System.out.printf(You are %d years oldn, age);
System.out.printf(You are %f inches talln, height);
System.out.printf(Employed: %bn, isEmployed);
System.out.printf(%s is %d years old, name, age);
// [.precision]
double price1 = 9.99;
double price2 = 100.15;
double price3 = -54.01;
System.out.printf(%.3fn, price1);
System.out.printf(%.3fn, price2);
System.out.printf(%.3fn, price3);
// [flags]
// + = output a plus
// , = comma grouping separator
// ( = negative numbers are enclosed in ()
// space = display a minus if negative, space if positive
System.out.printf(%fn, price1);
System.out.printf(%fn, price2);
System.out.printf(%fn, price3);
// [width]
// 0 = zero padding
// number = right justified padding
// negative number = left justified padding
int id1 = 1;
int id2 = 23;
int id3 = 456;
int id4 = 7890;
System.out.printf(id: %04dn, id1);
System.out.printf(id: %04dn, id2);
System.out.printf(id: %04dn, id3);
System.out.printf(id: %04dn, id4);
}
} Java printf() is really useful! ๐จ๏ธ](https://i.ytimg.com/vi/nTBDjxWAcoE/mqdefault.jpg)

![Learn Java overloaded methods in 6 minutes! ๐
#java #javatutorial #javacourse
public class Main {
public static void main(String[] args){
// overloaded methods = methods that share the same name,
// but different parameters
// signature = name + parameters
String pizza = bakePizza(flat-bread, mozzarella, pepperoni);
System.out.println(pizza);
}
static String bakePizza(String bread){
return bread + pizza;
}
static String bakePizza(String bread, String cheese){
return cheese + + bread + pizza;
}
static String bakePizza(String bread, String cheese, String topping){
return topping + + cheese + + bread + pizza;
}
} Learn Java overloaded methods in 6 minutes! ๐](https://i.ytimg.com/vi/nhnAx79gxCM/mqdefault.jpg)