0% found this document useful (0 votes)
28 views11 pages

1, Import Jav

This computer science assignment use it.

Uploaded by

jamsibro140
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views11 pages

1, Import Jav

This computer science assignment use it.

Uploaded by

jamsibro140
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 11

INJIBARA UNIVERSITY

College of Engineering and Technology

Object Oriented Programming assignment one

Group assignment

Group name. Id no

1jemal Ibrahim. 0461

2bedry sani. 0145

3mulu zeleke 0596

4hayu chemeda 0424

5 abreham jemberu. 0040

1, import java.util.Scanner;

public class NumberAnalyzer {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.print("Enter the first number: ");


double num1 = input.nextDouble();

System.out.print("Enter the second number: ");

double num2 = input.nextDouble();

System.out.print("Enter the third number: ");

double num3 = input.nextDouble();

double sum = num1 + num2 + num3;

double average = sum / 3;

double max = num1;

if (num2 > max) {

max = num2;

if (num3 > max) {

max = num3;

double min = num1;

if (num2 < min) {

min = num2;

if (num3 < min) {

min = num3;
}

System.out.println("Sum: " + sum);

System.out.println("Average: " + average);

System.out.println("Maximum: " + max);

System.out.println("Minimum: " + min);

2, Here is a Java program that accepts 10 constant integer numbers and computes the square root and
power of 2 of the numbers:

```

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

int[] numbers = new int[10];

System.out.println("Please enter 10 numbers:");

for (int i = 0; i < numbers.length; i++) {

numbers[i] = scanner.nextInt();

}
for (int i = 0; i < numbers.length; i++) {

System.out.println("The square root of " + numbers[i] + " is " + Math.sqrt(numbers[i]));

System.out.println("The power of 2 of " + numbers[i] + " is " + Math.pow(numbers[i], 2));

```

First, we create a Scanner object to read user input. We also create an array called `numbers` that will
store the 10 numbers entered by the user.

We then prompt the user to enter 10 numbers and use a loop to read and store them in the `numbers`
array.

Finally, we use another loop to compute the square root and power of 2 of each number in the
`numbers` array using the `Math.sqrt()` and `Math.pow()` functions, respectively, and print the results
to the console.

One possible solution using a parameterized constructor and an ArrayList:

```

3, import java.util.ArrayList;

public class Group_Name {

private String fullName;

private String idNo;

private String gender;


private String department;

public Group_Name(String fullName, String idNo, String gender, String department) {

this.fullName = fullName;

this.idNo = idNo;

this.gender = gender;

this.department = department;

public String getFullName() {

return fullName;

public String getIdNo() {

return idNo;

public String getGender() {

return gender;

public String getDepartment() {

return department;

}
public static void main(String[] args) {

ArrayList<Group_Name> group = new ArrayList<>();

group.add(new Group_Name("jemal ibrahim", "0461", "Male", "information system"));

group.add(new Group_Name("badry sani", "0145", "male", "information system"));

group.add(new Group_Name("mulu zeleke", "345678", "Male", "information system"));

group.add(new Group_Name("abreham jenberu", " ", "male", "information system");

group.add(new Group_Name("hayu chemada", " ", "male", "information system");

System.out.println("FullName\tIDNO\t\tGender\tDepartment");

for (Group_Name member : group) {

System.out.println(member.getFullName() + "\t" + member.getIdNo() + "\t" +

member.getGender() + "\t" + member.getDepartment());

```

Output:

```

FullName IDNO Gender Department

jemal ibrahim 0461 Male informatin system

badry sani 0145 male information system

mulu zeleke 0596 Male information system

abreham jenberu 0040 male information system

hayu chemada 0424 male information sytem


4, import java.util.Scanner;

public class StudentInfo {

public static void main(String[] args) {

// Create Scanner object for user input

Scanner input = new Scanner(System.in);

// Initialize arrays to hold student information

String[] studentNames = new String[5];

String[] courseNames = new String[5];

int[] scores = new int[5];

String[] gradePoints = new String[5];

// Accept user input for student information and store in arrays

for (int i = 0; i < 5; i++) {

System.out.println("Enter student #" + (i+1) + "'s information:");

System.out.print("Name: ");

studentNames[i] = input.nextLine();

System.out.print("Course Name: ");

courseNames[i] = input.nextLine();

System.out.print("Score: ");

scores[i] = input.nextInt();

input.nextLine(); // consume leftover newline character


System.out.print("Grade Point: ");

gradePoints[i] = input.nextLine();

// Output the student information

System.out.println("\nStudent Information:");

for (int i = 0; i < 5; i++) {

System.out.println("Name: " + studentNames[i]);

System.out.println("Course Name: " + courseNames[i]);

System.out.println("Score: " + scores[i]);

System.out.print("Grade: ");

if (scores[i] >= 90) {

System.out.println("A");

} else if (scores[i] >= 80) {

System.out.println("B");

} else if (scores[i] >= 70) {

System.out.println("C");

} else if (scores[i] >= 60) {

System.out.println("D");

} else {

System.out.println("F");

} System.out.println("Grade Point: " + gradePoints[i]);

System.out.println(); // add blank line for readability

}
5, Abstract Window Toolkit (AWT) is a collection of classes that Java
developers can use to create graphical user interfaces (GUI) for their
applications. It provides a way for developers to create windows, dialogs,
buttons, menus, and other common GUI components that users interact with.
AWT has been around since the early days of Java and is still used in many Java
applications today.

Java Virtual Machine (JVM) is the foundation of the Java platform. It is a virtual machine that is
responsible for executing Java bytecode, which is the compiled form of Java source code. JVM takes
care of memory management, garbage collection, and other low-level details that make Java a portable
and secure programming language. JVM also provides a sandbox environment that isolates Java
applications from the operating system and other applications running on the same machine.

Java applets are small programs that run inside web browsers. They were popular in the early days of
the web and were used to add interactivity to static HTML pages. Applets are still used today, but their
popularity has decreased due to security concerns and the rise of web technologies like JavaScript and
HTML5.

Java Swing is a set of GUI components that were introduced in Java 2. Swing is written entirely in Java
and offers a more modern and flexible approach to GUI development compared to AWT. Swing
provides a wide range of components, from basic buttons and labels to complex tables and trees. It is
widely used by Java developers today.

Pros of AWT:

- AWT is lightweight and fast compared to Swing.

- It has been around for a long time and is well-established.

- AWT components have a consistent look and feel across different platforms.

Cons of AWT:
- AWT components have limited functionality compared to Swing.

- It lacks support for modern UI features like transparency, alpha blending, and custom skins.

- AWT has a limited selection of layout managers, making it difficult to create complex UI layouts.

Pros of JVM:

- JVM provides a high level of portability, allowing Java code to run on any platform that has a JVM
installed.

- It offers a secure sandbox environment that isolates Java code from the operating system and other
applications.

- JVM provides automatic memory management and garbage collection, making it easy to write
memory-safe code.

Cons of JVM:

- JVM has a relatively high startup time compared to native applications.

- It can have a higher memory footprint compared to native applications.

- JVM is not as fast as native applications, especially for compute-intensive tasks.

Pros of Java applets:

- Applets can run on any machine that has a JVM installed, making them highly portable.

- They are easy to develop, as they can reuse existing Java code.

- Applets can offer a rich and interactive user experience, similar to native desktop applications.

Cons of Java applets:


- Applets have fallen out of favor due to security concerns and the rise of web technologies like
JavaScript and HTML5.

- They have a higher startup time compared to JavaScript applications.

- Applets require user permission to run, making it difficult to use them for certain applications.

Pros of Java Swing:

- Swing provides a wide range of GUI components that are highly customizable.

- It offers support for modern UI features like transparency, alpha blending, and custom skins.

- Swing has a wide selection of layout managers, making it easy to create complex UI layouts.

Cons of Java Swing:

- Swing can have a higher memory footprint compared to AWT.

- It has a steeper learning curve compared to AWT.

- Swing can be slower than AWT for simple UI components.:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy