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

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...
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)...
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, in most simple algorithm Using a stack class, write a static method called...
in Java language, in most simple algorithm Using a stack class, write a static method called parse that parses a String for balanced parentheses. we seek only to determine that the symbol ‘{‘ is balanced with ‘}’. parse accepts a single String parameter and returns an int. If parse returns a minus 1, then there are no errors, otherwise, parse should return the position within the String where an error occurred. For example parse(“{3 + {4/2} }”)   would return -1...
Language: Java I have written this code but not all methods are running. First method is...
Language: Java I have written this code but not all methods are running. First method is running fine but when I enter the file path, it is not reading it. Directions The input file must be read into an input array and data validated from the array. Input file format (500 records maximum per file): comma delimited text, should contain 6 fields: any row containing exactly 6 fields is considered to be invalid Purpose of this code is to :...
Write a RECURSIVE method that receives as a parameter an integer named n. The method will...
Write a RECURSIVE method that receives as a parameter an integer named n. The method will output n # of lines of stars. For example, the first line will have one star, the second line will have two stars, and so on. The line number n will have "n" number of ****** (stars) so if n is 3 it would print * ** *** The method must not have any loops!
Write a RECURSIVE method that receives a string as a parameter. The method will return true...
Write a RECURSIVE method that receives a string as a parameter. The method will return true if the string received as a parameter is a palindrome and false if it is not. The method must not have any loops! In JAVA
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT