Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 6, Problem 12E
Program Plan Intro
Generating name
Program plan:
- • Import necessary header files
- • Define the class “Android”.
- ○ Declare the necessary static variables.
- ○ Define the function “changeTag()”.
- ■ Initialize the variable “tryNext”.
- ■ The “while” loop executes until the condition becomes true.
- • Increment the variable “tryNext” by “1”.
- ■ Assign the value into the variable “tag”.
- ○ Define the function “isPrime()”.
- ■ Initialize the variable “hasFactor”.
- ■ Use “for” loop to iterate the “factor”.
- • The “if” statement check the condition.
- ○ If the condition becomes true, assign “true” into the variable “hasFactor”.
- • The “if” statement check the condition.
- ■ Return the value.
- ○ Define the empty constructor.
- ■ Initialize the variables.
- ■ Declare the method “changeTag()”.
- ○ Define the function “getName()”.
- ■ Return the value of the variable “name”.
- ○ Define the “main()” function.
- ■ Use “for” loop to iterate the “count”.
- ■ Create object for the class “Android”.
- ■ Print the necessary statements.
- ■ Call the necessary methods to print the result on the screen.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a program that create a class ‘simpleobject‘ , and using constructor print the following message (" MidTerm Exam ") ?
2. Create a SavingsAccount class that behaves just like a BankAccount, but also has an interest rate and a method that increases the balance by the appropriate amount of interest. Supply a test program or driver that tests these classes and methods.
A. Create a BankAccount class.
We want to be able to create a new bank account, make deposits and withdrawals, and check the balance. Each bank account created should receive a unique account id, numbered sequentially 1001, 1002, 1003, and so on. We should be able to change the name on the account. We should also be able to retrieve the account id and the name on the account.
Provide a constructor that takes a name for the account as a parameter. Remember that a constructor has the same name as the class. The constructor should initialize all of the instance variables.
What does the class need to remember? Those are the instance variables. There should be three.
Provide the following methods:
public double getID() gets the account id of this BankAccount
public double getBalance() gets the balance of this BankAccount
public String getName() gets the name of this BankAccount
public void setName(String newName) sets a new name for this BankAccount
public void deposit(double…
Chapter 6 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Ch. 6.1 - If a class is named Student, what name can you use...Ch. 6.1 - When defining a constructor, what do you specify...Ch. 6.1 - What is a default constructor?Ch. 6.1 - Does every class in Java automatically have a...Ch. 6.1 - In the program PetDemo shown in Listing 6 2, you...Ch. 6.2 - Prob. 6STQCh. 6.2 - Can a class contain both instance variables and...Ch. 6.2 - Can you reference a static variable by name within...Ch. 6.2 - Can you reference an instance variable by name...Ch. 6.2 - Can you reference a static variable by name within...
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 - The previous section showed you how to change 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 - Create a JavaFX application that displays a button...
Knowledge Booster
Similar questions
- 6..arrow_forwardWrite a program to print the names of books by creating a book class. If no name is passed while creating an object of book class, then the name should be "Unknown", otherwise the name should be equal to the String value passed while creating object of book class.arrow_forwardwrite a program to print the names of the student by creating a student class .if no name is passed while creating an object of the student class,then the name should be "unknown" ,otherwise the name should be equal to the string valaue passed while creating the object of the student class.arrow_forward
- Use java and use proper code indentation.arrow_forwardCreate a Java class called Student with attributes name, age, and grade. Implement a parameterized constructor to initialize these attributes. Then, create an array of Student objects, populate it, and print the details of all students.arrow_forwardplease may you : create a Python class named Animal with properties for name, age, and a method called speak. also include an initializer method for the class and demonstrate how to create an instance of this class. and extend the Animal class by adding a decorator for one of its properties (e.g., age). please include both a getter and a setter for the property, and demonstrate error handling.arrow_forward
- 16. Create a class SubstitutionCipher that implements the interface MessageEncoder, as described in the previous exercise. The constructor should have one parameter called shift. Define the method encode so that each letter is shifted by the value in shift. For example, if shift is 3, a will be replaced by d, b will be replaced by e, c will be replaced by f, and so on. (Hint: You may wish to define a private method that shifts a single character.)arrow_forwardYou have been hired by a local grocery store in order to update and expand the CashRegister Class that was discussedin class. Yourtaskis to update the class by adding functionality to it such that it will compute the total sales by all customer in a whole day, reset all variables after the store closes every day, and showthe customer count per day, every day In order to accomplish your taskyou needto do two smaller tasks: 1. Update the existing methods presented during lecture time, as needed, to accomplish the task described, above. 2 In order to help you further, you need to wite 4 new methods, as follows: • addCustomerCount () – increments the customer count at the end of every customer sale end • getCustomerCount () - gets/retums the customer count; to be invoked at the end of every day getSalesTotal () - gets/retums the total customer sales for all customers; to be invoked at the end of every day • resetSales () - clear daily instance variables that need to be cleared at the end…arrow_forwardRisking telling the obvious, you will need to make all necessary modifications to the files, including adapting the documentation and removing any parts that are irrelevant. I suggest that you pattern after the way the suggested book authors document a template class (such as for bag4) when adapting the documentation.arrow_forward
- Write in python and please include docstring. Write a class named Employee that has private data members for an employee's name, ID_number, salary, and email_address. It should have an init method that takes four values and uses them to initialize the data members. It should have get methods named get_name, get_ID_number, get_salary, and get_email_address. Write a separate function (not part of the Employee class) named make_employee_dict that takes as parameters a list of names, a list of ID numbers, a list of salaries and a list of email addresses (which are all the same length). The function should take the first value of each list and use them to create an Employee object. It should do the same with the second value of each list, etc. to the end of the lists. As it creates these objects, it should add them to a dictionary, where the key is the ID number and the value for that key is the whole Employee object. The function should return the resulting dictionary. For example, it…arrow_forwardCreate a class Car with some properties and inherit those in another class CarPrice. Use differnt OOP concepts such as overloading, overriging ,super, this, etc. in the program wth proper input and output.arrow_forwardHow about if the code only accepts "history", "language" and "PE", for the "class"? And, if they input a class that is not among the three, the string will return to "Error". How can we code it?arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- 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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education