Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1- Write a java class named Circle that have a field named radius and have a met

ID: 3834016 • Letter: 1

Question

1- Write a java class named Circle that have a field named radius and have a method named getArea that computes the area of a circle with radius r. Your main method should looks like this.
public class Circle {

public static void main(String[] args) {

double radius = 3;

Circle myCircle = new Circle(radius);

double area = myCircle.getArea();

System.out.printf("Area: %.2f ", area);

}

}

2- Write a java class for Student and define at least three fields for it. The student class has a method named printInfo which prints the value of these fields. Also, define classes for UndergraduateStudent and GraduateStudent. Define at least one extra field for these sub classes. In the main method, create objects for undergraduate and graduate students and print their information.

3- Write a java class named FiboNumber for Fibonacci numbers. This class has a field for integer n. The method fibValue will return the Fibonacci number for value n (the return type is integer). Print the value of Fibonacci numbers for 3, 10 and 15 as input on the main method.

Please help me.

Explanation / Answer

import java.util.*;
import java.lang.*;
import java.io.*;

class Circle
{
public static void main(String args[])
{
Scanner scan = new Scanner(System.in);
System.out.println(" Enter the radius of a Circle:");
double radius = scan.nextDouble();
double area = getArea(radius);
System.out.print(" Area of a Circle is:" +area);
}
public static double getArea(double rad)
{
return (3.14 * rad * rad);
}
}

OUTPUT:
  
Enter the radius of a Circle: 5

Area of a Circle is:78.5

-------------------------------------------------------------------------------------------------------------------------------------


import java.util.*;
import java.lang.*;
import java.io.*;
class Fibonacci
{
static int n1=0, n2=1, n3;
public static void fibvalue(int n)
{
if(n > 0)
{
n3 = n1 + n2;
n1 = n2;
n2 = n3;
System.out.print(" " +n3);
fibvalue(n-1);
}
}
public static void main(String args[])
{
int n = 3;
System.out.println(" Fibonacci Series");
System.out.print(n1 + " " +n2);
fibvalue(n-2);
}
}


OUTPUT


Fibonacci Series
0 1 1

----------------------------------------------------------------------------------------------------------------------------------------------


import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Scanner;
class Student
{
int coll_rollno;
String coll_name;
Student()
{
coll_name = "null";
coll_rollno = 0;
}
public Student(String name,int rollno)
{
coll_name = name;
coll_rollno = rollno;
}
public void undergraduate()
{
Scanner scan = new Scanner(System.in);
System.out.println(" Enter Student name:");
coll_name = scan.nextLine();
System.out.println(" Enter UG College Rollno:");
coll_rollno = scan.nextInt();
}
public void graduate()
{
System.out.println(" Enter Student name:" +coll_name);
System.out.println(" Enter UG College Rollno:" +coll_rollno);
}
}
class Student_det
{
   public static void main(String args[])
   {
   Student stud = new Student();
   stud.undergraduate();
   stud.graduate();
   }
}


OUTPUT


Enter Student name: jagan
Enter UG College Rollno: 20155
Enter Student name:jagan
Enter UG College Rollno:20155