import java.util.ArrayList;

public class NumberList {

    private ArrayList<Integer> numbers;

    public NumberList() {
        numbers = new ArrayList<>();
    }

    public void addNumber(int num) {
        numbers.add(num);
    }

    public int getNumberAtIndex(int index) {
        return numbers.get(index);
    }

    public static void main(String[] args) {
        NumberList list = new NumberList();
        list.addNumber(5);
        list.addNumber(10);
        list.addNumber(15);

        System.out.println(list.getNumberAtIndex(1));  
    }
}
NumberList.main(null)
10
import java.util.Random;
import java.util.Scanner;

public class GuessingGame {

    private int baseNumber;
    private int exponent;
    private double result;

    public GuessingGame() {
        Random rand = new Random();
        baseNumber = rand.nextInt(9) + 2; 
        exponent = rand.nextInt(4) + 1;    
        result = Math.pow(baseNumber, exponent);
    }


    public void provideHint() {
        if (exponent > 0) {
            System.out.println("Hint: The number is raised to a positive power.");
        } else {
            System.out.println("Hint: The number is raised to a negative power (root).");
        }
        System.out.println("Hint: The result of the operation is: " + result);
    }


    public static boolean checkGuess(int base, int exp, GuessingGame game) {
        return base == game.baseNumber && exp == game.exponent;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        GuessingGame game = new GuessingGame();

        System.out.println("Guess the base number and its exponent!");
        game.provideHint();

        System.out.print("Enter your guess for the base number: ");
        int userBase = scanner.nextInt();

        System.out.print("Enter your guess for the exponent: ");
        int userExponent = scanner.nextInt();

        if (checkGuess(userBase, userExponent, game)) {
            System.out.println("Congratulations! You guessed correctly.");
        } else {
            System.out.println("Sorry, that's incorrect. The correct base was " + game.baseNumber + " and the exponent was " + game.exponent + ".");
        }
    }
}
GuessingGame.main(null)
Guess the base number and its exponent!
Hint: The number is raised to a positive power.
Hint: The result of the operation is: 216.0
Enter your guess for the base number: Enter your guess for the exponent: Sorry, that's incorrect. The correct base was 6 and the exponent was 3.
import java.util.ArrayList;
import java.util.List;

public class Store {
    int id;
    boolean inStock;
    String name;
    double price;

    Store(int id, boolean inStock, String name, double price) {
        this.id = id;
        this.inStock = inStock;
        this.name = name;
        this.price = price;
    }

    public static void main(String[] args) {
        List<Store> products = new ArrayList<>();

        products.add(new Store(1, true, "Laptop", 999.99));
        products.add(new Store(2, false, "Mouse", 19.99));
        products.add(new Store(3, true, "Keyboard", 49.99));
        products.add(new Store(4, true, "Monitor", 149.99));
        products.add(new Store(5, false, "Headphones", 59.99));

        System.out.println(products.get(0).name + " - $" + products.get(0).price);
        System.out.println(products.get(2).name + " - $" + products.get(2).price);
        System.out.println(products.get(4).name + " - $" + products.get(4).price);
    }
}
Store.main(null)
Laptop - $999.99
Keyboard - $49.99
Headphones - $59.99
public class PersonName {

    private String fullName;

    PersonName(String fullName) {
        this.fullName = fullName;
    }

    public String getFirstName() {
        String firstName = "";
        for (int i = 0; i < fullName.length(); i++) {
            if (fullName.charAt(i) == ' ') {
                break;
            }
            firstName += fullName.charAt(i);
        }
        return firstName;
    }

    public String getLastName() {
        String lastName = "";
        boolean spaceFound = false;
        for (int i = 0; i < fullName.length(); i++) {
            if (fullName.charAt(i) == ' ') {
                spaceFound = true;
                continue;
            }
            if (spaceFound) {
                lastName += fullName.charAt(i);
            }
        }
        return lastName;
    }

    public static void main(String[] args) {
        PersonName person = new PersonName("John Doe");
        System.out.println("First Name: " + person.getFirstName());
        System.out.println("Last Name: " + person.getLastName());
    }
}
PersonName.main(null)
First Name: John
Last Name: Doe