Java: An Introduction to Problem Solving and Programming (7th Edition)
Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
Author: Walter Savitch
Publisher: PEARSON
Expert Solution & Answer
Book Icon
Chapter 6.4, Problem 34STQ

Explanation of Solution

Program:

Given code:

//Define the method "convertValue()"

public static int convertValue(double number)

{

    //Initialize the variable

    int result = 0;

    //Check the condition

    if(number > 0.0)

/*True, assign the value to the variable "result"*/

        result = (int)number;

    //Return the value

    return result;

}

//Define the method "convertValue()"

public static double convertValue(int number)

{

    //Initialize the variable

    double result = 0;

    //Check the condition

    if(number > 0...

Blurred answer
Students have asked these similar questions
mport java.util.Scanner; public class ParkingCharges {     // function to calculate the basic charge using the asked hours    static double getBasicCharge(int hours) {        if (hours >= 7 && hours <= 8)            return 5.50;        else if (hours >= 5 && hours <= 6)            return 4.50;        else if (hours >= 2 && hours <= 4)            return 4.00;        return 3.00;    }     // function to return the amount to subtract based on local living and OAP    static double getDiscount(String isLocal, String isOAP) {        if (isOAP.equals("Yes") && isLocal.equals("Yes"))            return 2.0 + 1.0;        else if (isOAP.equals("Yes"))            return 2.0;        else if (isLocal.equals("Yes"))            return 1.0;        return 0;    }     public static void main(String[] args) {        // create a new Scanner object        Scanner sc = new Scanner(System.in);         // prompt the user to ask if they are disabled…
int test(int *x, int y){ x=&y; return(*x+y); } int main(void) { int x=1, y=6; test(&y, x); printf("%d %d %d", x, test (&y,x),y); return 0; } 1 2 6
7    public static int test1(int x1, int x2){  8           9         if(x1==0){ 10            x1=10; 11         } 12         if(x2==0){ 13            x2=10 14         } 15          16         return x1*x2; 17    } 18     19    public static int test2(int x2, int x1){ 20         return x2-x1; 21    } 22    public static int input(){ //Don’t need to trace through             //this method to show how it works.  Just assume it pulls         //the value for the user. 23       Scanner keyboard = new Scanner(new BufferedReader(new InputStreamReader(System.in))); 24       int counter=0; 25       System.out.print("Please enter an integer:  "); 26       while(counter<3 && !keyboard.hasNextInt()) 27       { 28           System.out.println(); 29           String temp=keyboard.next(); 30           System.out.println(temp+" is not an integer.  Please reenter an integer."); 31           counter++; 32            33       } 34       return keyboard.nextInt(); 35    } 36  37  38…

Chapter 6 Solutions

Java: An Introduction to Problem Solving and Programming (7th Edition)

Ch. 6.2 - Can you reference an instance variable by name...Ch. 6.2 - Is the following valid, given the class...Ch. 6.2 - Prob. 13STQCh. 6.2 - Prob. 14STQCh. 6.2 - Prob. 15STQCh. 6.2 - Is the following valid, given the class...Ch. 6.2 - What values are returned by each of the following?...Ch. 6.2 - Suppose that speed is a variable of type double...Ch. 6.2 - Repeat the previous question, but instead assign...Ch. 6.2 - Suppose that nl is of type int and n2 is of type...Ch. 6.2 - Define a class CircleCalculator that hat only two...Ch. 6.2 - Which of the following statements are legal?...Ch. 6.2 - Write a Java expression to convert the number in...Ch. 6.2 - Consider the variable 5 of type String that...Ch. 6.2 - Repeat the previous question, but accommodate a...Ch. 6.2 - Write Java code to display the largest and...Ch. 6.3 - Prob. 27STQCh. 6.3 - Consider the variable allCents in the method...Ch. 6.3 - What is wrong with a program that starts as...Ch. 6.3 - Prob. 30STQCh. 6.3 - In your definition of the class OutputFormat. In...Ch. 6.4 - Prob. 32STQCh. 6.4 - Prob. 33STQCh. 6.4 - Prob. 34STQCh. 6.4 - Consider the class Species in Listing 5.19 of...Ch. 6.4 - Repeat the previous question for a method...Ch. 6.4 - Still considering the class Species in Listing...Ch. 6.4 - Rewrite the method add in Listing 6.16 so that it...Ch. 6.4 - In Listing 6.16, the set method that has a String...Ch. 6.5 - Give the definitions of three accessor methods...Ch. 6.6 - If cardSuit is an instance of Suit and is assigned...Ch. 6.7 - Suppose you want to use classes in the package...Ch. 6.7 - Prob. 43STQCh. 6.7 - Can a package have any name you might want, or are...Ch. 6.7 - On your system, place the class Pet (Listing 6.1)...Ch. 6.8 - Prob. 46STQCh. 6.8 - Prob. 47STQCh. 6.8 - Prob. 48STQCh. 6.8 - Prob. 49STQCh. 6.8 - Prob. 50STQCh. 6.8 - Prob. 51STQCh. 6.8 - Revise the applet in Listing 6.24 so that the...Ch. 6 - Prob. 1ECh. 6 - Prob. 2ECh. 6 - Write a default constructor and a second...Ch. 6 - Write a constructor for the class...Ch. 6 - Consider a class characteristic that will be used...Ch. 6 - Create a class RoomOccupancy that can be used to...Ch. 6 - Write a program that tests the class RoomOccupancy...Ch. 6 - Sometimes we would like a class that has just a...Ch. 6 - Create a program that tests the class Merlin...Ch. 6 - In the previous chapter, Self-Test Question 16...Ch. 6 - Create a class Android whose objects have unique...Ch. 6 - Prob. 12ECh. 6 - Modify the definition of the class Species in...Ch. 6 - Prob. 2PCh. 6 - Using the class Pet from Listing 6.1, write a...Ch. 6 - Do Practice Program 4 from Chapter 5 except define...Ch. 6 - The following class displays a disclaimer every...Ch. 6 - Do Practice Program 5 from Chapter 5 but add a...Ch. 6 - We can improve the Beer class from the previous...Ch. 6 - Define a utility class for displaying values of...Ch. 6 - Write a new class TruncatedDollarFormat that is...Ch. 6 - Complete and fully test the class Time that...Ch. 6 - Complete and fully test the class Characteristic...Ch. 6 - Write a Java enumeration LetterGrade that...Ch. 6 - Complete and fully test the class Per n that...Ch. 6 - Write a Temperature class that represents...Ch. 6 - Repeat Programming Project 8 of the previous...Ch. 6 - Write and fully test a class that represents...Ch. 6 - Write a program that will record the votes for one...Ch. 6 - Repeat Programming Project 10 from Chapter 5, but...Ch. 6 - Prob. 12PPCh. 6 - Prob. 13PPCh. 6 - Prob. 14PPCh. 6 - Prob. 15PP
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage