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

JAVA*****JAVA*****JAVA***** 1. Write two methods that demonstrate method overloa

ID: 3712793 • Letter: J

Question

JAVA*****JAVA*****JAVA*****

1. Write two methods that demonstrate method overloading

2. Write a program using Arrays.toString() to print out the values in a two-dimensional array

3. Write a method that returns the average of all the numbers in a two-dimensional array

4. Write a method that accepts three numbers and displays them in increasing order. For instance, method(2, 5, 1) returns 1 2 5.

5. Write a program that reads in eight numbers. The program then stores and displays an array of numbers that appear multiple times. Here is a sample run: Enter 8 numbers: 1, 1, 2, 3, 4, 5, 5, 6 Repeated numbers are: 1, 5

6. Write a program that generates a 6 by 6 two-dimensional array filled randomly with 0s and 1s.

7. Write a program that prompts the user to enter the number of students, the student’s names, and their scores. The program then prints the student names in decreasing order of their scores.

8. Design a class named rectangle. The class contains: a. Two double data fields named width and length, with default values of 1 for both. b. A no-arg constructor that creates a default rectangle c. A constructor that creates a rectangle with a user-specified width and length d. A method named getArea() that returns the area of the rectangle e. A method named getPerimeter() that returns the perimeter of the rectangle

9. Name and describe the differences between the three visibility modifiers

10. Assume a Student class has two variables: Name and Grade. Write an example of a get method and a set method for each of the two variables

JAVA*****JAVA*****JAVA*****

Explanation / Answer

1) Example of method overloading is:

int sum(int a,int b)

{

   return (a+b);

}

int sum(double a,double b)

{

   int c=(int)a+(int)b;

return c;

}

2) class Id
{
  
  
   public static void main (String[] args)
   {
       int arr[][]={{1,2},{3,4},{5,6}};
       System.out.println(Arrays.deepToString(arr));
   }
}

3) int average(int arr[][])
{
    int sum=0;
    int coun=0;
    for(int i=0;i<arr.length;i++)
    {
        for(int j=0;j<arr[j].length;j++)
        {
            sum=sum+arr[i][j];
            coun++;
        }
    }
    return sum/coun;
}

4) void Sort(int a, int b, int c) {
           
       int temp;
      
       if (b < a && b < c){
           temp = a;
           a=b;
           b= temp;
       }
       else if (c<a&&c<b) {
           temp = a;
           a= c;
           c= temp;
       }
       if (c< b) {
           temp = b;
           b=c;
           c=temp;
       }
       System.out.println(a + " " + b + " " + c);
}

5) Class Id{

void repeated()

{

   Scanner sc=new Scanner(System.in);

int arr[8];

int coun[100000]={0};

for(int i=0;i<8;i++)

{

arr[i]=sc.nextInt();

coun[arr[i]]++;

}

for(int i=0;i<100000;i++)

{

if(coun[i]>1)

System.out.println(i);

      }

public static void main(String args[])

{

    Id id=new Id();

id.repeated();

}

}

6) void random()

{

   int arr[][]=new int[6][6];

for(int i=0;i<6;i++)

{

   for(int j=0;j<6;j++)

{

   arr[i][j]=Math.random();

}

}

}