I need to create a data type that implement the following interface ;
myNumber()
myNumber(int valueIn)
void printDecimal()
void printBinary()
String toString() //returns a string stating both the decimal and binary value
Solution
import java.util.*;
interface Myinterface
{
public void mynumber();
public void mynumber(int value);
public void printDecimal();
public void printbinary();
public void tostring();
}
class Sample implements Myinterface
{
public void mynumber()
{
int value=0;
System.out.println("implementation of mynumber()");
}
public void mynumber(int value)
{
int a=value;
System.out.println("implementation of mynumber(int value):"+a);
}
public void printDecimal()
{
int x=10;
System.out.println("Decimal number is:"+x);
}
public void printbinary()
{
int x=10;
int arr[] = new int[100];
int i=0;
while(x>0)
{
arr[i]=x%2;
i++;
x=x/2;
}
int count=i-1;
System.out.println("Binary value :");
for(i=count;i>=0;i--)
{
System.out.println(arr[i]);
}
}
public void tostring()
{
//toSting is used to return the string object value for the integer
int x=10;
int p=x;
int arr[] = new int[100];
int i=0;
while(x>0)
{
arr[i]=x%2;
i++;
x=x/2;
}
int count=i-1;
System.out.println("deimal is: "+Integer.toString(p)); //implementing toSting object for decimal
System.out.println("Binary value :");
for(i=count;i>=0;i--)
{
System.out.println(Integer.toString(arr[i]));
}
}
public static void main(String args[])
{
//defining objects for the interface and are called in the void main
Myinterface obj = new Sample();
obj.mynumber();
obj.mynumber(3);
obj.printDecimal();
obj.printbinary();
obj.tostring();
}
}

More Related Content

DOCX
What was ABC Inc's net capital spending in the year 2022- given their.docx
DOCX
What subatomic partichis ate located in the nuicleas of an atom- nesif.docx
DOCX
what type of decision making style do well in environments where there.docx
DOCX
What skills have you gained that would be applied to a computer techno.docx
DOCX
What pattern of inheritance does variant have with the RCH gene at the.docx
DOCX
What percentage of genetic divergence is used to define separate speci.docx
DOCX
What makes Y-C+I+G+NX an identity- Each symbol identifies a variable-.docx
DOCX
What motivates radical environmentalist groups like the Earth Liberati.docx
What was ABC Inc's net capital spending in the year 2022- given their.docx
What subatomic partichis ate located in the nuicleas of an atom- nesif.docx
what type of decision making style do well in environments where there.docx
What skills have you gained that would be applied to a computer techno.docx
What pattern of inheritance does variant have with the RCH gene at the.docx
What percentage of genetic divergence is used to define separate speci.docx
What makes Y-C+I+G+NX an identity- Each symbol identifies a variable-.docx
What motivates radical environmentalist groups like the Earth Liberati.docx

More from mckerliejonelle (20)

DOCX
WHAT IS YOUR CULTURAL INTELLIGENCE- Instructlons- To what extent does.docx
DOCX
What is true about the relative concentration of H+ and OH- in water-.docx
DOCX
What is the result (in binary) of adding the unsigned char binary numb.docx
DOCX
What is the resolution of a digital-to-analog converter (DAC)- It is t.docx
DOCX
What is the primary reason that Earth is cold at the poles and hot at.docx
DOCX
What is the main differentiating factor of an Advanced Alternative Pay.docx
DOCX
What is the main difterence between Al- ML- and OL- Select ones a- ML.docx
DOCX
What is the function of helper T cells in cell mediated immunity- Kill.docx
DOCX
What is the general FUNCTION of this tissue tvoe- -Pseberbunef that pe.docx
DOCX
What is the effect of cholesterol on membrane fluidity at physiologic.docx
DOCX
What is the default IP Prefix for a Class A- -16 124 130 18.docx
DOCX
What is the biggest animal in the world- What is the only active volca.docx
DOCX
What is performance- What factors affect performance- What are the dim.docx
DOCX
What is NOT true about protein migration during polyacrylamide gel ele.docx
DOCX
What is NOT true about primary protein structures- A- the core of the.docx
DOCX
What is NOT a mechanism of viral interaction between a receptor and th.docx
DOCX
What is its quartile range of the data- What is the lower bound- What.docx
DOCX
What is an action potential- what is its physiological significance-.docx
DOCX
What is a -mutant- and how is a mutant created- (Please include the SO.docx
DOCX
What information does UEFI-BIOS report about total memory installed an.docx
WHAT IS YOUR CULTURAL INTELLIGENCE- Instructlons- To what extent does.docx
What is true about the relative concentration of H+ and OH- in water-.docx
What is the result (in binary) of adding the unsigned char binary numb.docx
What is the resolution of a digital-to-analog converter (DAC)- It is t.docx
What is the primary reason that Earth is cold at the poles and hot at.docx
What is the main differentiating factor of an Advanced Alternative Pay.docx
What is the main difterence between Al- ML- and OL- Select ones a- ML.docx
What is the function of helper T cells in cell mediated immunity- Kill.docx
What is the general FUNCTION of this tissue tvoe- -Pseberbunef that pe.docx
What is the effect of cholesterol on membrane fluidity at physiologic.docx
What is the default IP Prefix for a Class A- -16 124 130 18.docx
What is the biggest animal in the world- What is the only active volca.docx
What is performance- What factors affect performance- What are the dim.docx
What is NOT true about protein migration during polyacrylamide gel ele.docx
What is NOT true about primary protein structures- A- the core of the.docx
What is NOT a mechanism of viral interaction between a receptor and th.docx
What is its quartile range of the data- What is the lower bound- What.docx
What is an action potential- what is its physiological significance-.docx
What is a -mutant- and how is a mutant created- (Please include the SO.docx
What information does UEFI-BIOS report about total memory installed an.docx

Recently uploaded (20)

PDF
Uderstanding digital marketing and marketing stratergie for engaging the digi...
PDF
Hazard Identification & Risk Assessment .pdf
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PPTX
Share_Module_2_Power_conflict_and_negotiation.pptx
PDF
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
My India Quiz Book_20210205121199924.pdf
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
PDF
IGGE1 Understanding the Self1234567891011
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PDF
International_Financial_Reporting_Standa.pdf
PDF
AI-driven educational solutions for real-life interventions in the Philippine...
PDF
Empowerment Technology for Senior High School Guide
PDF
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
Uderstanding digital marketing and marketing stratergie for engaging the digi...
Hazard Identification & Risk Assessment .pdf
A powerpoint presentation on the Revised K-10 Science Shaping Paper
Share_Module_2_Power_conflict_and_negotiation.pptx
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
Unit 4 Computer Architecture Multicore Processor.pptx
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
What if we spent less time fighting change, and more time building what’s rig...
My India Quiz Book_20210205121199924.pdf
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
IGGE1 Understanding the Self1234567891011
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
International_Financial_Reporting_Standa.pdf
AI-driven educational solutions for real-life interventions in the Philippine...
Empowerment Technology for Senior High School Guide
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf

I need to create a data type that implement the following interface -.docx

  • 1. I need to create a data type that implement the following interface ; myNumber() myNumber(int valueIn) void printDecimal() void printBinary() String toString() //returns a string stating both the decimal and binary value Solution import java.util.*; interface Myinterface { public void mynumber(); public void mynumber(int value); public void printDecimal(); public void printbinary(); public void tostring(); } class Sample implements Myinterface { public void mynumber() { int value=0; System.out.println("implementation of mynumber()"); } public void mynumber(int value) { int a=value; System.out.println("implementation of mynumber(int value):"+a); } public void printDecimal()
  • 2. { int x=10; System.out.println("Decimal number is:"+x); } public void printbinary() { int x=10; int arr[] = new int[100]; int i=0; while(x>0) { arr[i]=x%2; i++; x=x/2; } int count=i-1; System.out.println("Binary value :"); for(i=count;i>=0;i--) { System.out.println(arr[i]); } } public void tostring() { //toSting is used to return the string object value for the integer int x=10; int p=x; int arr[] = new int[100]; int i=0; while(x>0) { arr[i]=x%2; i++; x=x/2; } int count=i-1; System.out.println("deimal is: "+Integer.toString(p)); //implementing toSting object for decimal System.out.println("Binary value :"); for(i=count;i>=0;i--) { System.out.println(Integer.toString(arr[i])); } } public static void main(String args[]) {
  • 3. //defining objects for the interface and are called in the void main Myinterface obj = new Sample(); obj.mynumber(); obj.mynumber(3); obj.printDecimal(); obj.printbinary(); obj.tostring(); } }