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

Create a new Java project using NetBeans, giving it the name Lab4 . In Lab4Part1

ID: 3872055 • Letter: C

Question

Create a new Java project using NetBeans, giving it the name Lab4.

In Lab4Part1 do the following:Write the main method that will test the following methods:

Write the method to convert Celsius to Fahrenheit.

Write the method to convert Fahrenheit to Celsius

Write a method operator(a,b,c) which will receive 2 integers and one of the 5 operators (*,/,+ -, %) as a character and perform the operation and return the integer value . Example operator(2,3,’*’) will return a 6. (assume no division by zero!))

Write the overloaded method operator(a,b,c) which will receive 2 doubles and one of the 4 operators (*,/,+ -) as a character and perform the operation and return the integer value . Example operator(2.1,3,’*’) will return a 63. (assume no division by zero!))

Write the method sumOfDigits(a) which will receive and integer and return the sum of their digits. (This was a lab!!) Example sumOfDigits(941) return 15.

Enter the following code and explain in comments what is happening

public class Lab4Part2 {

    /* The methods below illustrate invoking methods from other methods.

     * Review the code provided, and show the order in which

     * all of the methods are called.

     *

     * Trace the calls by hand yourself, then confirm your answer by

     * running the code.

     *

     * Note that the method calls are preceded by the name of the class.

     * In main, add at least 3 calls to the methods you created

     * from part 1 using any test values you wish.

     */

    public static void a(){

        System.out.println(" a in ");

        System.out.println(" a out ");

    }//a

    public static void b(){

        System.out.println(" b in ");

        Lab4Part2.a();

        System.out.println(" b out ");

    }//b

    public static void c(){

        System.out.println("c in ");

        Lab4Part2.a();

        Lab4Part2.b();

        System.out.println("c out ");

    }//c

    public static void main(String[] args) {

       System.out.println("main in ");

       Lab4Part2.a();

       Lab4Part2.b();

       Lab4Part2.c();

       System.out.println("main out ");

    }//main

}//class

Add another class to your Lab4 project, and name this class Lab4Part3. In this class, create an isAscending method that accepts 3 integer numbers. The method should return true if the numbers are in ascending order. Write a main method that tests your isAscending method. Your main should display the numbers tested along with the result, such as

The numbers 20, 40, and 50 are in ascending order

The numbers 20, 14, and 9 are NOT in ascending order

In your main invoke your method 3 times, once with numbers that are ascending, once with numbers that are not ascending, and once with numbers that are the same. Copy and paste your output.

Make sure your code is readable, indented and spaced.

Explanation / Answer

/**********************Lab4Part2.java*******************/

import java.util.Scanner;

/**

* The Class Lab4Part2.

*/

public class Lab4Part2 {

/*

* The methods below illustrate invoking methods from other methods. Review

* the code provided, and show the order in which all of the methods are

* called.

*

* Trace the calls by hand yourself, then confirm your answer by running the

* code.

*

* Note that the method calls are preceded by the name of the class. In

* main, add at least 3 calls to the methods you created from part 1 using

* any test values you wish.

*/

/**

* Fahrenheit to celsius.

*

* @param fahrenheit

* the fahrenheit

*/

public static void fahrenheitToCelsius(double fahrenheit) {

double celsius = (5.0 / 9.0) * (fahrenheit - 32);

System.out.println("Fahrenheit To Celsius: " + celsius);

}

/**

* Celsius to Fahrenheit.

*

* @param celsius

* the celsius

*/

public static void celsiusToFahrenheit(double celsius) {

double fahrenheit = (9.0 / 5.0) * celsius + 32;

System.out.println("Celsius To Fahrenheit: " + fahrenheit);

}

/**

* Operator.

*

* @param a

* the a

* @param b

* the b

* @param c

* the c

* @return the int

*/

public static int operator(int a, int b, char c) {

switch (c) {

case '+':

return a + b;

case '*':

return a * b;

case '/':

return a / b;

case '%':

return a % b;

case '-':

return a - b;

default:

return -1;

}

}

/**

* Operator.

*

* @param a

* the a

* @param b

* the b

* @param c

* the c

* @return the int

*/

public static int operator(double a, double b, char c) {

switch (c) {

case '+':

return (int) (a + b);

case '*':

return (int) (a * b);

case '/':

return (int) (a / b);

case '-':

return (int) (a - b);

default:

return -1;

}

}

/**

* Sum of digits.

*

* @param number

* the number

* @return the int

*/

public static int sumOfDigits(int number) {

int sum = 0;

int num = number;

while (num != 0) {

int remainder = num % 10;

sum += remainder;

num = num / 10;

}

return sum;

}

/**

* The main method.

*

* @param args

* the arguments

*/

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.println("Please Enter temerature in Fahrenheit: ");

double fahrenheit = input.nextDouble();

fahrenheitToCelsius(fahrenheit);

System.out.println("Please Enter temerature in Celsius: ");

double celsius = input.nextDouble();

celsiusToFahrenheit(celsius);

System.out.println("Operator method with Integers");

System.out.println("Sum is: " + operator(1, 2, '+'));

System.out.println("Multiplication is: " + operator(2, 3, '*'));

System.out.println("Operator method with Double");

System.out.println("Sum is: " + operator(2.1, 3, '*'));

System.out.println("SumOfDigits method calling");

System.out.println(sumOfDigits(941));

}// main

}// class

/***********************output*****************************/

Please Enter temerature in Fahrenheit:
100
Fahrenheit To Celsius: 37.77777777777778
Please Enter temerature in Celsius:
45
Celsius To Fahrenheit: 113.0
Operator method with Integers
Sum is: 3
Multiplication is: 6
Operator method with Double
Sum is: 6
SumOfDigits method calling
14

/******************************Lab4Part3.java*************************/

/**

* The Class Lab4Part3.

*/

public class Lab4Part3 {

/**

* Checks if is ascending.

*

* @param a

* the a

* @param b

* the b

* @param c

* the c

* @return true, if is ascending

*/

public static boolean isAscending(int a, int b, int c) {

if (a <= b) {

if (b <= c) {

return Boolean.TRUE;

}

}

return Boolean.FALSE;

}

/**

* The main method.

*

* @param args

* the arguments

*/

public static void main(String[] args) {

// Tesing

System.out.println(isAscending(20, 40, 50));

System.out.println(isAscending(20, 14, 9));

System.out.println(isAscending(20, 20, 20));

}

}

/************************output**********************/

true
false
true

Thanks a lot.

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