Write a method printCostTable() that prints out a table like the following:
| price | carpet | fitting |
|---|---|---|
| 5.0 | 150.0 | 120.0 |
| 9.0 | 270.0 | 120.0 |
| 13.0 | 390.0 | 120.0 |
The method should take four int arguments representing the width and length of the carpet, a start price and an end price.
The method should first print the headings
| price | carpet | fitting |
|---|
It should then print the price, carpet cost and fitting cost for each price starting from startPrice and increasing in increments of £4, up to but not exceeding endPrice. For example, assume you have initialised an instance of CarpetCostEstimator cce with labour charge £4.0. Then if startPrice is £5 and endPrice £15, and you execute.
cce.printCostTable(5, 6, 5, 15);
three rows of figures should be printed, as shown in the example above.
In order to align the columns of the table accurately, you should begin your method by defining a string that represents a tab character, like this
String tab = "\t";
I'm not sure on how to start with this java exercise so that the function would print a table.
Full working Java code:
import java.io.*;
class Demo {
//Static method to print the desired table
public static void printCostTable(int width, int length, int
startPrice, int endPrice)
{
//Calculate the area
float area = width * length;
//Fitting cost is fixed
float fittingCost = 120.0f;
String tab = "\t";
//Print the header first
System.out.println("price"+tab+"carpet"+tab+"fitting");
//Run loop till the startPrice becomes just less than end price and
increase startprice by 4
for(float i = startPrice; i < endPrice ; i+=4)
{
//Display the row according to given format
System.out.println(i+tab+(area*i)+tab+fittingCost);
}
}
public static void main (String[] args) {
//Call the static method with arguments.
printCostTable(5, 6, 5, 15);
}
}
Output:
price carpet fitting 5.0 150.0 120.0 9.0 270.0 120.0 13.0 390.0 120.0
Write a method printCostTable() that prints out a table like the following: price carpet fitting 5.0...
I need java code for the following problem.
Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...
Write a method called printReverse() that
takes a string and uses recursion to print the contents of the
string in reverse order. The string itself should
not be reversed; it must be left in its
original form.
The method has the following header:
void printReverse(String s, int i)
where s is a reference to the string, and i is an integer
parameter that you may use as you see fit. You do not need
to code up this method as...
This should be in Java Create a simple hash table You should use an array for the hash table, start with a size of 5 and when you get to 80% capacity double the size of your array each time. You should create a class to hold the data, which will be a key, value pair You should use an integer for you key, and a String for your value. For this lab assignment, we will keep it simple Use...
Using Python, Can someone please assist in the following:
These are the hints:
Summary This week's lab is to create a simple multiplication table using nested loops and if statements. Prompt the user for the size of the multiplication table (from 2x2 to 10x10). Use a validation loop to display a warning if the number is less than 2 or greater than 10 and prompt the user to enter the data again until they enter a valid number Put a...
3. Write Java methods to accomplish each of the following Write a method named simpleAry which accepts and return nothing. It creates an array that can hold ten integers. Fill up each slot of the array with the number 113. Then, display the contents of the array on the screen. You must use a loop to put the values in the array and also to display them. Write a method named sury which accepts an array of type double with...
Tasks Write a program that prints in text mode Project 2 written by YOURNAME And shows in a graphical way, as shown below, the names stored in a file. The coordinates to print the names will be also read from another file. Here is an example of what your graphic output should look like with the two files that are provided for test purposes. Drawing Panel Adam Bernie Cameron Daniel Fanny Gerard Harold Issac Jackie Raitlyn Note that the colors...
1) Write a public static method named printArray, that takes two arguments. The first argument is an Array of int and the second argument is a String. The method should print out a list of the values in the array, each separated by the value of the second argument. For example, given the following Array declaration and instantiation: int[] myArray = {1, 22, 333, 400, 5005, 9}; printArray(myArray, ", ") will print out 1, 22, 333, 400, 5005, 9 printArray(myArray,...
Activity: Writing Classes Page 1 of 10 Terminology attribute / state behavior class method header class header instance variable UML class diagram encapsulation client visibility (or access) modifier accessor method mutator method calling method method declaration method invocation return statement parameters constructor Goals By the end of this activity you should be able to do the following: > Create a class with methods that accept parameters and return a value Understand the constructor and the toString method of a class...
How to write the insert, search, and remove functions for this hash table program? I'm stuck... This program is written in C++ Hash Tables Hash Table Header File Copy and paste the following code into a header file named HashTable.h Please do not alter this file in any way or you may not receive credit for this lab For this lab, you will implement each of the hash table functions whose prototypes are in HashTable.h. Write these functions in a...
Prelab Exercises Your task is to write a Java program that will print out the following message (including the row of equal marks): Computer Science, Yes!!!! ========================= An outline of the program is below. Complete it as follows: a. In the documentation at the top, fill in the name of the file the program would be saved in and a brief description of what the program does. b. Add the code for the main method to do the printing. //...