Question

In: Computer Science

Create separate class with these members a, b, c, x, y, z int a b c...

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)

Solutions

Expert Solution

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


Related Solutions

Create separate class with these members a, b, c, x, y, z int a b c...
Create separate class with these members a, b, c, x, y, z int a b c float x y z Demonstrate 1) A two arg float constructor, and a two arg int 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)
Given the method static int test(int x, int y, int z){ return(x=y+z); } Which of the...
Given the method static int test(int x, int y, int z){ return(x=y+z); } Which of the follwing is true: public static void main(String[] args) { A System.out.println(test ( 7, 14, 23)) ; B System.out.println(test ( test ( 7,9, 14) , 23 ); C System.out.println( test ( 14, 23 ) ; D System.out.println(test(1,2,4), 14, 23)) ;
L= {x^a y^b z^c | c=a+b(mod 2)} .Create a DFA and NFA for the language L....
L= {x^a y^b z^c | c=a+b(mod 2)} .Create a DFA and NFA for the language L. Solution and explanation please..
class A { public: //constructors // other members private: int a; int b; }; Give declatations...
class A { public: //constructors // other members private: int a; int b; }; Give declatations of operator functions for each of the following ways to overload operator + You must state where the declatation goes, whether within the class in the public or private section or outside the class. The operator + may be overloaded. a) as friend function b) as member function c) as non-friend, non-member function
What are (a) the x component, (b) the y component, and (c) the z component of...
What are (a) the x component, (b) the y component, and (c) the z component of r Overscript right-arrow EndScripts equals a Overscript right-arrow EndScripts minus b Overscript right-arrow EndScripts plus c Overscript right-arrow EndScripts if a Overscript right-arrow EndScripts equals 5.4 i Overscript ̂ EndScripts plus 1.9 j Overscript ̂ EndScripts minus 3.6 k Overscript ̂ EndScripts , b Overscript right-arrow EndScripts equals negative 4.1 i Overscript ̂ EndScripts plus 5.4 j Overscript ̂ EndScripts plus 3.7 k Overscript...
public class P2 { public static int F(int x[], int c) { if (c < 3)...
public class P2 { public static int F(int x[], int c) { if (c < 3) return 0; return x[c - 1] + F(x, c - 1); } public static int G(int a, int b) { b = b - a; a = b + a; return a; } public static void main(String args[]) { int a = 4, b = 1; int x[] = { 3, 1, 4, 1, 5 }; String s = "Problem Number 2"; System.out.println(x[2 +...
which would evaluate to false? ((x&&!y ||z) || !z&&x) a. x and y are false b....
which would evaluate to false? ((x&&!y ||z) || !z&&x) a. x and y are false b. x and z are false c. z is false d. x y z are true e. x is false
give a) Domain b) VA c) HA* d) OA* e) y-int f) x-int for each 2)...
give a) Domain b) VA c) HA* d) OA* e) y-int f) x-int for each 2) f(x) = 4 /3x - 9 3) g(x) = (x -1)(x + 4) /(x + 1)(x - 5) 4) h(x) = x ^2 + 4x/ x + 6 5) j(x) = x ^2 - 4 /(x + 2)(x - 3)
if A,B, and C are true statements and X,Y, and Z are false statements, determine which...
if A,B, and C are true statements and X,Y, and Z are false statements, determine which of the following are true : 1. ~[(B > Z) * ~ (A * Y)] 2. [A * (Z > C)] V ~ [(C > B) V ~(X * ~B)] 3. {[(A * B) > ~ (~C V ~Z)] * ( ~Y V Z)} * [(X > ~B) >A] 4. ~{[A > ~(Z > C)} > [(A * ~B) V (Y > ~Z]} *...
static int product(int x,int y){ if(x==0||y==0){//checking if x or y is 0 return 0;//if x or...
static int product(int x,int y){ if(x==0||y==0){//checking if x or y is 0 return 0;//if x or y is 0, then the return value and x*y will be zero. }else if(y<0&&x<0){ x=-x;//Changing the sign of x y=-y;//Changing the sign of y }else if(x>=1){ return (y+product(x-1,y)); } return (x+product(x,y-1)); } find the space complexity and the time complexity of the above algorithm.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT