Make a program. Minimum of 3 Classes, (They have to work) Minimum of 6 Methods (
ID: 654407 • Letter: M
Question
Make a program.
Minimum of 3 Classes, (They have to work)
Minimum of 6 Methods (All Working)
Must include: If, For, While, If Else, Arrays, Nested Statments. Minimum of 4 each (minimum of 2 arrays)
If and If Else can work together.
2 calls for a class object.
at least 2 methods containing arguments. example: methodName(int thingHere)
Include at least 1 advance thing that was not covered in the chapters.
Code needs to be working, error free, and clean. So no random nonworking code!
Must have Input from a User. Meaning math, dialog box, buttons, etc.
This must include items from the chapters covered from the book. This can not be taken from the book, nor copied from any place. You may only reference.
This also needs to be advanced, and not a simple math program.
Explanation / Answer
import java.io.*;
class aclass
{
void sq(int a[])
{
int i;
for(i=0;i<5;i++)
{
System.out.println("Square is "+a[i]*a[i]);
}
}
void odd( int a[], int b[], int c[])
{
int i;
for(i=0;i<5;i++)
{
if((a[i]%2) == 0)
{
b[i] = a[i];
}
else
{
c[i] = a[i];
}
}
}
void disp(int b[], int c[])
{
int i;
for(i=0;i<5;i++)
{
System.out.println(b[i]);
}
for(i=0;i<5;i++)
{
System.out.println(c[i]);
}
}
};
class dt_simp
{
public static void main(String args[]) throws IOException
{
int[] a= new int[5];
int [] b = new int[5];
int[] c= new int[5];
int i;
String s1;
aclass o = new aclass();
DataInputStream o1=new DataInputStream(System.in);
for(i=0;i<5;i++)
{
System.out.println("Enter no");
s1=o1.readLine();
a[i]=Integer.parseInt(s1);
}
o.sq(a);
o.odd(a,b,c);
o.disp(b,c);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.