Concept explainers
Open the Code Pad in the better-ticket-machine project. Type the following in the Code Pad:
Take care to type these lines exactly as they appear here; pay particular attention to whether or not there is a semicolon at the end of the line. Note what the calls to getBalance return in each case.
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Additional Engineering Textbook Solutions
Database Concepts (8th Edition)
Concepts Of Programming Languages
Management Information Systems: Managing The Digital Firm (16th Edition)
SURVEY OF OPERATING SYSTEMS
Starting Out with C++ from Control Structures to Objects (9th Edition)
Starting Out With Visual Basic (8th Edition)
- Create a class that represents the grade distribution for a given course. In this class you should write methods to perform the following tasks: Read the number of each of the letter grades A, B, C D and F Set the number of letter grades A, B, C, D and F Return the total number of grades Return the percentage of each letter grade as a whole number between 0 and 100 inclusive Draw a bar graph of the grade distributionThe graph should have five bars, one per grade. Each bar can be a horizontal row of asterisks, such that the number of asterisks in a row is proportionate to the percentage of grades in each category. For example, let on asterisk represent 2%, so 50 asterisks correspond to 100%. Mark the horizontal axis at 10% increments from 0 to 100% and label each line with a letter grade.For example, if the grades are entered as 1A, 4B's, 6C's, 2D's and 1 F, then the output would look like: 0 10 20 30 40 50 60 70 80 90 100 IIIIIIIIIII **************************************************…arrow_forwardcanMove(int x, int y, int destX, int destY, Side s): This method returns true if the player of color s can move the piece at coordinates (x,y) can move to coordinates (destX, destY) on the board in its current state. This means that here you do need to consider this piece’s interaction with other pieces on the board. Conditions for this method to return false are given in the code. public boolean canMove(int x, int y, int destX, int destY, Side s){ /* TODO write a method that checks if a piece at coordinates x,y can move to coordinates destX,destY Conditions for false: - Origin or destination coordinates are outside the board - Piece at origin is null - If source and destination coordinates are the same - Piece at origin is not of the same side as s - You can check this using piece.getSide() - Piece cannot move to the destination by piece movement rules - You should check this using Piece.canMove(destX,…arrow_forwardMake a MAZE game on Spyder, giving the user to choose their route. Each route will have either doors or obstacles that the user will solve or use logic to complete. Use a random function so the obstacles change with a new try. The user needs to get out of the Maze in three tries or he loses a life. The user will be asked a question whether they want to try it again or skip the level. Need help with the code!! Thank youarrow_forward
- Can you implement the Student class using the concepts of encapsulation? A solution is placed in the "solution" section to help you, but we would suggest you try to solve it on your own first. You are given a Student class in the editor. Your task is to add two fields: ● String name ● String rollNumber and provide getter/setters for these fields: ● getName ● setName ● getRollNumber ● setRollNumber Implement this class according to the rules of encapsulation. Input # Checking all fields and getters/setters Output # Expecting perfectly defined fields and getter/setters. There is no need to add constructors in this class.arrow_forwardLook at the API of the Point class and find out how to construct a Point object. Write a Java program “PointTester”, that constructs two points with coordinates (3, 4) and (–3, –4). Find the distance between them, using the distance method. Print the distance, as well as the expected value. (You may draw a sketch on graph paper to find the value you will expect.) - Update your program so it randomly select coordinate points (x,y), where −50 ≤ ? ≤ 50 ??? ? ∈ [−90, 90].arrow_forwardPlease show work in javaarrow_forward
- Q2: Wire a code for an Arduino Car Speed Detector shown in the schematic diagram below (IR sensor=KY-032) IR sensor 1 IR sensor 2 How it works: This project works on a simple physics law of calculating the speed as distance/time. Speed = Distance/Time When a car passes the ist IR sensor, it detects and save the first-time value. Then we measure the second time value when the car reaches the IR sensor 2. The difference of both the time is the travel distance from one sensor to the other. We get the time in which car travels a distance of 10 meters so we can calculate the speed of the car. 10 metersarrow_forwardAVA code OVERVI EW This is a review exercise, so the primary goal of the exercise is to get your mind working and in the correct space.In this activity you will create a imaginary grid of locations that goes from −?≤?≤?, −?≤?≤?, with the coordinate (0,0) being "home". On this grid you will keep track of various animal objects as they move around the grid. Make sure that all animals stay within that grid at all timesincluding when they are created. Zwill be the map size and will control the highest number allowed on themap before wraping around. Using Java, create the following classes and primary program that uses the classes that you developed. INS T RUCT IONS Create the following classes. A N I MA L C LA SS Create an Animal class. Each animal has a name, an x and y integer coordinate. The Animal class should have at minimum the following methodsbelowbut you may want to add more if necessary: Also note, everyanimal will need to have to have “z”passed to it so that it knows how big the…arrow_forwardCalculating the area under a curve is a standard problem in numerical methods. What you will develop is an app that calculates and displays the area under a range of curves. Figure 1: Area under the curve of y = x2 over the range 1 to 2, with 1 trapezoid. The area can be calculated by drawing one or more polygons (trapezoids) that approximate the curve. We start by drawing a trapezoid that encompasses our curve between the given limits and the x-axis, so for equation 1 of table 1, it looks like figure 1. We then calculate the area of the trapezoid. Notice that the trapezoid over-estimates the true area. With enough (smaller) trapezoids we can get a very good approximation to the area under the curve (see figure 2). The sum of the area of the smaller trapezoids is the area under the curve. The area of a trapezoid is given by: A = ½ (h1 + h2) d Plot graphs of the equations in table 1 for varying (input) total numbers of trapezoids. Compute and display the area between each curve and…arrow_forward
- Design an application that does the following: A Solid can be a FlatSurfaceSolid or a CurvedSurfaceSolid. Every solid will have a volume. The method volume will be polymorphic. A solid has faces, vertices and edges. A flat-surface solid also has a variable called side which represents the length of the side. A curved-surface solid also has a radius. A Cube is a FlatSurfaceSolid. A cube has 6 faces, 8 vertices and 12 edges. It will have a side. A Sphere is a CurvedSurfaceSolid. It has 1 face, 0 vertices and 0 edges. It will have a radius. Create an ArrayList of solids (driver file named YourLastNameCISC231Q1.java). The arraylist will have 4 elements – 2 cubes (one with side length 3 and another will side length 4) and 2 spheres (one with radius 3 and another with radius 4). Create a driver class to instantiate an array of solids and display the details of each solid along with the volume of each solid.arrow_forwardCurrently, there are two draw rectangle methods in the DoodleController class. Since two different turtles need to draw a rectangle, create a draw rectangle method in the DoodleTurtle class that will take the width and height of the rectangle as parameters and draw a rectangle of the specified size. The size will be the number of steps by the turtle. With the new method introduced, the calls to drawRectangleWithLittleTurtle and drawRectangleWithBigTurtle can be replaced with a call to the turtle’s drawRectangle method passing in the desired size of the rectangle. Refactor the DoodleController accordingly. Note: When you are done with the refactoring the drawRectangleWithLittleTurtle and drawRectangleWithBigTurtle method in the DoodleController need to be deleted. After this refactoring, do not move on until you verify the program works as it did before.arrow_forwardExercise 1 - Number Guessing Game Make a new Java Project called Lab2. Within it, add a new class with the main method called NumberGuessGame. Inside the main method, implement a number guessing game, which will work by generating a pseudorandom number in the range of 0 to 100 (inclusive, so both 0 and 100 should be possible), then asking the user to enter a number that will be their guess. If the two match, display an appropriate message. Otherwise, display either "greater" or "lesser", depending on whether the pseudorandom number is greater than or less than the number entered.arrow_forward
- 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