Category: Java assignments

Java assignment 11: Current date & time worldwide

Write a program that allows users to enter a letter that represents a city in the world. When the user inserts the letter and presses the enter button, the program writes the current date and time in that city. In the following example the user entered the letter “n”, therefore the program shows the date […]

Java assignment 10: Select the month of the year

Write a simple program that allows users to enter a number. For each number the program writes its equivalent month. If the user enters the number 5 for example, the program writes the equivalent month of 5, which is “May”. That applies to all the months of the year. If the user enters an invalid […]

Java assignment 09: Selecting basketball players

Write a simple program that allows users to insert the age and the height of new basketball players. If the age of the player is between 16 and 30 years and his height is 180 or higher, your program should write a message that the player is selected otherwise the player is rejected as shown […]

Java assignment 08: Examen results

The output of this code is nothing. We pass the variable score to the method. The method should do the following! If the number 10 is passed to the method, the ouput is “Excellent”. If the number 9 is passed to the method, the ouput is “Very good”. If the numbers 8, 7 and 6 […]

Java assignment 07: Find the leap years

Write a program that allows the user to enter a year. After inserting a year and pressing the enter button, the program determines whether the inserted year is a leap year. Note: A leap year is divisible by 4 with no remainder. Java assignment 07: Find the leap years Level: Normal Author: Sar Maroof Answer […]

Java assignment 06: Find the sum of integers

The output of this code is nothing. The method writeSum should write the sum of three integers, namely i, i2 and i3 to the standard output. Java assignment 6: Find the sum of integers Level: Easy Author: Sar Maroof Answer explanation The body of the method is written in the following code. The following program […]

Java assignment 05: Write the largest integer

Write the body of the method getLargest. The method writes the largest number out of three integers. If two or more equal largest integers are passed to the method, the output of the program should be “Enter unique numbers!”.   Java assignment 5: Write the largest integer Level: Normal  Author: Sar Maroof Answer explanation The […]

Java assignment 04: Working with strings

As a Java programmer you will often need to work with the Java standard API specification. I tried to write a Java assignment based on one of my favorite quotes. The text of the q is a quote by Mahatma Gandhi, but there is an unwanted web site link inside the quote. Write only one statement […]

Java assignment 03: Converting dollar to euro

Today, I am gonna teach you to write a simple useful Java program. This program converts any amounts of dollars to euros, when 1 euro = 1.18 dollar. If you run the program, a text appears in the standard output that asks users to enter an amount in dollars. When the user enters the amount […]

Java assignment 02: Calculate net salary

You can solve this assignment easily if you have learned from the first one. The method getNetSalary calculates the net salary of employees. The method applies only if the tax rate is equal to 0.20 and the monthly income is $4000. Change the code of the method so that it can calculate the net salary […]

Java assignment 01: Calculate net salary

Here below is a Java assignment for beginner programmers. When you start to work by a company, you often need to write Java methods and classes! The method getNetSalary calculates the net salary of employees who have a monthly income of $3200. This method can be applied only if the tax rate is equal to 0.30. […]