ACTIVITY 4.10.1: Improve the Rearrange the following lines of code to produce an improved version of the intName method. One line is not useful. How to use this tool Unused return name; if (part >= 20) { name = name + Helper.tensName(part) + ""; part = part % 10; } else if (part >= 10) { name = name + Helper.teenName(part); part = 0; } if (part > 0) { name = name + Helper.digitName(part); } if (part >= 100) Check IntegerName.java import java.util.Scanner; public class IntegerName { /* Turns a number into its English name. @param number a positive integer < 10,000 @return the English name of the number */ public static String intName(int number) { // The part that still needs to // be converted int part = number; // The return value String name = ""; } public static void main (String [] args) { } Load default template...
Added by Lorena F.
Close
Step 1
In this case, the line "Unused importjava.util.Scanner;" is not useful and can be removed. Show more…
Show all steps
Your feedback will help us improve your experience
Akash M and 59 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
5.2.4: Produce a method that computes the area of a square Select and arrange the lines of code needed to produce a method squareArea that computes the area of a square of a given side length. Not all lines are useful. Unused Area.java Load default template.. return squareArea; import java.util.Scanner; public class Area { public static double squareArea(double sideLength) { double area = sideLength * sideLength; return area; } public static void main(String[] args) { Scanner in = new Scanner(System.in); double squareSideLength = in.nextDouble(); double area = squareArea(squareSideLength); System.out.println(area); } }
Akash M.
Please fix the code provided on GitHub (Week11 => ClassLabAggregation => Circle.java). Code: Please follow the instructions provided inside the file. Lab 10 (Aggregation) Please fix the code provided on GitHub (Week11 => ClassLabAggregation => Circle.java). Please follow the instructions provided inside the file. Main X The area of a circle is 78.5 Process finished with exit code 0
12.1.5: Handling input exceptions: restaurant max occupancy tracker. Arrange the following lines to make a program that determines when the number of people in a restaurant equals or exceeds 10 occupants. The program continually gets the number of people entering or leaving the restaurant. Ex: 2 means two people entered, and -3 means three people left. After each input, the program outputs the number of people in the restaurant. Once the number of people in the restaurant equals or exceeds 10, the program exits. If an InputMismatchException exception occurs, the program should get and discard a single string from input. Ex: The input '2 abc 8' should result in 10 occupants. Not all lines are used in the solution. import java.util.Scanner; import java.util.InputMismatchException; public class MaxOccupancyTracker { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int maxNumPeople = 10; int totalNumPeople = 0; while (totalNumPeople < maxNumPeople) { try { totalNumPeople += scnr.nextInt(); System.out.println("Occupancy: " + totalNumPeople); } catch (InputMismatchException e) { scnr.next(); } } System.out.println("We're full!"); } }
Supreeta N.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD