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...
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...
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...
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 :...
Use JAVA language. Using the switch method concept create a program in which you have an...
Use JAVA language. Using the switch method concept create a program in which you have an artist (singer) and the list of his or her songs. Add 18 songs. Then alter the script to achieve the following in each test run: a) Print all the songs. b) Print only song 15. c) Print only song 19.
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
Write a method in JAVA to do the following: As the user to select from 2...
Write a method in JAVA to do the following: As the user to select from 2 different (default) pokemon or load their pokemon by giving you the name of their pokemon. Based on their selection (default or supplied name), read the move list and damage range from the input file(you do not need to create this) for the selected pokemon. Randomly select one of the default pokemon - Bulbasaur, Charmander, Squirtle (or you can add additional computer only options if...
Language is Java Design and write a Java console program to estimate the number of syllables...
Language is Java Design and write a Java console program to estimate the number of syllables in an English word. Assume that the number of syllables is determined by vowels as follows. Each sequence of adjacent vowels (a, e, i, o, u, or y), except for a terminal e, is a syllable. However, the minimum number of syllables in an English word is one. The program should prompt for a word and respond with the estimated number of syllables in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT