Concept explainers
Consider the variable allCents in the method writePositive in Listing 6.14. It holds an amount of money as if it were all cents. So for the amount $12.95, the int variable allCents would be set to 1295. Using an int variable is somewhat limiting. The largest value of type int is 2147483647, meaning that the largest amount the method can handle a $21,474,836.47. That is more than $21 million, a nice large sum, but we often need to consider larger amounts, such as the national budget or even the salary for the CEO of a large company. How can you easily change the definitions of the methods in the class DollarFormat so that they handle larger amounts of money?
Want to see the full answer?
Check out a sample textbook solutionChapter 6 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Additional Engineering Textbook Solutions
Programming in C
Starting Out with C++: Early Objects (9th Edition)
Problem Solving with C++ (9th Edition)
Starting Out with Java: From Control Structures through Objects (6th Edition)
C++ How to Program (10th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
- Write a method call for a non-static method name convertFah that converts a temperature from Fahrenheit to Celsius ( ( (F – 32) where F is the Fahrenheit temperature and C is the Celsius temperature). Given the class name is convertTemp. (a)arrow_forwardJava Program Give comment to explain the code please. Write a program that calls these two methods as described below A void method that ask user to input an integer to be a parameter and prints following pattern. For example, the user entered 5 as input, the pattern will be: 5 4 3 2 1 5 4 3 2 5 4 3 5 4 5 b. A void method takes Sting as a parameter. Then print out all the vowels in the string. Example given below:arrow_forwardWrite a method (with a parameter n), n: integer type that prints numbers from 1 to n. The print out should be 5 numbers per line. All the output numbers should be aligned well. Call the method with n=13 and n=10 in the main()arrow_forward
- The method convertVolume() has an integer parameter. Define a second convertVolume() method that has two integer parameters. The first parameter is the number of gallons and the second parameter is the number of pints. The method should return the total number of pints. Ex: If the input is 9 2, then the output is: 9 gallons yields 72 pints. 9 gallons and 2 pints yields 74 pints. Note: The total number of pints can be found using (gallons * 8) + pints. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 import java.util.Scanner; public class VolumeMethods { publicstaticintconvertVolume(intgallons) { returngallons*8; } /* Your code goes here */ publicstaticvoidmain(String[] args) { Scannerscnr=newScanner(System.in); intgallonsUsed; intpintsUsed; inttotalPints1; inttotalPints2; gallonsUsed=scnr.nextInt(); pintsUsed=scnr.nextInt(); totalPints1=convertVolume(gallonsUsed);arrow_forwardWrite a Java method that generates and returns a random number between 2 valuesreceived as parameters. You must consider 2 cases when there are or not differencebetween values (please refer to slide 43 from 04 Methods). The function should checkif the difference is strictly positive otherwise replace it with the value 1.Test your method using main as follows (bold values are input by the user):Lowest value: 60Highest value: 100Diff. between values: 5Number of random numbers: 5060 90 70 65 70 60 75 100 100 8580 90 60 95 75 65 80 70 90 9085 65 95 60 85 95 75 85 60 7090 80 65 65 90 90 80 60 95 7560 90 70 70 90 60 65 60 85 60arrow_forwardIn java create a method long-isogram: determine the longest isogram in the paragraph. An isogram is a word that has no repeating letters.(Differences between uppercase and lowercase letters are ignored.) For example, “computer” is an isogram. The word“science” is not. If there happens to be more than one such longest isogram, then the first one in the paragraph can bechosen. Make certain to exclude any punctuation marks from your determination (for example, when the word appears atthe end of a sentence or contains an apostrophe). For example, the isogram “Kim’s” should be considered four characterslong, with the apostrophe ignored. Return the longest isogram on one line and its length on a second line whencommunicating back to the client. The method should accept a list of strings where each string is line of the paragraph The method should be public static String long_isogram(List<String> par){}arrow_forward
- You can just provide code as you don't have required utility class, Please provide explanation and comments for code : Write a static method asciiGraph(), to display a “graph” of ASCII values of a String. 2.The method has a single String parameter str, and returns nothing (void).3.The method loops through all characters in str, and for each displays a line of *s on a row equal to the ASCII/Unicode integer value of the character being examined (see example).Hints:1. recall the String methods .charAt() and .length(), and casting a char with (int) directly returns the int ASCII/Unicode value2. to produce the line of *s, call the method starLine() from the Exam utility class3. in the output capture document, consider reducing the font size to 7 or 8 point to have each row of *s on a single line Consider the strings “Ab C” and “TED 99”, that are composed of:A displays 65 stars (*), since Unicode 65 = 'A'b 98 stars (*), since Unicode 98 = 'b'space 32 * , since Unicode 32 = ' ' (the space)C…arrow_forwardjava program give comments for the code please. Write a program that calls these two methods as described below A void method that ask user to input an integer to be a parameter and prints following pattern. For example, the user entered 5 as input, the pattern will be: 5 4 3 2 1 5 4 3 2 5 4 3 5 4 5 b. A void method takes Sting as a parameter. Then print out all the vowels in the string. Example given below: Please enter a String. Christopher Vowel in the String:ioearrow_forwardAll the animals are having a feast! Each animal is bringing one dish. There is just one rule: the dish must start and end with the same letters as the animal's name. For example, the great blue heron is bringing garlic naan and the chickadee is bringing chocolate cake. Write a method that takes the animal's name and dish as arguments and returns true or false to indicate whether the beast is allowed to bring the dish to the feast. Assume that beast and dish are always lowercase strings, and that each has at least two letters. Beast and dish may contain hyphens and spaces, but these will not appear at the beginning or end of the string. They will not contain numerals.arrow_forward
- Define a method findAnnualMembership() that takes two integer parameters as a person's number of museum visits and the person's age, and returns the person's museum membership fee as an integer. The membership fee is returned as follows: Visits < 7 years 7 - 70 years > 70 years < 6 75 80 70 6 - 12 45 55 40 > 12 30 35 25 Ex: If the input is 5 6, then the output is: 75 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 import java.util.Scanner; public class MembershipFinder { /* Your code goes here */ publicstaticvoidmain(String[] args) { Scannerscnr=newScanner(System.in); intmuseumVisits; intuserAge; museumVisits=scnr.nextInt(); userAge=scnr.nextInt(); System.out.println(findAnnualMembership(museumVisits, userAge)); } }arrow_forwardImplement the main method below in a class called Grade. The program should read integer points (use the Scanner class) and print the grade (“A”, “B”, “C”, “D”, or “F”) based on the final score associated with a student. Grades are classified as follows: Number of Points Final Grade Greater than or equal to 90 A Between 80 (inclusive) and 90 (exclusive) B Between 70 (inclusive) and 80 (exclusive) C Between 60 (inclusive) and 70 (exclusive) D Less than 60 F Restrictions/Assumptions Use the message “Enter final score” to prompt the user to enter the number of points. Use the Scanner class to read the number of points, i.e., Scanner sc = new Scanner(System.in); Use System.out.println(...) to print the final grade. Assume that the user correctly enters an integer score. Start with this code: import java.util.Scanner; public class Grade { public static void main(String[] args) { For the toolbar, press ALT+F10 (PC) or ALT+FN+F10 (Mac)arrow_forwardModify the program below and add a public method called isZero() to the Fraction class. This method will determine if a Fraction represents a zero fraction. A zero fraction has a numerator == 0, no matter what the denominator is. Your isZero() method should return a Boolean resultindicating a zero fraction or otherwise. The method will be used by the client class to test whether the ‘calling fraction’ is equal to the number zero. Modify the program so that it now loops until a fraction representing zero is entered. //Import the essential package import java.util.ArrayList; import java.util.Scanner; //Define the class Fraction class Fraction { private int n, d; public Fraction() { //Initialize the values this.n = this.d = 0; } public Fraction(int n, int d) { //Initialize the variables this.n = n; this.d = d; } //Define the getter function getNum() that returns the numerator public int getNum() {…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education