This repository contains a collection of Java projects that demonstrate the use of different types of loops (for
, while
, do-while
) and other related programming concepts. Each project focuses on applying loops to solve a specific problem.
- Sum of Numbers
- Distance Traveled
- Distance File
- Pennies for Pay
- Letter Counter
- File Letter Counter
- Hotel Occupancy
- Average Rainfall
- Population Growth
- Largest and Smallest
- Celsius to Fahrenheit Table
- Bar Chart
- Dice Game
- Slot Machine Simulation
- Random Number Guessing Game
- ESP Game
- Square Display
- Personal Web Page Generator
This program asks the user to enter a positive nonzero integer. It then calculates and displays the sum of all the numbers from 1 up to the entered value.
Usage:
javac SumOfNumbers.java
java SumOfNumbers
This program calculates the distance a vehicle travels for each hour of a given time period based on user input for speed and time.
Usage:
javac DistanceTraveled.java
java DistanceTraveled
This is a modification of the Distance Traveled project. Instead of displaying the output to the console, the program writes the distance traveled for each hour to a text file.
Usage:
javac DistanceFile.java
java DistanceFile
This program calculates the total salary earned over a given number of days if the salary starts with one penny and doubles each day. The output is shown in dollar format.
Usage:
javac PenniesForPay.java
java PenniesForPay
This program asks the user to enter a string and a character. It counts and displays how many times the character appears in the string.
Usage:
javac LetterCounter.java
java LetterCounter
This program reads from a file, asks the user for a character, and then counts how many times the character appears in the file.
Usage:
javac FileLetterCounter.java
java FileLetterCounter
This program calculates the occupancy rate of a hotel by asking the user for the number of floors, rooms per floor, and the number of rooms that are occupied. It then calculates and displays the occupancy rate.
Usage:
javac HotelOccupancy.java
java HotelOccupancy
This program calculates the average rainfall over a given number of years by asking for rainfall data for each month.
Usage:
javac AverageRainfall.java
java AverageRainfall
This program predicts the size of a population based on an initial population size, a daily population growth rate, and the number of days for growth. The program uses loops to calculate the population growth over time.
Usage:
javac PopulationGrowth.java
java PopulationGrowth
This program asks the user to enter a series of integers and determines the largest and smallest numbers in the series. The user enters -99 to indicate the end of input.
Usage:
javac LargestAndSmallest.java
java LargestAndSmallest
This program displays a table converting Celsius temperatures from 0 to 20 to their Fahrenheit equivalents using a for loop.
Usage:
javac CelsiusToFahrenheit.java
java CelsiusToFahrenheit
This program generates a simple bar chart based on sales figures entered for five stores. Each bar represents sales using asterisks, with each asterisk representing $100.
Usage:
javac BarChart.java
java BarChart
This is a simple game where the user competes against the computer by rolling dice. The game runs for 10 rounds, and the program keeps track of how many times each side wins.
Usage:
javac DiceGame.java
java DiceGame
This program simulates a slot machine. The user enters an amount of money, and the program generates random results for a slot machine. If two or more results match, the user wins.
Usage:
javac SlotMachineSimulation.java
java SlotMachineSimulation
The program generates a random number and allows the user to guess it. The user receives feedback whether the guess is too high or too low until they guess correctly.
Usage:
javac RandomNumberGuessingGame.java
java RandomNumberGuessingGame
This game tests the user’s ESP (extrasensory perception). The computer randomly selects a color from a list, and the user has to guess which color was selected.
Usage:
javac ESPGame.java
java ESPGame
This program asks the user to enter a positive integer no greater than 15 and displays a square made of X characters of that size.
Usage:
javac SquareDisplay.java
java SquareDisplay
This program asks the user for their name and a description. It generates a basic HTML page that displays this information.
Usage:
javac PersonalWebPageGenerator.java
java PersonalWebPageGenerator
To run any of these programs:
- Clone the repository:
git clone https://github.com/ryankerbyIT/JavaLoops.git
- Navigate to the specific project folder:
cd path/to/project/folder
- Compile the .java file:
javac FileName.java
- Run the program:
java FileName
This project is licensed under the MIT License - see the LICENSE file for details.
Feel free to explore, modify, and improve upon these projects. Happy coding!