
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
Translate the pseudocode in Section 2.4 for computing the number of tiles and the gap width into Java.
number of pairs = integer part of (total width - tile width) / (2 x tile width)number of tiles = 1 + 2 x number of pairsgap at each end = (total width - number of tiles x tile width) / 2
I'm wondering why this test failed, during another test, it was good because the gap was 1.00. Is there something I should do in terms of rounding?
![... 7. Translate the pseudocode in Section 2.4 for computing the number of tiles and the gap width into Java.
number of pairs
number of tiles = | + 2 x number of pairs
integer part of (total width - tile width) / (2 x tile width)
gap at each end
= (total width - number of tiles x tile width) / 2
Tiles.java
1 import java.util.Scanner;
3 public class Tiles
4 {
5
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Total width: ");
int totalWidth = in.nextInt ();
System.out.print ("Tile width: ");
int tileWidth = in.nextInt();
int pairs = (totalWidth - tilewidth) /(2 * tileWidth);
int tiles= 1 + (2 * pairs);
double gap = (totalWidth - (tiles * tileWidth))/2;
System.out.printf("Pairs: %d%nTiles: %d%nGap:
}
7
10
11
12
13
14
15
16
%.2f%n", pairs, tiles, gap);
17 }
CodeCheck
Reset
Testing Tiles.java
Test 1
Actual output
Expected output
Total width: Tile width: Pairs: 9 Total width: Tile width: Pairs: 9
Tiles: 19
Tiles: 19
Gap:
2.00
Gap:
2.50](https://content.bartleby.com/qna-images/question/d772767f-fd91-4ca5-b737-b5766e3fef0a/95e06998-5ec7-4dc6-bc62-5cf616813517/wzaib2t_thumbnail.png)
Transcribed Image Text:... 7. Translate the pseudocode in Section 2.4 for computing the number of tiles and the gap width into Java.
number of pairs
number of tiles = | + 2 x number of pairs
integer part of (total width - tile width) / (2 x tile width)
gap at each end
= (total width - number of tiles x tile width) / 2
Tiles.java
1 import java.util.Scanner;
3 public class Tiles
4 {
5
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Total width: ");
int totalWidth = in.nextInt ();
System.out.print ("Tile width: ");
int tileWidth = in.nextInt();
int pairs = (totalWidth - tilewidth) /(2 * tileWidth);
int tiles= 1 + (2 * pairs);
double gap = (totalWidth - (tiles * tileWidth))/2;
System.out.printf("Pairs: %d%nTiles: %d%nGap:
}
7
10
11
12
13
14
15
16
%.2f%n", pairs, tiles, gap);
17 }
CodeCheck
Reset
Testing Tiles.java
Test 1
Actual output
Expected output
Total width: Tile width: Pairs: 9 Total width: Tile width: Pairs: 9
Tiles: 19
Tiles: 19
Gap:
2.00
Gap:
2.50
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images

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 a java program that prompts user for 10 numbers of any type and stores them in an array. Then print the following: All the values in the array. The sum of all values in the array. The average of all values in the array. The largest value in the array. The smallest value in the array. All the positive numbers in array. All the negative numbers in array. All the odd numbers in array. All the even numbers in array.arrow_forwardNeeds to be written in java: Write a program with a main() method that asks the user to input an integer array of 10 elements.Next, create three methods described below. From inside your main() method, call each of thethree methods described below and print out the results of the methods 2, 3, which return values.1. printReverse() - a method that receives an array of integers, then reverses the elements ofthe array and prints out all the elements from inside the method. Print all in one lineseparated by commas (see sample output below).2. getLargest() – a method that receives an array of integers, then returns the largest integervalue in the array. (print result from main())3. computeTwice()- a method that receives the previously reversed array of integers, thenreturns an array of integers which doubles the value of each number in the array (see thesample output below). (print result from main())Sample output:Enter a number:22Enter a number:34Enter a number:21Enter a number:35Enter a…arrow_forwardThere are three main operations on rectangles: intersection, union, and difference. Among them, only intersection is guaranteed to return another rectangle. In general, the union of two rectangles is... two rectangles, and the difference between two rectangles is ... a whole lot of rectangles, as we will see. We let you implement rectangle intersection. Of course, the intersection is defined only if the rectangles have the same number of dimensions. The intersection is computed by taking the intersection of the intervals of the two rectangles for corresponding dimensions. If one of the intervals is empty, you should return None. [] # @ title Rectangle intersection def rectangle_and(self, other): if self.ndims != other.ndims: raise TypeError("The rectangles have different dimensions: {} and {}".format( )) self.ndims, other.ndims ### YOUR SOLUTION HERE Rectangle. _and_ = rectangle_and [ ] r1 = Rectangle((2, 3), (0, 4)) r2 = Rectangle((0, 4), (1, 3)) draw rectangles (r1, r2) draw…arrow_forward
- I need help solving this in Java. The expected outputs are shown but after the last number the should not be a space after it. Ex: 4 3 2 1(no space after)arrow_forwardWrite a Java program that expands a given binomial (x + y)^n, where integer n is user input. To do the work of the binomial expression, first create a method that accepts n as a parameter and then returns an array holding the coefficients needed for the binomial expansion using the Pascal’s Triangle method. Create a 2nd method which takes the array holding the coefficients as a parameter and prints the appropriate binomial expansion. For example, if n = 5 is entered by the user, the method calculating the coefficients should return {1,5,10,10,5,1} and the method that prints the expansion should print the following: (x + y)^5 = x^5 + 5x^4y + 10x^3y^2 + 10x^2y^3 + 5xy^4 + y^5 Your main method should use an appropriate loop for repeated inputs and automatically call the methods to calculate the coefficients and print the binomial expansion. There isn’t a need for a menu although you should ask the user if they want to quit or continue after their binomial expansion is printed each time.…arrow_forward
arrow_back_ios
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