Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
7th Edition
ISBN: 9780134802213
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 8.9, Problem 8.7CP
Program Plan Intro
“enum” keyword:
“enum” data type is used to refer the enumerations in java. Variables, methods and constructors can be added to it. The main objective of “enum” is to define own data types. Every enum constant represents an object of type enum.
Example:
enum Color
{
Blue, Yellow, Red;
}
public class test
{
public static void main(String[] args)
{
Color c1=Color.Blue;
System.out.println(c1);
}
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
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
Text-based adventure game: Pretend you are creating a text-based adventure game. At different points in the game, you want the user to select to fight, run, or hide from certain enemies. Modify the application below (week3.py) so that the selection variable is sent as an argument into the choice() function.
The user should enter 1 to fight, 2 to run, or 3 to hide in the main(). The choice() function should print one of the three options.
You will need to add an if statement in the choice() function to make the correct selection.
Please fo function to set grades
.
Chapter 8 Solutions
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Ch. 8.1 - What is the difference between an instance field...Ch. 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...
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
- Assignment Content Write a program that lets the user enter the coordinates of the center and radius of two circles, circle 1 with center coordinates at (* Y1 and circle 2 with center coordinates at (X y,). The program then determines whether circle 2 is inside circle 1 or overlaps with circle 1. rl rl • (x1, y1) (x1, y1) (x2, y2), (x2, y2) Circle 2 is found to be inside circle 1 if distance between the centers is <=Tradius circle1 - radius cirede and circle 2 is said to overlap circle one if the distance between the two centers is <=radius circle1 + radius circle2- Test Cases: Enter center coordinates (x, y) and radius of circle 1:0.5 5.1 13 Enter center coordinates (x, y) and radius of circle 2:11.7 4.5 Circle 2 is inside of circle 1 Enter center coordinates (x, y) and radius of circle 1:3 75.5 Enter center coordinates (x, y) and radius of circle 2: 6.7 3.5 3 Circle 2 overlaps circle 1 Enter center coordinates (x, y) and radius of circle 1:3.55.5 1 Enter center coordinates (x, y) and…arrow_forwardusing System; using System.Linq; using System.Text; namespace Games; { class Program { staticvoid Main(string[] args) { int choice,games_choice; cout<<"What are your favorite games - outdoor or indoor"<<endl; cout<<"Press 1 for 'outdoor' or Press 2 for 'indoor'"<<endl; cin>>choice; if(choice==1) { cout<<"What is your favorite outdoor game"<<endl; cout<<"Press 1 for Tennis"<<endl; cout<<"Press 2 for Football"<<endl; cout<<"Press 3 for Cricket"<<endl; cin>>games_choice; if(games_choice==1) cout<<"I also like Tennis"<<endl; elseif(games_choice==2) cout<<"I also like Football"<<endl; elseif(games_choice==3) cout<<"I also like Cricket"<<endl; } elseif(choice==2) { cout<<"What is your favorite indoor game"<<endl; cout<<"Press 1 for Ludo"<<endl; cout<<"Press 2 for Chess"<<endl; cout<<"Press 3 for Cards"<<endl;…arrow_forwardActivity 20 Electric Bill: Using Switch Statement, write a program that will calculate and show bills of the Manila Electric Company. The rates vary depending on whether the use is residential (R), commercial( C) , or industrial (I). Any other code should be treated as an error. The program should accept the subscriber ID, Subscriber Name, his total electrical consumption in a month, and the code of the consumer type. The rates are computed as follows: R: 50 plus .50 per kwh used C: 100 for the first 1000 kwh and 0.45 for each additional kwh I: 180 for the first 1000 kwh and 0.75 for each additional kwharrow_forward
- Grade Book A teacher would like to assign a letter grade to a student, based on student's test score. Write a program to help this teacher managing her students' test score. Use the following grading scale to assign a letter grade to a student. Test Score Letter Grade 80 - 100 A 70 - 79 B 60 69 C 50 - 59 0- 49 F Your program must have an array of string objects to hold the student names and an array of int to hold the student scores. Let the teacher determines the number of students and ask the teacher to enter the information for each student. Your program should have the following programmer-defined functions: getInput () - to read the students name and scores from user getGrade () - to determine the letter grade corresponding to the score getReport () - to determine the maximum, minimum, average and standard deviation of the scores Display an error message if the teacher enter mark below 0 or above 100, and keep asking for a valid value. The program should also be capable of…arrow_forwardNumber guessing Game Write a C program that implements the “guess my number” game. The computer chooses a random number using the following random generator function srand(time(NULL)); int r = rand() % 100 + 1; that creates a random number between 1 and 100 and puts it in the variable r. (Note that you have to include <time.h>) Then it asks the user to make a guess. Each time the user makes a guess, the program tells the user if the entered number is larger or smaller than its number. The user then keeps guessing till he/she finds the number. If the user doesn’t find the number after 10 guesses, a proper game over message will be shown and the actual guess is revealed. If the user makes a correct guess in its allowed 10 guesses, then a proper message will be shown and the number of guesses the user made to get the correct answer is also printed. After each correct guess or game over, the user decides to play again or quit and based on the user choice, the computer will make…arrow_forwardC++: Describe how the following call by reference works. Make a comment for each line. void pxc(int& c, int& d) { int k = c; c = d; d = k; } int main() { int a = 15, b = 100; pxc(a, b); }arrow_forward
- in c++ without using arraysarrow_forwardComplete main() to read dates from input, one date per line. Each date's format must be as follows: March 1, 1990. Any date not following that format is incorrect and should be ignored. Use the substr() function to parse the string and extract the date. The input ends with -1 on a line alone. Output each correct date as: 3-1-1990. Ex: If the input is: March 1, 1990 April 2 1995 7/15/20 December 13, 2003 -1 then the output is: 3-1-1990 12-13-2003 Use the provided GetMonthAsInt() function to convert a month string to an integer. If the month string is valid, an integer in the range 1 to 12 inclusive is returned, otherwise 0 is returned. Ex: GetMonthAs Int("February") returns 2 and GetMonthAs Int("7/15/20") returns 0.arrow_forwardJAVA Programming Problem 5 – CharacterArray Write a program which will store the following string into a character array: 6901 Sudley Road Manassas VA Your program will display each original character, determine and display whether the character is a digit or a letter, and redisplay the character according to the directions below. Directions Create a class called CharacterArray. The scanner class is not required. Initialize the character array with the given string. Write a program which will accept an alpha numeric string at the keyboard. Store the string, of any length, into a character array, for example: RBDB Manassas Campus 6901 Sudley Road Manassas VA 20109 For each visible character: Display the original character Determine and display whether the character is a digit or a letter If the character is a lower case letter, redisplay the character in upper case If the character is a upper case letter, redisplay the character in lower case If the character is a digit, display it…arrow_forward
- Date: Lab Objectives This lab was designed to reinforce the following programming concepts: Using repetition structures. Using decision making Using /0 files. Exercise#1: Counting Number of Digits Write a Java program that inputs one integer number from the user, determine the number af individual digits and prin the number of digits and the digits separated from one another by a tab space. For example, if the user types in the numbe 42339, the program should print "There are 5 digits, which are 4 2339", Sample Input/Output Enter an integer value: 12345678 There are(8 aigite, wrich are(1)2 3 45676 num/13 Exercise#2: Sales A mal-order house sells five products whose retail arices are as follows: Procuct 1. $2. sa; product 2, 54.50; product 3, 34. 481 Eroduct 4. $4.99 and product 5. $6.87. Write a Java program that reads a series of pairs as foliows: product number and product name. The quantity sold is generated at randam between O and 50. Your program should n a svitch statem.ent to…arrow_forwardRest of code in image / This is a bad programming style since it is using goto. // This is an spagetti code and not working.// Use function to display menu, and display game rules,// Use different color for text display.// fix it so it works any way you like./*HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE); // Write 16 lines in 16 different colors. for (int color = 0; color < 16; color++) { SetConsoleTextAttribute (screen, color); cout << " Hello World!" << endl; Sleep(400); // Pause between lines to watch them appear } // Restore the normal text color) SetConsoleTextAttribute(screen, 7);*/#include <iostream>#include <windows.h>using namespace std;int main(){ //textbackground(WHITE); //textcolor(RED); system("cls"); char ch, a[20], ch2; int num = 100, rnum, guess, count, ch1, c = 0; cout << "**********************************************************"<<endl; cout << "*…arrow_forward// LeftOrRight.cpp - This program calculates the total number of left-handed and right-handed // students in a class. // Input: L for left-handed; R for right handed; X to quit. // Output: Prints the number of left-handed students and the number of right-handed students. #include <iostream> #include <string> using namespace std; int main() { string leftOrRight = ""; // L or R for one student. int rightTotal = 0; // Number of right-handed students. int leftTotal = 0; // Number of left-handed students. // This is the work done in the housekeeping() function cout << "Enter an L if you are left-handed, a R if you are right-handed or X to quit: "; cin >> leftOrRight; // This is the work done in the detailLoop() function // Write your loop here. // This is the work done in the endOfJob() function // Output number of left or right-handed students. cout << "Number of left-handed students:…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT