In: Computer Science
Create separate class with these members
a, b, c, x, y, z
int a b c
float x y z
Demonstrate
3) A two arg float, int constructor, and a three arg int, float, float constructor to instantiate objects, initialize variables read from the keyboard, display the sum
Note:- Please type and execute this above java program and also give the output for both problems. (Type a java program)
Hey ,
Here you can find your answer. Comment it if any query i will give the solution for your query. Do like my answer.
JAVA PROGRAM
import java.util.*;
class A
{
int a;
int b;
int c;
A(int a, int b,int c) //constructor
{
this.a=a;
this.b=b;
this.c=c;
int sum=a+b+c;
System.out.println("sum="+ sum);
}
}
class B
{
float x;
float y;
float z;
B(float x, float y,float z) //constructor
{
this.x=x;
this.y=y;
this.z=z;
float sum=x+y+z;
System.out.println("sum="+ sum);
}
}
public class C //main
class
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
System.out.println("Enter a:"); //Print statement
int value1=Integer.parseInt(s.nextLine()); //Read the entered value as
integer
System.out.println("Enter b:");
int value2=Integer.parseInt(s.nextLine());
System.out.println("Enter c:");
int value3=Integer.parseInt(s.nextLine());
A obj=new A(value1,value2,value3); //Object creation; the constructor is
called when the object is created
System.out.println("Enter x:");
float value4=Float.parseFloat(s.nextLine());
//Read the entered value as
Float
System.out.println("Enter y:");
float value5=Float.parseFloat(s.nextLine());
System.out.println("Enter z:");
float value6=Float.parseFloat(s.nextLine());
B obj1=new B(value4,value5,value6);
}
}
OUTPUT