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

Please help with my Java Homework 1. Provide the code segment for a method that

ID: 3838320 • Letter: P

Question

Please help with my Java Homework

1. Provide the code segment for a method that receives two double values, calculates the product, and returns the result.

II. Provide a code segment in Java that realizes the following processes

2. A certain integer array is declared as shown below. Provide a code segment that allows access to every data cell. (10 points)

int[][] ar1 = { {2,4}, {5,9,1}, {2}}

III. For the following code related to Strings, state the value of each variable when the code execution reaches each of the commented “checkpoints”. (10 points)

String st1 = "CPEN";

String st2 = "358";

String st3 = "SNL 252";

String st4 = "";

String st5;

//CHECKPOINT A

st1.toLowerCase()

st3 = st3.toLowerCase();

if(st2.equals("358")){

      st5 = " Yes ";

}

else{

      st5 = " No ";

}

//CHECKPOINT B

st3.replace(" ", "-");

st5 = st1 + st2;

st3 = "EDI" + st3.substring(4);

//CHECKPOINT C

st5 = st5.trim();

st2 + st4;

//CHECKPOINT D

Explanation / Answer

1)

//This method will receives two double values and calculate the product
   private static double calProduct(double val1, double val2) {
      
       return val1*val2;
   }

___________

Complete Program regarding above method:

package org.students;

import java.util.Scanner;

public class Product {

   public static void main(String[] args) {
       //declaring variables
       double val1,val2;
      
       //Scanner object is used to get the inputs entered by the user
       Scanner sc=new Scanner(System.in);
      
       //getting the numbers entered by the user
       System.out.print("Enter the value 1 :");
       val1=sc.nextDouble();
      
       System.out.print("Enter the value 2 :");
       val2=sc.nextDouble();
      
       //calling the method
       double result=calProduct(val1,val2);

          System.out.printf("The product of %.2f and %.2f is :%.2f",val1,val2,result );
   }

   //This method will receives two double values and calculate the product
   private static double calProduct(double val1, double val2) {
      
       return val1*val2;
   }

}

_________________

Output:

Enter the value 1 :45.6
Enter the value 2 :56.7
The product of 45.60 and 56.70 is :2585.52

______________

2)

IrregularArray.java

public class IrregularArray {

   public static void main(String[] args) {
       int arr1[][]={{2,4},{5,9,1},{2}};
      
       for(int i=0;i<arr1.length;i++)
       {
           for(int j=0;j<arr1[i].length;j++)
           {
               System.out.print(arr1[i][j]+" ");
           }
           System.out.println();
       }

   }

}

_________________

Output:

2 4
5 9 1
2

_____________

3)

CHECKPOINT A

st1=CPEN
st2=358
st3=SNL 252

st4="";

st5=null; //Not pointing to anything

__________________

CHECKPOINT B

st1=CPEN
st2=358
st3=snl 252

st4="";

st5=Yes

___________________

CHECKPOINT C

st1=CPEN
st2=358
st3=EDI252

st4="";

st5=CPEN358

_________________

CHECKPOINT D

st1=CPEN
st2=358
st3=EDI252

st4="";

st5=CPEN358

__________________Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote