Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
3rd Edition
ISBN: 9780134038179
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 2, Problem 14MC
Program Description Answer
Java has the ability to convert lower ranked value to higher ranked type, this process is called as “widening conversion”.
Hence, the correct answer is option “C”.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
// Add to this partially built code.
// fill in code where there is a TODO
#include<iostream>
using namespace std;
int main()
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint); // show decimals even if not needed
cout.precision(2); // two places to the right of the decimal
// TODO: enter the missing types below
int time;
float ticketPrice;
destination; //'C'=Chicago, 'P'=Portland, 'M'=Miami
typeOfDay; //'D'=weekDay 'E'=weekEnd
cout << "Welcome to Airlines!" << endl;
cout << "What is your destination? ([C]hicago, [M]iami, [P]ortland) ";
cin >> destination;
cout << "What time will you travel? (Enter time between 0-2359) ";
cin >> time;
// TODO: set isDayTime to true if time 5AM or later, but before 7PM
cout << "What type of day are you traveling? (week[E]nd or week[D]ay) ";
cin >> typeOfDay;
// TODO: set isWeekend to true if typeOfDay is 'E', otherwise false
// Depending upon the destination, and whether…
This code is not working. I'm getting errors.Can you check code again.
#include <cctype>#include <cstring>#include <iostream>
using namespace std;
class Song {private: char* title; char* author; char* genre; float time;
public: Song(); Song(char* t, char* a, char* g, float ti); ~Song(); void Set(char* t, char* a, char* g, float ti); void Display(); bool operator<(Song& a); bool operator<=(Song& a); bool operator>(Song& a); bool operator>=(Song& a); bool operator==(Song& a); bool operator!=(Song& a);};
Song::Song() { title = NULL; author = NULL; genre = NULL; time = 0;}
Song::Song(char* t, char* a, char* g, float ti) { title = new char[strlen(t) + 1]; strcpy(title, t); author = new char[strlen(a) + 1]; strcpy(author, a); genre = new char[strlen(g) + 1]; strcpy(genre, g); time = ti;}
Song::~Song() { delete[] title; delete[] author; delete[] genre;}…
I get an error when I submit my program.
My code is as follows
#include<iostream>
using namespace std;
int main()
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint); // show decimals even if not needed
cout.precision(2); // two places to the right of the decimal
// TODO: enter the missing types below
int time;
float ticketPrice;
char destination; //'C'=Chicago, 'P'=Portland, 'M'=Miami
char typeOfDay; //'D'=weekDay 'E'=weekEnd
bool isDayTime = false,isWeekend;
cout << "Welcome to Fordham Airlines!" << endl;
cout << "What is your destination? ([C]hicago, [M]iami, [P]ortland) ";
cin >> destination;
cout << "What time will you travel? (Enter time between 0-2359) ";
cin >> time;
// TODO: set isDayTime to true if time 5AM or later, but before 7PM
if(time>500&&time<1900){
isDayTime = true;
}
cout << "What type of day are you traveling? (week[E]nd or week[D]ay) ";
cin >> typeOfDay;
// TODO: set isWeekend to true if typeOfDay…
Chapter 2 Solutions
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Ch. 2.1 - Prob. 2.1CPCh. 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 - Prob. 6SACh. 2 - Prob. 7SACh. 2 - Prob. 8SACh. 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...Ch. 2 - Planting Grapevines A vineyard owner is planting...Ch. 2 - Compound Interest When a bank account pays...
Knowledge Booster
Similar questions
- Choose the best data type for each of the following, so that no memory storage is wasted. Give an example of a typical value that would be held by the variable, and explain why you chose the type you did. the number of years of school you have completed your final grade in this class the population of China the number of passengers on an airline flight one players score in a Scrabble game the number of Electoral College votes received by a U.S. presidential candidate the number of days with below freezing temperatures in a winter in Miami, Florida one teams score in a Major League Baseball gamearrow_forwardGiven a positive integer nDigits received from the user, list all binary numbers you can represent withthe given digits, along with their decimal representation. Format your output as it follows:binary_number -> decimal_numberMake sure the value is nDigits in the range [1, 10].Remember to comment the code such that it is easy for other developers to understand it. (in c++) example: Input: nDigits = 4Output:0000 -> 00001 -> 10010 -> 20011 -> 30100 -> 40101 -> 50110 -> 60111 -> 71000 -> 81001 -> 91010 -> 101011 -> 111100 -> 121101 -> 131110 -> 141111 -> 15 1 <= nDigit <= 10write all your code in the main function, do not divided into other functions• do not use built-in functions • do not use arrays or any advanced data structurearrow_forward8.1: FrequencyDesign and implement an application that reads an arbitrary number of integers that are in the range 0 to 50 inclusive and counts how many occurrences of each are entered. After all input has been processed, print all of the values (with the number of occurrences) that were entered one or more times. The output should be one frequency count per line with the following format:3 occurrences of 27 occurrences of 5 SPECIFICATION OF NAMES: Please name your application class Frequency Complete program using Javaarrow_forward
- IN JAVA CODE: Create an application that allows the user to do the following: Input a series of characters (sentence, phrase, paragraph, etc.) as the basis for the creation of the Huffman code and output a table of values that will show the following: (Character, Huffman code, number of bits, and percentage (%) of storage). Please note the following when creating the code for the program: There should be an error message if the text cannot be converted (e.g. using character/s in the input text that is/are not part of the table Huffman codes).arrow_forwardwrite an application that reads English-Language phrase and encodes it into morse code. also write an application that reads a phrase in morse code and converts it into the English-Language equivalent . Use one blank between each Morse-code letter and three blanks between each Morse-coded word.arrow_forwardGiven 4 numbers (passed in as parameters) write a function that returns the average of these numbers please write this with a function in java form example function.somthing() and make an html file of the version as well please somthing like this function Numbers() { for (let i = 1; i <= 10; i++) { console.log(i);} } i just need somethig simple like function() var a = (make the user put a random nuber in) var b = (make the user put a random nuber in) var c = (make the user put a random nuber in) var d = (make the user put a random nuber in) return a+b+c+d/4 WITH OUT PYTHON PLZ WITHOUT THIS CODE below import java.util.Scanner; public class AverageClass { public static void main(String[] args) { int a, b, c, d; Scanner sc = new Scanner(System.in); System.out.print("Enter 4 numbers : "); a = sc.nextInt(); b = sc.nextInt(); c = sc.nextInt(); d = sc.nextInt(); System.out.println("Average : " + average(a, b, c, d)); } static float average(int a, int b, int…arrow_forward
- Describe how the arguments are used in the following code: def display_state_details(state_code,district_code): print(state_code,district_code,end="") def display_vehicle_number(vehicle_code,vehicle_number): print(vehicle_code,vehicle_number) def main(): state_code=input("Enter the state code:") district_code=int(input("Enter the district number:")) vehicle_code=input("Enter vehicle code:") vehicle_number=int(input("Enter the vehicle number:")) print("The generated licenses plate number is:") display_state_details(state_code,district_code) display_vehicle_number(vehicle_code,vehicle_number) if __name__ == "__main__": main()arrow_forwardProgram10.java Write a Java program that prompts the user to enter a security code that matches a specific pattern. Your program must approve the user's entry. The pattern consists of these characters in this sequence: A lower case character, two upper case characters, two or three digits, two lower case characters, an upper case character, 2 or 3 lower case characters, 2 digits.Refer to Appendix H beginning on pages 1176.Example Run Enter the code patternbHT482haQmo82Yes, bHT482haQmo82 matches the pattern Recheck the requirements before you submit!arrow_forwardGiven the following code segment, what is output to the screen? char name1[20] = "Sean"; char name2[20] = "Pierce"; strcpy(name1,name2); cout << name1 << " " << name2; Group of answer choices Pierce Pierce Sean Sean Sean Pierce None of these ================== Given the following code segment, what is output to the screen? void assignments(int&, int); int main() { int output = 0, input = 5; assignments(output, input); cout << output << endl; } void assignments(int& myOutput, int myInput) { if (myInput < 0) myOutput = -2; else if (myInput == 0) myOutput = 0; else myOutput = myInput; } Group of answer choices 5 0 -2 None of these ============== A void function can be used in an assignment. Group of answer choices True Falsearrow_forward
- #include <iostream>#include <iomanip>#include <cmath>using namespace std; #define PROPERTY_TAX_RATE_PER_YEAR 1.25#define COST_OF_UTILITIES_PER_MONTH 300.00#define COST_OF_INSURANCE_PER_YEAR 550.00 void inputData(double& sellingPrice, double& interestRate, int& durationOfLoan); void handleAllComputations(double sellingPrice,double interestRate,int durationOfLoan,double downPaymentRate,double& downPayment,double& amountOfLoan,double& mortgagePayment,double& propertyTax,double& costOfInsurance,double& totalMonthlyHouseCost); double calculateDownPayment(double sellingPrice, double downPaymentRate);double calculateAmountOfLoan(double sellingPrice, double downPayment);double calculateMortgagePayment(double amountOfLoan,double interestRate,int durationOfLoan); void outputResults(double sellingPrice,double downPayment,double amountOfLoan,double interestRate,int durationOfLoan,double mortgagePayment,double propertyTax,double…arrow_forwardWrite an C# application named MultiplicationTable that prompts the user for an integer value, for example 7. Then display the product of every integer from 1 through 10 when multiplied by the entered value. For example, the first three lines of the table might read 1 x 7 = 7, 2 x 7 = 14, and 3 x 7 = 21.arrow_forwardhi can you please write this code function avg(){vara = parseInt(prompt("Enter 1st number"))varb = parseInt(prompt("Enter 2nd number"))varc = parseInt(prompt("Enter 3rd number"))vard = parseInt(prompt("Enter 4th number")) average = (a+b+c+d)/4} avg() alert("Average is "+average) but instead of asking the user in a java code can you make it in a html code for example somthing like this <html lang="en"><head></head> <body> <h1>Enter a number</h1> <div class="input"> <input id="number" placeholder="number" name="number" type="text"> </div> </body></html>arrow_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 - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher: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
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,