Starting Out with Java: From Control Structures through Objects (6th Edition)
6th Edition
ISBN: 9780133957051
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 2.4, Problem 2.14CP
Program Plan Intro
Data types to be used for a variable:
A memory space, which contains a data value, is called as variable.
- The variable must be declared before it is used in the program, because Java
programming language statically typed. - The declaration of variable tells the compiler about the type of data to be stored in it along with the variable name.
- The datatype is a set of values and each datatype have its own purpose.
- Based on the input value, datatypes are assigned to the variable.
- Datatype can be int, short, byte, double, float, long, Boolean, and String.
- “int”, “short” and “byte” datatype is used for values containing integers and natural numbers.
- “double” and “float” datatype are used for values with decimal numbers.
- “String” datatype is used for values containing alphanumeric characters.
- “Boolean” datatype is used for values containing 0 or 1 and True or False.
Explanation of Solution
b. Primitive data type used to store whole number in the region of -40,000 to +40,000:
The Primitive data type, which is used to store whole number in the r...
Explanation of Solution
c. The literal that uses more memory:
“22.1” and “22.1F” are the two given literals.
The literal, which occupies more memory is “22.1”, because, “22.1” is a double variable and “22...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Hi pleas help me
i need the solv by uesing online java compiler
Create the principal program, which will complete the following tasks :a. Create a new Student object by reading the required details and by applying at least one type of data validation of your choice on the input.b. Read and save the list of module names and the list of module marks awarded to the student in the two assignments. c. Display the transcript of the student by calling the adequate method.d. Repeating the previous tasks until the user decides to exit.
Write C++ Program to check whether the Given String is a Palindrome.
To resolve this problem, you should write 3 void functions: inputStrings, testPalindrome and
displayNumbers.
• inputStrings : the aim of this function to read 7 strings from the user and insert them in
array of 7 elements.
testPalindrome: to check whether the given strings in the array are palindrome.
• displayPalindrome: print the palindrome strings.
Using C++; Define a struct, fruitType, to store the following data about a fruit: Fruit name (string), color (string), fat (int), sugar (int), and carbohydrate (int). Write a program that declares a variable of type fruitType, prompts the user to input data about a fruit, and outputs the fruit data.
Chapter 2 Solutions
Starting Out with Java: From Control Structures through Objects (6th Edition)
Ch. 2.1 - The following program will not compile because the...Ch. 2.1 - When the program in Question 2.1 is saved to a...Ch. 2.1 - Complete the following program skeleton so it...Ch. 2.1 - On paper, write a program that will display your...Ch. 2.1 - Prob. 2.5CPCh. 2.1 - Every Java application program must have...Ch. 2.2 - The following program will not compile because the...Ch. 2.2 - Study the following program and show what it will...Ch. 2.2 - On paper, write a program that will display your...Ch. 2.3 - Examine the following program. // This program...
Ch. 2.3 - What will the following program display on the...Ch. 2.4 - Which of the following are illegal variable names...Ch. 2.4 - Prob. 2.13CPCh. 2.4 - Prob. 2.14CPCh. 2.4 - Prob. 2.15CPCh. 2.4 - A program declares a float variable named number,...Ch. 2.4 - Prob. 2.17CPCh. 2.4 - Prob. 2.18CPCh. 2.4 - Prob. 2.19CPCh. 2.4 - Prob. 2.20CPCh. 2.4 - What is wrong with the following statement? char...Ch. 2.5 - Prob. 2.22CPCh. 2.5 - Prob. 2.23CPCh. 2.6 - Write statements using combined assignment...Ch. 2.7 - The following declaration appears in a program:...Ch. 2.7 - The variable a is a float and the variable b is a...Ch. 2.9 - Write a statement that declares a String variable...Ch. 2.9 - Assume that stringLength is an int variable. Write...Ch. 2.9 - Prob. 2.29CPCh. 2.9 - Prob. 2.30CPCh. 2.9 - Prob. 2.31CPCh. 2.11 - Prob. 2.32CPCh. 2.11 - How are documentation comments different from...Ch. 2.14 - Prob. 2.34CPCh. 2.14 - Write code that will display each of the dialog...Ch. 2.14 - Write code that displays an input dialog asking...Ch. 2.14 - Prob. 2.37CPCh. 2 - Every complete statement ends with a __________....Ch. 2 - The following data 72 'A' Hello World 2.8712 are...Ch. 2 - A group of statements, such as the contents of a...Ch. 2 - Which of the following are not valid assignment...Ch. 2 - Which of the following are nor valid println...Ch. 2 - The negation operator is __________. a. unary b....Ch. 2 - This key word is used to declare a named constant....Ch. 2 - These characters mark the beginning of a...Ch. 2 - These characters mark the beginning of a...Ch. 2 - These characters mark the beginning of a...Ch. 2 - Which Scanner class method would you use to read a...Ch. 2 - Which Scanner class method would you use to read a...Ch. 2 - You can use this class to display dialog boxes. a....Ch. 2 - Prob. 14MCCh. 2 - Prob. 15MCCh. 2 - True or False: A left brace in a Java program is...Ch. 2 - True or False: A variable must be declared before...Ch. 2 - True or False: Variable names may begin with a...Ch. 2 - True or False: You cannot change the value of a...Ch. 2 - True or False: Comments that begin with / / can be...Ch. 2 - True or False: If one of an operators operands is...Ch. 2 - What will the following code segments print on the...Ch. 2 - int x = 0, y=2; x = y 4; System.out.println(x +...Ch. 2 - System.out.print(I am the incredible);...Ch. 2 - System.out.print(Be careful\n);...Ch. 2 - int a, x = 23; a = x % 2; System.out.println(x +...Ch. 2 - Find the Error There are a number of syntax errors...Ch. 2 - Show how the double variables temp, weight, and...Ch. 2 - Prob. 2AWCh. 2 - Write assignment statements that perform the...Ch. 2 - Assume the variables result, w, x, y, and z are...Ch. 2 - Prob. 5AWCh. 2 - Modify the following program so it prints two...Ch. 2 - What will the following code output? int apples =...Ch. 2 - What will the following code output? double d =...Ch. 2 - What will the following code output? String...Ch. 2 - What will the following code output? String...Ch. 2 - Convert the following pseudocode to Java code. Be...Ch. 2 - Prob. 12AWCh. 2 - Write the code to set up all the necessary objects...Ch. 2 - Prob. 14AWCh. 2 - A program has a float variable named total and a...Ch. 2 - Is the following comment a single-line style...Ch. 2 - Is the following comment a single-line style...Ch. 2 - Describe what the phrase self-documenting program...Ch. 2 - Prob. 4SACh. 2 - Prob. 5SACh. 2 - What does a variable declaration tell the Java...Ch. 2 - Prob. 7SACh. 2 - What things must be considered when deciding on a...Ch. 2 - Briefly describe the difference between variable...Ch. 2 - What is the difference between comments that start...Ch. 2 - Briefly describe what programming style means. Why...Ch. 2 - Assume that a program uses the named constant PI...Ch. 2 - Assume the file Sales Average, java is a Java...Ch. 2 - Prob. 14SACh. 2 - Name, Age, and Annual Income Write a program that...Ch. 2 - Name and Initials Write a program that has the...Ch. 2 - Personal Information Write a program that displays...Ch. 2 - Star Pattern Write a program that displays the...Ch. 2 - Sales Prediction The East Coast sales division of...Ch. 2 - Land Calculation One acre of land is equivalent to...Ch. 2 - Sales Tax Write a program that will ask the user...Ch. 2 - Cookie Calories A bag of cookies holds 40 cookies....Ch. 2 - Miles-per-Gallon A cars miles-per-gallon (MPG) can...Ch. 2 - Test Average Write a program that asks the user to...Ch. 2 - Circuit Board Profit An electronics company sells...Ch. 2 - Prob. 12PCCh. 2 - Restaurant Bill Write a program that computes the...Ch. 2 - Male and Female Percentages Write a program that...Ch. 2 - Stock Commission Kathryn bought 600 shares of...Ch. 2 - Energy Drink Consumption A soft drink company...Ch. 2 - Ingredient Adjuster A cookie recipe calls for the...Ch. 2 - Word Game Write a program that plays a word game...Ch. 2 - Stock Transaction Program Last month Joe purchased...
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 Declare statements for the following variables or constants, making use of the rules of PL/I regarding attributes. Also explain the reasons why you selected the particular attributes. The variables are given as follows: a) A variable named PERCENT which takes values from 0•00 to 100•00. PERCENT is an array of 8 elements. b) A variable named AMOUNT which represents dollars and cents, from 0•00 to 1 million dollars. c) A variable named NUMBER which represents Avogadro's number = 6•022x1023 d) A variable named TOTAL which represents integer numbers from 1 to 4000, to be stored in a binary form.arrow_forwardCreate a program in C language that calculates the month's day from a given year and year's day. Use pointers for the month and month's day variables. Don't forget to add proper errors handling in your program. Example or errors - Invalid Input- Invalid year- Invalid year day Example of input # ./month_day <year> <yearday> # Example for Feb 2nd, 2019:\$ ./month-day 2019 33Feb 02, 2019 I have this class - month-day.c - #include <stdio.h> /* month_day function's prototype*/void month_day(int year, int yearday, int *pmonth, int *pday); int main() {return 0;} Note: I don't need the calendar, please read the instructions well!!arrow_forwardSolution is needed in C# Language please! You are tasked with writing a program to process students’ end of semester marks. For each student you must enter into your program the student’s id number (an integer), followed by their mark (an integer out of 100) in 4 courses. A student number of 0 indicates the end of the data. A student moves on to the next semester if the average of their 4 courses is at least 60 (greater than or equal to 60). Write a program to read the data and print, for each student: The student number, the marks obtained in each course, final mark of the student (average of all the marks), their final grade (A,B,C,D or F) and whether or not they move on to the next semester. In addition, after all data entry is completed, print The number of students who move on to the next semester and the number who do not. The student with the highest final mark (ignore the possibility of a tie). Grades are calculated as follows: A = 70 and over, B = 60 (inclusive) -70,…arrow_forward
- JAVA CODE PLEASE 2. Functions With Parameters and Return Values Practice ll by CodeChum Admin Create a function named compare that receives three integer arguments and compares them. Return the integer with the greatest value. In the main function, create a program that asks for three integer user inputs and assign it to an integer variable. Call the compare function by passing the three integer variables in the actual parameters and assign the returned value to a variable. On the next line, print the value assigned to the variable. Input 1. One line containing the first integer 2. One line containing the second integer 3. One line containing the third integer Output Enter·number·1:·1 Enter·number·2:·2 Enter·number·3:·3 Greatest:·3arrow_forwardCan you write a new code in C language with the values I sent you, just like this output? There are two files named group1.txt and group2.txt that contain course information and grades of each student for each class. I will calculate each course average for each group and show in simple bar graph. Use "*" and "#"characters for group1 and group2, respectively. I will see the number -999 at the end of each line in the input files. This value is used for line termination and you can use it to verify that you have arrived at the end of the line. The averages of each group should also be calculated and printed at the end of the file. Group 1: CSC 80 100 70 80 72 90 89 100 83 70 90 73 85 90 -999 ENG 80 90 80 94 90 74 78 63 83 80 90 -999 HIS 90 70 80 70 90 50 89 83 90 68 90 60 80 -999 MTH 74 80 75 89 90 73 90 82 74 90 84 100 90 79 -999 PHY 100 83 93 80 63 78 88 89 75 -999 Group 2: CSC 90 75 90 75 80 89 100 60 80 70 80 -999 ENG 80 80 70 68 70 78 80 90 90 76 -999 HIS 100 80 80 70 90 76 88 90…arrow_forwardWrite a complete C++ program to help the manufacturer determine the greatest profit obtain from making tables and chairs with a given number of M type A and N type B wood blocks. • The program should prompt the user to input M and N. • Then tabulates all the combinations of tables and chairs possibly made, and calculates the profit obtain using array. • The program should also identify the greatest profit and make a concluding remark. • The program should be written in modular form with the main() function calling other functions. If arrays are involved in the function, the arrays should be passed into the function as parameters. • Lastly, display the output to an external .txt file.arrow_forward
- 20. Code a JavaScript function that simulates the Math.pow() method, or the exponent (**) operator, where it accepts two floating point arguments (base and exponent) and returns a valid calculated power value. You are not permitted to use any JavaScript Math object methods or the exponent operator and your function does not need to address negative base or exponent values.arrow_forward1. Which is not a rule for read cv() as related to numbers: a. If any value of a column is non-numeric, the column's values are represented as Python types as opposed to NumPy types b. If a column has integer values and some missing values, pandas will use the Python int type or None for the values in the column c. if any value in a column of numbers is missing, even is all non-missing values are integers, the column is stored as a NumPy float type d. If all values in a column are numeric and any value has decimal places, the column is represented as a NumPy float 2. For a pandas DataFrame df, which expression can be used to find rows with missing values for the column named id? df[df.id.isna()] df.id.isna df.missing('id') df.id. Falsearrow_forwardWrite a C++ program that stores data of students in a struct. It should store student's ID, QuizMarks (5 Quizzes), and QuizAverage. Write an Input () function that takes Students' ID and QuizMarks from the user on the command line. Write another function Average () that calculates QuizAverage from QuizMarks. The value of QuizMarks should be passed by reference using pointers. Write a Display function that displays the data of the student specified using his ID.arrow_forward
- CS 220: Programming in C and Unix Lab#03 2. Write a function that has the following prototype: int Equalcols (int *A, int rows, int cols); The function should return the value 1 if the sums of the values in each column are the same and 0 otherwise. For example: For the matrix: 1 2 0 3 2 3 2 1 3 1 4 2 The value 1 is returned since the sums of the values in each column are the same (each column sum is equal to 6), while for the matrix: 2 4 3 2 2 3 4 1 1 35 2 The value 0 is returned since the sums of the values in each column are not equal. Write a function that takes a pointer to a two dimensional array, number of rows and number of columns as arguments. The function should read the elements of the matrix from the user and store them in the two dimensional array using pointer offset notation. Write a main program that makes use of the functions above to: Read a matrix from the user, where the number of rows and number of columns should be input from the user. The maximum dimensions of…arrow_forwardCan someone help me with this c++ code? Instructions: This assignment uses pointers to perform something done often in computer applications: the parsing of text to find “words” (i.e., strings delineated by some delimiter). Assume you are working in the marketing department of a company that sells computers and accessories. Your team has been tasked with determining how customers perceive your products based on customer surveys. The questions in the surveys are open-ended. That is, customers write product reviews as paragraphs about their perceptions of your products. Your job is to prepare the customer responses to facilitate a sentiment analysis. Program executes without crashing Appropriate Internal Documentation main() Declares variables appropriately (uses pointers where needed for tokenization and creates a Review object for storage of Words) Prompts user to enter a filename with appropriate error checking Contains a loop to tokenize…arrow_forwardPrograming C Just with #include Matrix Addition and Subtraction (Associatively) Write a program that performs matrices addition and subtraction. As shown in the example below, you have to ask the user for the number of rows and number of columns that both matrices should have (they both have to be the same size, that is why you only ask once). You will then ask the user for the values of each matrix. Then, you will print the values that the user inputted, the added values of both matrices, and the subtracted values (matrix 2 should be subtracted from matrix 1). In this challenge Guidelines/steps: • The number of rows and the number of columns should be global variables. • Once you get these two from the user, you should declare your two matrices in main. • Then, from main, you will call function aaa twice; first, you will send matrix 1 and populate it with values inputted by the user. You will call the function a second time, send matrix 2 and populate it. In other words, function aaa…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