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
Concept explainers
Textbook Question
Chapter 8.9, Problem 8.6CP
Assume that the following enumerated data type has been declared:
enum Creatures{ HOBBIT, ELF, DRAGON }
What will the following code display?
System.out.println(Creatures.HOBBIT + “ ”
+ Creatures.ELF + “ ”
+ Creatures.DRAGON);
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
#include
tinclude
3 tinclude
4 void modify(int *, int) ;
5 int main (void)
int sensor[15];
int i, thr = 15;
for (i=0;i<15;i++)
* (sensor+i)=rand () *100;
8
10
11
printf("Sensor Value\n");
for (i=0;i<15;i++)
printf("%3d",* (sensor+i));
modify(sensor,thr);
printf("\nAfter Modification\n");
for (i=0;i<15;i++)
printf("%3d",*(sensor+i));
return 0;
13
14
15
16
17
18
19
20 L}
21
22 void modify(int *d, int t)
23B {
24
int i;
for (i=0;i<15;i++)
25
26
if (*(d+i) <= t)
* (d+i) = t;
27
28
29
30
B
Sensor Value
41 67 34 0 69 24 78 58 62 64 5 45 81 27 61
After Modification
Sensor Value
41 67 34 0 69 24 78 58 62 64 5 45 81 27 61
After Modification
41 67 34 12 69 24 78 58 62 64 12 45 81 27 61
41 67 34 20 69 24 78 58 62 64 25 45 81 27 61
D
Sensor Value
41 67 34 0 69 24 78 58 62 64 5 45 81 27 61
After Modification
Sensor Value
41 67 34 0 69 24 78 58 62 64 5 45 81 27 61
After Modification
41 67 34 15 69 24 78 58 62 64 15 45 81 27 61
61 87 54 20 89 44 98 78 82 84 25 65101 47 81
oao 123 456 r89
Fill in the blanks
int grades[100];
int i;
for (i=0;i <= 100;i++)
{
grades[i) = 100;
}
The above C++ code is the proper way to initialize the grades array, TRUE or FLASE
True
False
Chapter 8 Solutions
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Ch. 8.1 - Prob. 8.1CPCh. 8.1 - Prob. 8.2CPCh. 8.1 - Describe the limitation of static methods.Ch. 8.8 - Prob. 8.4CPCh. 8.9 - Look at the following statement, which declares an...Ch. 8.9 - Assume that the following enumerated data type has...Ch. 8.9 - Prob. 8.7CPCh. 8 - This type of method cannot access any non-static...Ch. 8 - Prob. 2MCCh. 8 - If you write this method for a class, Java will...
Ch. 8 - Making an instance of one class a field in another...Ch. 8 - This is the name of a reference variable that is...Ch. 8 - This enum method returns the position of an enum...Ch. 8 - Assuming the following declaration exists: enum...Ch. 8 - You cannot use the fully qualified name of an enum...Ch. 8 - The Java Virtual Machine periodically performs...Ch. 8 - If a class has this method, it is called...Ch. 8 - CRC stands for a. Class, Return value, Composition...Ch. 8 - True or False: A static member method may refer to...Ch. 8 - True or False: All static member variables are...Ch. 8 - Prob. 14TFCh. 8 - Prob. 15TFCh. 8 - Prob. 16TFCh. 8 - True or False: Enumerated data types are actually...Ch. 8 - True or False: enum constants have a toString...Ch. 8 - public class MyClass { private int x; private...Ch. 8 - Assume the following declaration exists : enum...Ch. 8 - Consider the following class declaration: public...Ch. 8 - Consider the following class declaration: public...Ch. 8 - A pet store sells dogs, cats, birds, and hamsters....Ch. 8 - Prob. 1SACh. 8 - Prob. 2SACh. 8 - Prob. 3SACh. 8 - Even if you do not write an equals method for a...Ch. 8 - A has a relationship can exist between classes....Ch. 8 - Prob. 6SACh. 8 - Is it advisable or not advisable to write a method...Ch. 8 - Prob. 8SACh. 8 - Look at the following declaration: enum Color {...Ch. 8 - Assuming the following enum declaration exists:...Ch. 8 - Under what circumstances does an object become a...Ch. 8 - Area Class Write a class that has three overloaded...Ch. 8 - BankAccount Class Copy Constructor Add a copy...Ch. 8 - Carpet Calculator The Westfield Carpet Company has...Ch. 8 - LandTract Class Make a LandTract class that has...Ch. 8 - Month Class Write a class named Month. The class...Ch. 8 - CashRegister Class Write a CashRegister class that...Ch. 8 - Sales Receipt File Modify the program you wrote in...Ch. 8 - Parking Ticket Simulator For this assignment you...Ch. 8 - Geometry Calculator Design a Geometry class with...Ch. 8 - Car Instrument Simulator For this assignment, you...Ch. 8 - First to One Game This game is meant for two or...Ch. 8 - Heads or TaiLs Game This game is meant for two or...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Why were computer programming languages invented?
Starting Out With Visual Basic (8th Edition)
What are the advantages and disadvantages of implicit declarations?
Concepts Of Programming Languages
The words that make up a high-level programming language are called______. a. binary instructions b. mnemonics ...
Starting out with Visual C# (4th Edition)
What is the distinction between application software and system software? Give an example of each.
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
True or False: If a subclass constructor does not explicitly call a superclass constructor, Java will not call ...
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Drop Lowest Score Modify Problem 2 above so the lowest test score is dropped. This score should not included in...
Starting Out with C++ from Control Structures to Objects (9th Edition)
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
- Given a map pre-filled with student names as keys and grades as values, complete main() by reading in the name of a student, outputting their original grade, and then reading in and outputting their new grade. Ex: If the input is: Quincy Wraight 73.1 the output is: Quincy Wraight's original grade: 65.4 Quincy Wraight's new grade: 73.1arrow_forwardFind errors / syntax error. Write line numberarrow_forward#include <string>#include <iostream>#include <vector>class Snack{public:Snack(std::string, float, bool);int set_price(float);void set_expired(bool);void set_name(std::string);std::string name() const{return name_;}float price() const{return price_;}bool expired() const{return expr_;}int how_many_for_ten();private:std::string name_;float price_;bool expr_;};void SortByPrice(std::vector<Snack>&,bool); Task: Implement a function working with Snack objects that are stored using a vector. It has the following signature: void SortByPrice(std::vector<Snack>& list_ref, bool asc). This function should sort the vector list_ref based on the price_ of the Snacks. The sorting should be done in the following order: Ascending if asc is true Descending if asc is false. In both cases if variables have the same value for price_, the sorting should be done based on the name_ in ascending order.arrow_forward
- #include <string>#include <iostream>#include <vector>class Snack{public:Snack(std::string, float, bool);int set_price(float);void set_expired(bool);void set_name(std::string);std::string name() const{return name_;}float price() const{return price_;}bool expired() const{return expr_;}int how_many_for_ten();private:std::string name_;float price_;bool expr_;};void SortByPrice(std::vector<Snack>&,bool); Task: Define the public function int Snack::set_price(float price) : If the value passed by price is smaller than 0 the function should return -2. If the value of price is greater or equal to 0, proceed as follows: If the value passed by price is smaller than the current value of price_, the function should assign price to price_ and return -1. If the value passed by price is larger than the current value of price_, the function should assign price to price_ and return 1. If price is equal to price_, the function should assign price to price_ and return…arrow_forwardIn C++ struct myGrades { string class; char grade; }; Declare myGrades as an array that can hold 5 sets of data and then set a class string in each position as follows: “Math” “Computers” “Science” “English” “History” and give each class a letter gradearrow_forwardsnack.h #include <string>#include <iostream>#include <vector>class Snack{public:Snack(std::string, float, bool);int set_price(float);void set_expired(bool);void set_name(std::string);std::string name() const{return name_;}float price() const{return price_;}bool expired() const{return expr_;}int how_many_for_ten();private:std::string name_;float price_;bool expr_;};void SortByPrice(std::vector<Snack>&,bool); main.cpp #include <iostream>using namespace std; #include "snack.h" int main(){ Snack snicker=Snack("Snickers",2.0,false); std::cout<<snicker.name()<<" "<<snicker.price()<<" "<<snicker.expired()<<std::endl; Snack twix=Snack("Twix",3.0,false); std::cout<<twix.name()<<" "<<twix.price()<<" "<<twix.expired()<<std::endl; Snack mars=Snack("Mars",1.5,false); std::cout<<mars.name()<<" "<<mars.price()<<" "<<mars.expired()<<std::endl;…arrow_forward
- The code for a class, the code for a method, and the code for while and for loops with more than ones statement is enclosed in ____. /* and */ [ and ] { and }arrow_forward#include <stdio.h>#include<stdlib.h>struct Distance{int feet;float inch;} dist1, dist2, sum;int main(){struct Distance* distance1 = NULL; struct Distance* distance2 = NULL; struct Distance* distance3 = NULL; distance1 = (struct Distance*)malloc(sizeof(struct Distance*));distance2 = (struct Distance*)malloc(sizeof(struct Distance*));distance3 = (struct Distance*)malloc(sizeof(struct Distance*));printf("input feet for distance no.1:");scanf("%d", &distance1->feet); printf("input inch for distance no.1:");scanf("%f", &distance1->inch); printf("input feet for distance no.2:");scanf("%d", &distance2->feet); printf("input inch for distance no.2:");scanf("%f", &distance2->inch); printf("input feet for distance no.3:");scanf("%d", &distance3->feet); printf("input inch for distance no.3:");scanf("%f", &distance3->inch); printf("1st distance\n");printf("Enter feet: ");scanf("%d", &dist1.feet); printf("Enter inch: ");scanf("%f",…arrow_forwardint class Inventory { std::vector<Item*> m_Items; static unsigned int m_ItemsMade; void CreateItem() { std::string name = "Item " + std::to_string(m_ItemsMade); m_Items.push_back(new Item(name.c_str(), 100 * m_ItemsMade)); ++m_ItemsMade; } public: Inventory() { CreateItem(); CreateItem(); CreateItem(); } void Print() const { size_t* nSize = new size_t(m_Items.size()); std::cout << "_____INVENTORY_____\n"; for (unsigned int i = 0; i < *nSize; ++i) { m_Items[i]->Print(); } } }; GetValidatedInt(const char* strMessage, int nMinimumRange = 0, int nMaximumRange = 0); This function should first display the provided message to the screen then use cin to get an int from the user. Error check and validate to ensure a legal integer was entered. If not, clear the cin buffer using clear() and ignore() and try again (Note: the buffer still needs to be cleared even if this step was successful). If a legal integer was entered, check its value to see if it is within the…arrow_forward
- // Assume all libraries are included 3 void func (int a, int &b, int &c); // int main () { int i = 5, j = 4, k = 33; 4 7 %3D 8. func (i, j, k); func (j, i, k); cout << j « k << i <« endl; 10 11 12 13 return 0; 14 } // 15 16 void func (int a, int &b, int &c) { 17 18 = 2*c + b; 19 b a; 20 C = a + 3*b; } // 21 22 I|||arrow_forwardGroup Project In Java(Airline System) A small airline has just purchased a computer for its new automated system. You have been asked to develop the new system. You are to write an application to assign seats on each flight of the airline’s planes.1. Your application should display the following alternatives: "Please type 1 for Roundtrip" "Please type 2 for One-way"2. Enter passenger’s information (name, gender, phone number,...etc)3. Enter departure and destination airports4. Enter depart and return date(if roundtrip)5. Selection for the seatIf the user types 1, your application should provide inputs for both departure and destination airports and corresponding dates. If the user types 2, your application should only provide inputs for departure airport and depart date. Your application should also display a set of inputs for passenger information.Use a one-dimensional array of primitive type boolean to represent the seating chart of the plane. Initialize all the elements of the…arrow_forward#include<stdio.h>#include<stdlib.h> int cent50=0;int cent20=0;int cent10=0;int cent05=0; void calculatechange(int* change){if(*change>0){if(*change>=50){*change-=50;cent50++;}else if(*change>=20){*change-=20;cent20++;}else if(*change>=10){*change-=10;cent10++;}else if(*change>=05){*change-=05;cent05++;}calculatechange(change);}}void printchange(){if(cent50)printf("\n50cents:%d coins",cent50);if(cent20)printf("\n20cents:%d coins",cent20);if(cent10)printf("\n10cents:%d coins",cent10);if(cent05)printf("\n05cents:%d coins",cent05);cent50=0;cent20=0;cent10=0;cent05=0;}void takechange(int* change){scanf("%d",change);getchar();}int main(){int change=0;int firstinput=0;while(1){if(!firstinput){printf("\nEnter the amount:");firstinput++;}else{printf("\n\nEnter the amount to continue or Enter -1 to…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
What is Abstract Data Types(ADT) in Data Structures ? | with Example; Author: Simple Snippets;https://www.youtube.com/watch?v=n0e27Cpc88E;License: Standard YouTube License, CC-BY