Question
Part A: Objective: Implement methods in Java from a specification. Problem Statement: Create a class called MathLibs which is capable of calculating the absolute value,
Part A: Objective: Implement methods in Java from a specification. Problem Statement: Create a class called MathLibs which is capable of calculating the absolute value, the oddness of a number and prints a message about the magnitude of the number. See the method headers in the starter code for a complete description of functionality of these methods. Create a new project called Lab7-MathLibs. Download and add the MathLibs.java starter code provided on Blackboard.
Part B: Objective: Implement a method in Java. Problem Statement: Create a program which will display a spaceship at a relative position across the width of the screen. The position should be a percentage value from 0-100 where 0 would represent the left side of the display, 50 would represent the middle and 100 would represent the right side of the screen. It should be possible to redraw the spaceship multiple times, with each rendering appearing on a new line. The ship will be represented by one * character. You should create a method named printShip to display the ship at the appropriate position. Call the program SpaceShip.java
The MathLibs
public class MathLibs { public static void main(String[] args) { // Print some stats on -5, 0 and 5 for(int i = -5; i <=5; i += 5) { System.out.println("|" + i + "| is " + absValue(i)); System.out.println("Is " + i + " odd? " + isOdd(i)); printMagnitude(i); System.out.println("---"); } } /************************************************************************** * absValue - Calculates the absolute value of an integer number * * int x - The number whose absolute value is to be determined * return int - The absolute value (i.e., distance from 0) for x, the given int */ public static int absValue(int x) { return 0; } /************************************************************************** * isOdd - Determines if an integer value is odd * * int x - The number whose oddness is to be checked * return boolean - Indicates if the given integer is odd. */ public static boolean isOdd(int x) { return false; } /************************************************************************** * printMagnitude - Prints a message to the display containing * the distance of an integer value from 0 (i.e., magnitude) * * int x - The number whose magnitude is to be determined and displayed */ public static void printMagnitude(int x) { } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started