Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
11th Edition
ISBN: 9780134743356
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 3, Problem 4.1E
Explanation of Solution
Using Classes without importing them:
- The “String” class provides a number of methods that examines for a string inside of a string.
- The Scanner class helps to create an object for Scanner method for reading the input strings from console and inputs are delimited by whitespace characters.
- The syntax to create an object for Scanner class using System.in is given below:
Scanner objName = new Scanner(System...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Instructions
Assuming you are registered in a class with several activities/categories (quizzes, labs, homework, attendance, etc.), you would like to keep track of your grades throughout the quarter. For each category, you need to add your grade, e.g., for the labs you got 100 in lab 1, 95 in lab 2, etc.
How are we going to store our grades for each category?
Remember that in our main program, we keep the information for various grade categories. This information is stored as a list of lists, which can, for example, look like this:
[["Lab", 35], ["Quiz", 35]]
Each list that is contained in the main “database” (a list of lists) contains information about a category and its corresponding grade percentage.
If for the labs, you got 100 in lab 1, 95 in lab 2, we can store this information for the “Lab” category as an additional list:
["Lab", 35, [100, 95]]
This means that our database would then look like this (note the nesting of the grades):
[["Lab", 35, [100, 95]], ["Quiz", 35]]
In order…
Discussion: Advantages of Methods
This discussion has 2 parts: What are the advantages of using methods? Name at least 2 advantages and how you benefit from each. List at least 1 scenario you would want to use methods instead of having the code in the main class.
Objectives:
• More practice designing and writing classes
• Use Java loop structures
• More practice rounding numbers
• Write boolean expression(s)
Background
Companies raise money (to be able to do more) by selling shares of stock. You can buy whole shares of stocks. Stocks prices vary over time. If you buy some shares and then sell them when they are higher, you make money :). For
stocks, the cost basis is the amount that you spent purchasing the shares. It is calculated as the sum of the number of shares purchased multiplied by the purchase price (at the time of the purchase). After selling shares, the profit is
the number of shares sold multiplied the current price, then minus the cost basis.
Look at the following examples for illustrations of calculating the profit.
Example 1 - Acme Corporation
Number of Shares Price per Share
5.50
5.15
100
100
100
6.16
The cost basis is calculated as follows: (100 * 5.50) + (100 * 5.15) + (100 * 6.16) = $1,681.00.
Assume that when you go to sell…
Chapter 3 Solutions
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Ch. 3 - Fill in the blanks in each of the following: Each...Ch. 3 - Fill in the blanks in each of the following:...Ch. 3 - Fill in the blanks in each of the following:...Ch. 3 - Fill in the blanks in each of the following: Each...Ch. 3 - Prob. 1.5SRECh. 3 - Fill in the blanks in each of the following: Java...Ch. 3 - Prob. 1.7SRECh. 3 - Prob. 1.8SRECh. 3 - Prob. 1.9SRECh. 3 - Prob. 1.10SRE
Ch. 3 - Prob. 1.11SRECh. 3 - Prob. 1.12SRECh. 3 - Fill in the blanks in each of the following: A(n)...Ch. 3 - Prob. 1.14SRECh. 3 - Prob. 1.15SRECh. 3 - Prob. 1.16SRECh. 3 - Fill in the blanks in each of the following: Types...Ch. 3 - Prob. 2.1SRECh. 3 - Prob. 2.2SRECh. 3 - State whether each of the following is true or...Ch. 3 - Prob. 2.4SRECh. 3 - Prob. 2.5SRECh. 3 - Prob. 2.6SRECh. 3 - State whether each of the following is true or...Ch. 3 - State whether each of the following is true or...Ch. 3 - Prob. 2.9SRECh. 3 - Prob. 2.10SRECh. 3 - State whether each of the following is true or...Ch. 3 - Prob. 3.1SRECh. 3 - Prob. 4.1SRECh. 3 - (Keyword new) Whats the purpose of keyword new?...Ch. 3 - Prob. 2.1ECh. 3 - (Instance Variables) Explain the purpose of an...Ch. 3 - Prob. 4.1ECh. 3 - (Using a Class without Importing It) Explain how a...Ch. 3 - (set and get Methods) Explain why a class might...Ch. 3 - Prob. 7.1ECh. 3 - (Invoice Class) Create a class called Invoice that...Ch. 3 - (Employee Class) Create a class called Employee...Ch. 3 - Prob. 10.1ECh. 3 - (Target-Heart-Rate Calculator) While exercising,...Ch. 3 - (Computerization of Health Records) A health-care...
Knowledge Booster
Similar questions
- Note:- Please type and execute this java program and also please upload the output of the code with it.arrow_forwardBank Balance – (In java) The First National Bank of Parkville recently opened up a new “So You Want to Be a Millionaire” savings account. The new account works as follows: The bank doubles the customer’s balance every year until the customer’s balance reaches one million.The customer isn’t allowed to touch the money (no deposits or withdrawals) until the customer’s balance reaches one million. If the customer dies before becoming a millionaire, the bank keeps the customer’s balance.Note:Customers close to $1,000,000 tend to get “accidentally” run over in the bank’s parking lot.Write a program that prompts the user for a starting balance and then prints the number of years it takes to reach $100,000 and also the number of years it takes to reach $1,000,000.arrow_forwardObject-Oriented Programming (Using Java Language) - 1arrow_forward
- Question Completion Status: QuestioI A. (1) Write a Java program named ConeVolume. (1 mark) (2) The program should read and store Cone's radius and height. The radius and height values should be typed in by the user in response to a prompt message. (2 mark) (3) Then it should compute and display Cone's volume. (3 marks) (4) You must type your name and student number above the class declaration using a comment. (1 mark) The cone's volume is given by the following equation: V = nr²h Where, r is the radius and h is the height. Attach File Browse My Computer Click Save and Submit to save and submit. Click Save All Answers to save all answers. Save All Answarrow_forwardc++ my code is attached, along with an image of what problem i am experiencing. I know the code works fine, but when running it in the window in this particular form, my results show zero per the image i have attached and highlighted. *please note, i enter the input as follows. 5 space 10, enter then 2, enter then 1 i have also tried 5, enter, 10, enter then 2, enter then 1 and nothing works. Amanda and Tyler opened a business that specializes in shipping liquids, such as milk, juice, and water, in cylindrical containers. The shipping charges depend on the amount of the liquid in the container. (For simplicity, you may assume that the container is filled to the top.) They also provide the option to paint the outside of the container for a reasonable amount. Write program that does the following: Prompts the user to input the dimensions (in feet) of the container (radius of the base and the height). Prompts the user to input the shipping cost per liter. Prompts the user to input…arrow_forwardTrue or false: Some built-in methods (print or input) can be overridden to be/do something else. (python)arrow_forward
- Java Programming Question [Problem Description]Create an Employee class with name, age, sarary and bonus. Define a constructor to initialize these attributes of the class.Define method to output the employee's name, age, and total income (the sum of salary and bonus). [Input form]Please input the employee's name:Please input the employee's age:Please input the employee's salary:Please input the employee's bonus: [Output form]Employee's name:Employee's age:Employee's income:[Input Sample ①]Please input the employee's name: TomPlease input the employee's age: 20Please input the employee's salary: 3000.0Please input the employee's bonus: 4000.0 [Output Sample ①]Employee's name: TomEmployee's age: 20Employee's income: 7000.0 [Sample explanation]The format of the input and output must exactly match the specified format, otherwise no score.arrow_forwardRolling Dice Simulator [Java Assignment]Objective: Create a Java program that rolls two dice and displays the results. The program should have two Java classes: one for a single die and another for a pair of dice. Assignment Details: User Input: Ask the user to specify the number of sides they want on each die. Ensure that the user's input is within a reasonable range. Dice Rolling: Simulate rolling the dice using Math.random() based on the user's chosen number of sides. Display the sum of the values rolled, e.g., "5 + 3 = 8." Special Combinations: If the dice roll results in combinations of 2, 7, or 12, print special messages: "1 + 1 = 2 snake eyes!" "3 + 4 = 7 craps!" "6 + 6 = 12 box cars!" Main Method: In the main method, create a pair of dice, roll them, and display the results. Allow the user to decide whether to continue rolling the dice or exit the program. Additional Features: You are welcome to add more features or enhancements to the program if desired.…arrow_forwardTo utilize the Scanner class in JAVA, what statement you must put in your source code?arrow_forward
- Data structure & Algorithum Java program magine a pile of books on your desk. Each book is so large and heavy that you can remove only the top one from the pile. You cannot remove a book from under another one. Likewise, you cannot add a book beneath another one. You can add another book to the pile only by placing it on top of the pile. If you represent booka by thier titles alone, the "PileInterface.java" interface attached can be used to track the books in the pile on your desk. Define a class "PilesOfBooks.java" that implements this interface using a chain of linked nodes. Then, write a program that demonstrates your implementation (i.e. PilesOfBookDemo.java) to prompt the user for various book titles and thoroughly tests all the methods in the PileOfBooks.java.class. public interface PileInterface<T>{/** Adds a new book to the top of this pile.@param newBook An object to be added to the pile. */public void add(T newBook);/** Removes and returns this pile's top…arrow_forwardjava An instance variable declared as static is "common" to all objects of the class. Choose one of the options:TrueFalsearrow_forwardmust attach output screenshotarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTNew Perspectives on HTML5, CSS3, and JavaScriptComputer ScienceISBN:9781305503922Author:Patrick M. CareyPublisher:Cengage Learning
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Cengage Learning
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning