EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 6, Problem 5PE
Explanation of Solution
Program:
File name: “Perfect.java”
//Import necessary header files
import java.util.*;
//Define a class named Perfect
public class Perfect
{
//Define main method
public static void main(String args[])
{
//Declare a variable
int i;
//Print the message
System.out.println("The perfect numbers in the range 1 to 1000 are:");
//For loop to print the perfect numbers between 1 and 1000
for(i = 1; i <= 1000; i++)
{
//Declare variables and initialize the value
int sum = 0, j;
//For loop is executed until the value of j exceeds i
for(j = 1; j < i; j++)
...Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write an application TestStudent that prompts for and reads a student name. It then creates a Student object. It then prompts for and reads the number of quizzes n that the student has taken. It then prompts for and reads the scores of the student in n quizzes and adds each to the totalScore of the student using addQuiz() method. Finally, the application prints the student object using the toString() method, and it also prints his quiz average.
The main method must handle java.util.InputMismatchException, java.lang.IllegalArgumentException and java.lang.Unsupported OperationException.
IN JAVA
When people enter their telephone numbers into a form they use many different formats. Some examples are: (444) 999-1234 4449991234 444.999.1234 In the PhoneNumbers class below, complete the cleanNumber method. It takes a string and extracts the numeric digits from the string. If there are exactly 10 numeric digits, the number is reformatted: (###) ###-#### and returned. If there are any other number of digits, the string "Error" is returned. Hint: Use the Character.isDigit method to check whether a character is a digit.
public class PhoneNumbers{ /** Cleans a phone number. @param phoneNumber a phone number that should contain ten digits and possibly other characters @return the phone number in the form (###) ###-#### or the string "Error" if phoneNumber does not have ten digits */ public String cleanNumber(String phoneNumber) { // your work here ... for (int i = 0; i < ...; i++) { char ch = phoneNumber.charAt(i);…
Write a Java application for Blizzy's car care Shop that shows a user a list of available services: oil change, tire rotation, battery check, or brake inspection. Allow the user to enter a string that corresponds to one of the options, and display the option and its price as R250, R220, R150, or R50, accordingly. Display an error message if the user enters an invalid item.
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Write an application named, Lab14.java. This application will do the following: 1. Display an introductory message 2. Choose a random word from the file, wordlist.txt, and display it 3. Disguise the selected word, and display it 4. Ask the user whether to continue, i.e., whether to repeat steps 2, 3, and 4, or quit the application Once the user chooses to stop the application: 5. Display the total number of vowels hidden 6. Display the total number of consonants hidden 7. Display termination message The user will be asked whether to continue playing and will indicate that another game is to be played by answering ‘y’ or ‘Y’ in response to the question, “Want to play again?” asked by the program after displaying each chosen word and its disguised version. If the user’s response is any character other than ‘y’ or ‘Y’, the totals are displayed and then the application termination message is displayed. See examples below. About randomly choosing a word from the file, wordlist.txt, found on…arrow_forwardJava Programming: Below is the lexer, shank and token files along with the shank.txt file. The shank file is the main method file. The lexer must break up the input text stream into lexemes and return a token object for each one in the shank.txt file. Make sure to fix the errors in the lexer.java file and show the complete code for lexer.java.There must be no error in the code at all. Run the whole code and show the output which the shank.txt must be printed out in the terminal. Attached is the rubric. Lexer.java package mypack; import java.util.HashMap;import java.util.List;import mypack.Token.TokenType; public class Lexer { private static final int INTEGER_STATE = 1;private static final int DECIMAL_STATE = 2;private static final int IDENTIFIER_STATE = 3;private static final int SYMBOL_STATE = 4;private static final int ERROR_STATE = 5;private static final int STRING_STATE = 6;private static final int CHAR_STATE = 7;private static final int COMMENT_STATE = 8; private static final…arrow_forwardWrite a java application for Limpopo’s Car Care Shop that shows a user a list of available services: oil change, tire rotation, battery check, or brake inspection. Allow the user to enter a string that corresponds to one of the options, and display the option and its price as R250, R220, R150, or R50, accordingly. Display an error message if the user enters an invalid item.arrow_forward
- This program uses Java. You will be making a general class that will be called “GeneralBusiness”. This class must have the following methods: selectSalesTax() – This method will read in a file “stateTaxInfo.txt” that has the name of a state and the tax percentage (decimal form) for that state and save them to the given arrays. It will then print a menu for the user to choose the state that the business is in and set the variables to hold the values. getCustomerName() – This method will prompt the user for the name of the person using the program calcSalesTax() – This method will be sent a subtotal and calculate the sales tax outputReceipt() – This method will output a generic receipt as follows: Subtotal $37.50 Sales Tax $2.44 Total $39.94 outputMenu() - This method will receive the number of items and output a generic menu as follows: Item 1 Item 2 Item 3 Item 4 must have the following variables: stateNames - array saleTax – array saleTaxAmount theStateName subtotal total firstName…arrow_forwardCode with comments and output screenshot is must for an Upvote. Thank you! Using Java: Create a random 2000-digit number and store it in a file. Read the number from the file and find the smallest number within our larger number that contains at least every digit. For instance,149485420251367 contains every digit, but 94556780231 is a smaller number that contains every digit.arrow_forwardWrite a Java application with (comments) for Car Care Shop that shows a user a list of available services: oil change, tire rotation, battery check, or brake inspection. Allow the user to enter a string that corresponds to one of the options, and display the option and its price as R250, R220, R150, or R50, accordingly. Display an error message if the user enters an invalid item.arrow_forward
- Create a class called StudentBirthYear. It should only have two members, both of them arrays. One of type string called Names. The second of type int called BirthYears. Now in your main class create a StudentBirthYear object. Make sure both arrays are of the size 13. Add thirteen different names and thirteen different birth years. Then display each name with its birth year using only 1 for loop. Only use a for loop, no other kind of loop.arrow_forwardWrite a code using Console.WriteLine for the image.arrow_forwardWrite in Java using JOptionPane.showInputDialog If you have downloaded this book’s source code (the companion Web site is available at www.pearsonhighered.com/gaddis), you will find a file named WorldSeriesWinners.txt. Also is file is attached to the dropbox as well as in the downloads for this chapter. This file contains a chronological list of the winning teams in the World Series from 1903 through 2009. (The first line in the file is the name of the team that won in 1902, and the last line is the name of the team that won in 2009. Note that the World Series was not played in 1904 or 1994, so those years are skipped in the file.) Write a program that lets the user enter the name of a team, and then displays the number of times that team has won the World Series in the time period from 1903 through 2009. You should list the years cronoligically. Possible Look to Programarrow_forward
- In Javaarrow_forwardFor Java Write an application that prompts the user for a password that contains at least two uppercase letters, at least three lowercase letters, and at least one digit. Continuously reprompt the user until a valid password is entered. Display Valid password if the password is valid; if not, display the appropriate reason(s) the password is not valid as follows: The password did not have enough of the following: uppercase letters lowercase letters digitsarrow_forwardWrite a java application for Limpopo’s Car Care Shop that shows a user a list of available services: oil change, tire rotation, battery check, or brake inspection. Allow the user to enter a string that corresponds to one of the options, and display the option and its price as R250, R220, R150, or R50, accordingly. Display an error message if the user enters an invalid item. NB:ALSO SHOW OUTPUTarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY