You are currently viewing UNIUYO Java Labwork 2: Project 1 – 10

UNIUYO Java Labwork 2: Project 1 – 10

Write a Java program to implement the current students’ grading system. Your program should accept the test and examination score, calculate the total and determine the grade for n number of students. The output on the screen should be in a tabular form; Reg_Num, Test, Exam, Total and grade.

Solution

uniuyo java projet

Explanation

This Java program allows users to input test and exam scores for a given number of students and calculates their total scores and grades based on predefined grade boundaries. Let’s break down the code:

  1. import java.util.Scanner;: Imports the Scanner class from the java.util package to allow user input.
  2. public class Project11 {: Defines a class named Project11.
  3. public static void main(String[] args) {: Defines the main method, which is the entry point of the program.
  4. Scanner sc=new Scanner(System.in);: Creates a new Scanner object named sc to read input from the console.
  5. System.out.print(“Pls enter the total number of students: “);: Prompts the user to enter the total number of students.
  6. int stud=sc.nextInt();: Reads the total number of students entered by the user and stores it in the variable stud.
  7. String[] RegNo=new String[stud];: Declares an array named RegNo to store the registration numbers of the students.
  8. int [] Test =new int[stud];: Declares an array named Test to store the test scores of the students.
  9. int[]Exam = new int[stud];: Declares an array named Exam to store the exam scores of the students.
  10. int [] Total = new int[stud];: Declares an array named Total to store the total scores of the students.
  11. String[] Grade= new String[stud];: Declares an array named Grade to store the grades of the students.
  12. for (int i=0; i<stud; i++) { … }: Iterates over each student to input their registration number, test score, and exam score.
  13. System.out.println();: Prints a newline for formatting purposes.
  14. System.out.print(“Enter Student “+(i+1)+ ” Reg number: “);: Prompts the user to enter the registration number of the current student.
  15. RegNo[i]=sc.next();: Reads the registration number entered by the user and stores it in the RegNo array.
  16. System.out.print(“Enter the test score for “+RegNo[i]+ “: “);: Prompts the user to enter the test score for the current student.
  17. Test[i]=sc.nextInt();: Reads the test score entered by the user and stores it in the Test array.
  18. System.out.print(“Enter the exam score for “+RegNo[i]+ “: “);: Prompts the user to enter the exam score for the current student.
  19. Exam[i]=sc.nextInt();: Reads the exam score entered by the user and stores it in the Exam array.
  20. Total[i]=Test[i]+Exam[i];: Calculates the total score for the current student by adding their test and exam scores.
  21. System.out.println(“\n\nSN\tREG NO\t\tTEST\tEXAM\tTOTAL\tGRADE”);: Prints a header for the table displaying student information.
  22. for (int i=0; i<stud; i++) { … }: Iterates over each student to calculate their grade based on their total score and prints their information.
  23. if(Total[i]>=70) { … } else if …: Determines the grade for each student based on their total score using predefined grade boundaries.
  24. System.out.println((i+1)+”\t”+RegNo[i]+”\t”+Test[i]+”\t”+Exam[i]+”\t”+Total[i]+”\t”+Grade[i]) ;: Prints the student’s information, including their serial number, registration number, test score, exam score, total score, and grade.

Output

uniuyo java project

The management board of De-Gibson University decided to automate the implementation of the board’s decision on increasing the school fees for next academic session, which depends on the number of students admitted given a cut off mark of 275; that is, those admitted is above 60% of total applicants. write a Java program that will determine the number of candidates admitted or not admitted, and advise the management whether to increase the school fees or not.

Solution

Uniuyo java project

Explanation

This Java program simulates a scenario where applicants are considered for admission based on their scores. Let’s go through the code line by line:

  1. import java.util.Scanner;: Imports the Scanner class from the java.util package to allow user input.
  2. public class PROJECT12 {: Defines a class named PROJECT12.
  3. public static void main(String[] args) {: Defines the main method, which is the entry point of the program.
  4. Scanner sc = new Scanner(System.in);: Creates a new Scanner object named sc to read input from the console.
  5. System.out.print(“Pls enter the total number of applicants: “);: Prompts the user to enter the total number of applicants.
  6. int app = sc.nextInt();: Reads the total number of applicants entered by the user and stores it in the variable app.
  7. System.out.print(“Pls enter the total number of students that scored above 275: “);: Prompts the user to enter the total number of students who scored above 275.
  8. int add = sc.nextInt();: Reads the total number of students who scored above 275 entered by the user and stores it in the variable add.
  9. int admitted = add;: Initializes the variable admitted with the value of add, representing the number of students admitted.
  10. int NotAdmitted = app – add;: Calculates the number of students not admitted by subtracting the number admitted (add) from the total number of applicants (app).
  11. double Decision = (add * 100) / app;: Calculates the percentage of students admitted by dividing the number admitted (add) by the total number of applicants (app) and multiplying by 100.
  12. if (Decision > 60) { … } else { … }: Checks if the percentage of students admitted is greater than 60%. If it is, the program prints a message indicating that school fees should be increased. Otherwise, it prints a message indicating that school fees should not be increased.
  13. System.out.println(“\nTotal Number Admitted: ” + admitted … );: Prints the total number of students admitted, the total number not admitted, the percentage of students admitted, and the decision based on the admission percentage.

Output

Write a Java program that requires the user to enter a single character from the alphabet, print Vowel or consonant, depending on the user input. If the user input is not a letter between Aa – Zz, print an error message.

Solution

project 3

Explanation

  1. package labwork23;: Specifies the package name where the class Project13 is located.
  2. import java.util.Scanner;: Imports the Scanner class from the java.util package to allow user input.
  3. public class Project13 {: Defines a class named Project13.
  4. public static void main(String[] args) {: Defines the main method, which is the entry point of the program.
  5. Scanner sc = new Scanner(System.in);: Creates a new Scanner object named sc to read input from the console.
  6. System.out.println(“Enter a single character: “);: Prompts the user to enter a single character.
  7. String input = sc.next();: Reads the user input and stores it in the input variable.
  8. if (input.length() != 1) { … }: Checks if the length of the input string is not equal to 1, indicating that the user did not enter a single character.
  9. char Alp = input.toLowerCase().charAt(0);: Converts the input string to lowercase and extracts the first character, storing it in the variable Alp.
  10. if ((Alp >= ‘a’ && Alp <= ‘z’) && (Alp == ‘a’ || Alp == ‘e’ || Alp == ‘i’ || Alp == ‘o’ || Alp == ‘u’)) { … }: Checks if Alp is a lowercase letter and if it is one of the vowels (‘a’, ‘e’, ‘i’, ‘o’, ‘u’).
  11. else if ((Alp >= ‘a’ && Alp <= ‘z’) && (!(Alp == ‘a’ || Alp == ‘e’ || Alp == ‘i’ || Alp == ‘o’ || Alp == ‘u’))) { … }: Checks if Alp is a lowercase letter and not one of the vowels, indicating that it is a consonant.
  12. else { … }: Handles the case where the input is not a letter.

Output

project 3

Write a Java to generate 10 terms of the sequence 1/2, 1/4, 1/6, 1/8, 1/10, …, 1/M. Your outputs must be in fraction (e.g. 1/2).

Solution

uniuyo java labwork 2

Explanation

  1. public class Project44 {: Defines a class named Project44.
  2. public static void main(String[] args) {: Defines the main method, which is the entry point of the program.
  3. System.out.println(“enter the last number in the series: “);: Prints a message asking the user to enter the last number in the series.
  4. Scanner sc = new Scanner(System.in);: Creates a new Scanner object named sc to read input from the console.
  5. int lastNumber = sc.nextInt();: Reads the last number in the series entered by the user and stores it in the variable lastNumber.
  6. System.out.print(“The series are: “);: Prints a message indicating that the series will be displayed.
  7. for (int i = 2; i <= lastNumber; i += 2) { … }: Starts a loop that iterates over even numbers from 2 up to the last number in the series entered by the user.
  8.  System.out.print(“1/” + i + “, “);: Prints each term of the series in the format “1/x,” where “x” represents the current even number in the series.

Output

UNIUYO java labwork 2

Write a Java program to add natural numbers between 1 to 20 but ensuring that the final sum of these numbers does not exceed 110. Display the final sum and the nth term of the natural number.

Solution

project 5

Explanation

  1. public class Project55 {: Defines a class named Project55.
  2. public static void main(String[] args) {: Defines the main method, which is the entry point of the program.
  3. int sum = 0;: Initializes a variable sum to store the sum of the terms.
  4. int term = 0;: Initializes a variable term to store the value of the last term added to the sum.
  5. for (int i = 0; i <= 20; i++) { … }: Starts a loop that iterates from 0 up to 20.
  6. if (sum + i <= 110) { … }: Checks if adding the current value of i to the sum (sum + i) will not exceed 110.
  7. sum += i;: If the condition is met, adds the current value of i to the sum.
  8. term = i;: Updates the term variable with the current value of i.
  9. else { break; }: If adding the current value of i would exceed 110, breaks out of the loop.
  10. System.out.println(“Term: ” + term + “\nSum: ” + sum);: Prints the value of the last term added (term) and the total sum (sum).

Output

UNIUYO java labwork 2

A farming industry is in need of a program to select Irish apples after harvesting as green-apple, and red-apples. The green-apples are identified as even numbers (2,4,6,…), And the red-apples as odd number (1,3,5,…). However, any apple identified as any number divisible by five is defective and hence should not be selected. Write a Java program as a prototype to solve this problem assuming that n number of  Irish apples were harvested. Hint: your program should output a set of even and odd numbers.

Solution 1

uniuyo java labwork 2

Explanation

  1. import java.util.Scanner;: Imports the Scanner class from the java.util package to allow user input.
  2. public class Project66 {: Defines a class named Project66.
  3. public static void main(String[] args) {: Defines the main method, the entry point of the program.
  4. Scanner sc = new Scanner(System.in);: Creates a Scanner object named sc to read input from the console.
  5. System.out.print(“enter the total number of irish apple: “);: Prompts the user to enter the total number of Irish apples.
  6. int input = sc.nextInt();: Reads the integer input entered by the user and stores it in the variable input.
  7. if (input == 0) { … }: Checks if the input is zero. If true, prints “No Harvest”.
  8. else if (input == 1) { … }: Checks if the input is one. If true, prints “You Harvested just one red apple”.
  9. else { … }: If the input is neither zero nor one, proceeds with the following logic.
  10. for (int i = 1; i <= input; i++) { … }: Starts a loop to iterate from 1 up to the value of input.
  11. if (i % 2 == 0 && i % 5 != 0) { … }: Checks if the current number (i) is even and not divisible by 5. If true, prints it as a green apple.
  12. System.out.print(“\nThe Red apples are: “);: Prints a label for the red apples.
  13. if (input > 4) { … }: Checks if the input is greater than 4. If true, proceeds with the following logic.
  14. System.out.print(“\nThe defective Apples are: “);: Prints a label for the defective apples.

Output

project 6 code

Solution 2 (Accepting the apple number from user)

project 6 solution 2

Explanation

  1. import java.util.Scanner;: Imports the Scanner class from the java.util package to allow user input.
  2. public class Project55_2 {: Defines a class named Project55_2.
  3. public static void main(String[] args) {: Defines the main method, the entry point of the program.
  4. Scanner sc = new Scanner(System.in);: Creates a Scanner object named sc to read input from the console.
  5. System.out.println(“Enter the total number of Irish apple harvested”);: Prompts the user to enter the total number of Irish apples harvested.
  6. int input = sc.nextInt();: Reads the integer input entered by the user and stores it in the variable input.
  7. int Harvest[] = new int[input];: Creates an integer array named Harvest to store the details of each apple, with the size determined by the user input.
  8. int green = 0; int red = 0; int defect = 0;: Initializes variables to count the number of green, red, and defective apples.
  9. for (int i = 0; i < input; i++) { … }: Starts a loop to iterate from 0 up to the value of input.
  10. System.out.print(“enter the irish apple ” + (i + 1) + ” number: “);: Prompts the user to enter the details of each apple.
  11. Harvest[i] = sc.nextInt();: Reads the integer input entered by the user and stores it in the Harvest array at index i.
  12. if (Harvest[i] % 2 == 0 && Harvest[i] % 5 != 0) { … }: Checks if the current apple is green based on its properties and increments the green counter if true.
  13. else if (Harvest[i] % 2 != 0 && Harvest[i] % 5 != 0) { … }: Checks if the current apple is red based on its properties and increments the red counter if true.
  14. else if (Harvest[i] % 5 == 0) { … }: Checks if the current apple is defective based on its properties and increments the defect counter if true.
  15. if (green != 0) { … }: Checks if there are any green apples and prints them if true.
  16. if (red != 0) { … }: Checks if there are any red apples and prints them if true.
  17. if (defect != 0) { … }: Checks if there are any defective apples and prints them if true.

Output

Uniuyo java labwork 2
project 7

Solution

project 7

Output

project 7
project 7b

Solution

uniuyo java labwork 2

Output

uniuyo java labwork 2
uniuyo java labwork 2

Solution

uniuyo java labwork 2

Output

uniuyo java labwork 2
project 9

Solution

project 9

Output

project 9

The solutions provided for the Java lab work are intended solely for study purposes. Under no circumstances should any student directly copy these solutions into the exam or test hall. These solutions are meant to enhance understanding and facilitate learning, and students are encouraged to use them responsibly as study guides. Plagiarism or academic dishonesty is strictly prohibited and can result in severe consequences, including disciplinary action. It is essential for students to demonstrate their understanding of the concepts independently during assessments.

Study more on java projects here