Question: In Java Complete this lab import java.util.Scanner; public class L4 { public static void main(String[] args) { Scanner keyboard = new Scanner (System.in); System.out.println(Enter the
In Java Complete this lab
import java.util.Scanner; public class L4 {
public static void main(String[] args) { Scanner keyboard = new Scanner (System.in); System.out.println("Enter the number of feet as a whole number"); int feet1 = keyboard.nextInt(); System.out.println("Enter the number of inches as a whole number"); int inch1 = keyboard.nextInt(); FeetInches f = new FeetInches(feet1, inch1); System.out.println(f); System.out.println("Enter an integer"); int num = keyboard.nextInt(); FeetInches m= f.multiply(num); System.out.print(f + " multiplied by " + num + " is "); System.out.println(m); FeetInches d= f.divide(num); System.out.print(f + " divided by " + num + " is "); System.out.println(d); System.out.println("Enter the number of feet as a whole number"); int feet2 = keyboard.nextInt(); System.out.println("Enter the number of inches as a whole number"); int inch2 = keyboard.nextInt(); FeetInches g = new FeetInches(feet2, inch2); FeetInches a = f.add(g); System.out.println(f + " plus " + g + " is " + a); FeetInches s = f.subtract(g); System.out.println(f + " minus " + g + " is " + s); } }
public class FeetInches { private int feet; private int inches;
public FeetInches() {//write the code for the default constructor here feet = 0; inches = 0; } public FeetInches(int f, int i) { feet = f + i/12; inches = i%12; } //add accessors and mutators //add methods add, subtract, multiply, divide public String toString() { return feet + " feet " + inches + " inches"; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
