In: Computer Science
JAVA Assignement
In the same file, create two classes: a public class Module1 and a non-public (i.e. default visibility) class Module1Data. These classes should have the following data fields and methods:
d(i.e., the value of (int)number cubed, not (int)(number cubed))
Additional Constraints
/* No comments the exact comments mentioned in the questions is followed*/
import java.util.*;
import java.lang.*;
import java.io.*;
public class Module1
{
Module1Data m1d;
double input;
Scanner scanner;
public Module1()
{
m1d=new Module1Data();
scanner=new
Scanner(System.in);
}
public static void main(String[] args)
{
Module1 module1=new
Module1();
System.out.println("Application
launched");
System.out.println("Enter a
floating point number to be squared and cubed");
module1.input=module1.scanner.nextDouble();
System.out.println("int
squared"+module1.m1d.square((int)module1.input));
System.out.println("double
squared"+module1.m1d.square(module1.input));
System.out.println("int
cubed"+module1.m1d.intCubed((int)module1.input));
System.out.println("double
cubed"+module1.m1d.doubleCubed(module1.input));
}
}
class Module1Data
{
int square(int number)
{
return
(int)Math.pow(number,2);
}
double square(double number)
{
return Math.pow(number,2);
}
int intCubed(double number)
{
return
(int)Math.pow((int)number,3);
}
double doubleCubed(double number)
{
return Math.pow(number,3);
}
}
sample output:
Application launched
Enter a floating point number to be squared and cubed
5.5
int squared25
double squared30.25
int cubed125
double cubed166.375