Question

In: Computer Science

Java language. 1. write a conversion method that have 2 parameter 1. feet and 2. inches(as...

Java language.

1. write a conversion method that have 2 parameter 1. feet and 2. inches(as small as 1/8 inch)(make sure precondition, can't be smaller than 1/8 inch)

and give output as feet in decimal place.

2 Write a method to calculate the area of a rectangle that take in width and height (feet) (as small as 1/8 inch)(make sure precondition, can't be smaller than 1/8 inch) and round up to the closet feet.

Write test cases for both method in J unit (including precheck the precondition (as small as 1/8 inch))

Solutions

Expert Solution

JAVA CODE:

package ideone;
import java.util.*;
import java.lang.*;
import java.io.*;

class Ideone
{
   //method to convert feets and inches to feets
   static double feet(double feets,double inch)
   {
       //if inches is less than 1/8 then precondition is not satisfied
       if(inch < 0.125){
           System.out.println("Precondition not satisfied.");
           return 0;
       }
       //returning answer by converting inches into feet and adding it into the given feets
       return feets + inch*0.0833333;
   }
  
   //method to calculate area of rectangle
   static double area(double height,double width)
   {
       //if either height or width of rectangle is less than 1/8 inches(which is equal to 0.01041667 feets).
       if(width < 0.01041667 || height < 0.01041667){
           System.out.println("Precondition not satisfied.");
           return 0;
       }
       //returning area of rectangle i.e height * width
       return width*height;
   }
   public static void main (String[] args) throws java.lang.Exception
   {
       //TEST CASE 1
       double test_feet1=5.00,test_inches1=0.345;
       double test_height1=.65,test_width1=0.345;
      
      
      
       if((int)feet(test_feet1,test_inches1)!=0.00){
          
           System.out.println("Test Case 1(FEET) :");
           System.out.println("feet = 5.00 , inches = 0.345 ");
           System.out.println("Feets in decimal places : "+ feet(test_feet1,test_inches1));
       }
       if(area(test_height1,test_width1)!=0.00){
          
           System.out.println("Test Case 1(AREA) :");
           System.out.println("height = .65 , width = 0.345 ");
           System.out.println("Area in decimal places : "+ area(test_height1,test_width1));
       }
       System.out.println("");
      
      
       //TEST CASE 2
       double test_feet2=8.535,test_inches2=0.098;
       double test_height2=.65,test_width2=0.01005;
      
      
       System.out.println("Test Case 2(FEET) :");
       System.out.println("feet = 8.535 , inches = 0.098 ");
       if(feet(test_feet2,test_inches2)!=0.00){
           System.out.println("Feets (in decimal places) : "+ feet(test_feet2,test_inches2));
       }
      
      
       System.out.println("Test Case 2(AREA) :");
       System.out.println("height = .65 , width = 0.01005 ");
       if(area(test_height2,test_width2)!=0.00){
           System.out.println("Area (in decimal places) : "+ area(test_height2,test_width2));
       }
      
   }
}

CODE SCREENSHOT:

OUTPUT:


Related Solutions

Write a java program called ImperialMetric that displays a conversion table for feet and inches to...
Write a java program called ImperialMetric that displays a conversion table for feet and inches to metres. The program should ask the user to enter the range of values that the table will hold. Here is an example of what should be output when the program runs: Enter the minimum number of feet (not less than 0): 5 Enter the maximum number of feet (not more than 30): 9 | | | | | | 0" 1.524 1.829 2.134 2.438...
Java 1.Write a method removeEvenLength that takes an ArrayList of Strings as a parameter and that...
Java 1.Write a method removeEvenLength that takes an ArrayList of Strings as a parameter and that removes all of the strings of even length from the list. 2. Given the following Vehicle interface and client program in the Car class: public interface Vehicle{ public void move(); } public class Car implements Vehicle{ public static void main(String args[]) Vehicle v = new Vehicle(); // vehicle declaration } The above declaration is valid? True or False? 3. Java permits a class to...
Java Write a valid Java method called printReverse that takes a String as a parameter and...
Java Write a valid Java method called printReverse that takes a String as a parameter and prints out the reverse of the String. Your method should not return anything. Make sure you use the appropriate return type.
using java language only write a code Have the function StringChallenge(str) take the str string parameter...
using java language only write a code Have the function StringChallenge(str) take the str string parameter being passed and return the number of words the string contains (e.g. "Never eat shredded wheat or cake" would return 6). Words will be separated by single spaces. Examples Input: "Hello World" Output: 2 Input: "one 22 three" Output: 3 ------- you have the following code edit it to get the result mport java.util.*; import java.io.*; class Main {   public static String StringChallenge(String str)...
Language java Rewrite the method getMonthusing the "this" parameter CODE: import java.util.Scanner; public class DateSecondTry {...
Language java Rewrite the method getMonthusing the "this" parameter CODE: import java.util.Scanner; public class DateSecondTry { private String month; private int day; private int year; //a four digit number. public void writeOutput() { System.out.println(month + " " + day + ", " + year); } public void readInput() { Scanner keyboard = new Scanner(System.in); System.out.println("Enter month, day, and year."); System.out.println("Do not use a comma."); month = keyboard.next(); day = keyboard.nextInt(); year = keyboard.nextInt(); } public int getDay() { return day;...
In java Write a static method named consecutiveDigits that accepts an integer n as a parameter...
In java Write a static method named consecutiveDigits that accepts an integer n as a parameter and that returns the highest number of consecutive digits in a row from n that have the same value. For example, the number 3777785 has four consecutive occurrences of the number 7 in a row, so the call consecutiveDigits(3777785) should return 4. For many numbers the answer will be 1 because they don't have any adjacent digits that match. Below are sample calls on...
Please use JAVA to do this: Write a method that takes four strings as parameter. The...
Please use JAVA to do this: Write a method that takes four strings as parameter. The first string should be a pokemon name, the second a pokemon type(either fire, water, or leaf, where water beats fire, fire beats leaf and leaf beats water), the third a pokemon name, and the fourth a pokemon type. The method should print out which pokemon has the advantage over the other based on their type. Example: Pokemon X(which is the fire type) has the...
Programming language is Java: Write a pseudocode method to determine if a set of parentheses and...
Programming language is Java: Write a pseudocode method to determine if a set of parentheses and brackets is balanced. For example, such a method should return true for the string, "[()]{}{[()()]()}" and false for the string "[(])". Also please discuss how the algorithm will perform and how much space in memory it will take if somebody passes a massive string as input.
Write, in Java, a recursive method countBinaryStrings that has one integer parameter n and returns the...
Write, in Java, a recursive method countBinaryStrings that has one integer parameter n and returns the number of binary strings of length n that do not have two consecutive 0’s. For example, for n = 4, the number of binary strings of length 4 that do not contain two consecutive 0’s is 8: 1111, 1110, 1101, 1011, 1010, 0111, 0110, 0101. For this problem, your method needs to return only the number of such strings, not the strings themselves. You...
in java language Write a method called findNums that takes a two-dimension array of integers and...
in java language Write a method called findNums that takes a two-dimension array of integers and an int as parameters and returns the number of times the integer parameter appears in the array. For example, if the array (as created by the program below) is 10 45 3 8 2 42 3 21 44 And the integer parameter is 3, the value returned would be 2 (the number 3 appears two times in the array) public class Question2 {   ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT