0% found this document useful (0 votes)
11 views4 pages

Java Program Assignment Examples

The document contains Java assignment programs that cover three tasks: collecting student details including name, roll number, grade, and percentage; creating a Student class with a default constructor and a Commission class to calculate sales commission; and defining a Circle class to calculate the area based on user input for radius and color. Each assignment includes sample input and output along with the corresponding Java code. The programs utilize Scanner for user input and demonstrate basic object-oriented programming concepts.

Uploaded by

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

Java Program Assignment Examples

The document contains Java assignment programs that cover three tasks: collecting student details including name, roll number, grade, and percentage; creating a Student class with a default constructor and a Commission class to calculate sales commission; and defining a Circle class to calculate the area based on user input for radius and color. Each assignment includes sample input and output along with the corresponding Java code. The programs utilize Scanner for user input and demonstrate basic object-oriented programming concepts.

Uploaded by

biggod151004
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Assignment Programs

Assignment Question - 1

Assignment Question -1

Write a Java program to get your Full name, Roll number, Grade, and Percentage.

Sample Input:
Ayan S
5220365
A
9.5%

Sample Output:
Ayan S
5220365
A
9.5%
---------------------------------------------
import [Link];

public class StudentDetails {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

[Link]("Enter Full Name with Initial: ");


String fullName = [Link]();

[Link]("Enter Roll Number: ");


String rollNumber = [Link]();

[Link]("Enter Grade: ");


String grade = [Link]();

[Link]("Enter Percentage: ");


String percentage = [Link]();

[Link]("\n" + fullName);
[Link](rollNumber);
[Link](grade);
[Link](percentage);

[Link]();
}
}

Assignment Question - 2
Java Assignment Programs

Assignment Question -2

Create a default constructor in the class Student that prints a message.


Define a class Commission with methods to calculate sales commission.

---------------------------------------------
import [Link];

class Student {
Student() {
[Link]("Student object is created");
}
}

class Commission {
String name, address;
String phone;
double salesAmount;

void acceptDetails() {
Scanner sc = new Scanner([Link]);

[Link]("Enter Name: ");


name = [Link]();

[Link]("Enter Address: ");


address = [Link]();

[Link]("Enter Phone: ");


phone = [Link]();

[Link]("Enter Sales Amount: ");


salesAmount = [Link]();
}

void calculateCommission() {
double commission = 0;

if (salesAmount >= 100000) {


commission = salesAmount * 0.10;
} else if (salesAmount >= 50000) {
commission = salesAmount * 0.05;
} else if (salesAmount >= 30000) {
commission = salesAmount * 0.03;
} else {
commission = 0;
}

[Link]("Commission for " + name + " is: Rs." + commission);


}
Java Assignment Programs

public class SalesCommissionDemo {


public static void main(String[] args) {
Student studentObj = new Student();

Commission emp = new Commission();


[Link]();
[Link]();
}
}

Assignment Question - 3

Assignment Question -3

Define a class Circle with radius and color.


Create methods to get input and calculate area.

---------------------------------------------
import [Link];

class Circle {
double radius;
String color;

void getInput() {
Scanner sc = new Scanner([Link]);

[Link]("Enter Radius of Circle: ");


radius = [Link]();
[Link]();

[Link]("Enter Color of Circle: ");


color = [Link]();
}

void calcArea() {
double area = [Link] * radius * radius;
[Link]("Circle Color: " + color);
[Link]("Area of Circle: " + area);
}
}

public class CircleDemo {


public static void main(String[] args) {
Circle c = new Circle();
[Link]();
Java Assignment Programs

[Link]();
}
}

You might also like