0% found this document useful (0 votes)
7 views3 pages

Java Virtual Lab - 1

The document outlines a Java application for number conversion using an object-oriented approach. It includes a main class that allows users to convert numbers between decimal, binary, and hexadecimal formats. The application features a loop for user input and handles various conversion types through a separate NumberConverter class.

Uploaded by

harishheisenberg
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Java Virtual Lab - 1

The document outlines a Java application for number conversion using an object-oriented approach. It includes a main class that allows users to convert numbers between decimal, binary, and hexadecimal formats. The application features a loop for user input and handles various conversion types through a separate NumberConverter class.

Uploaded by

harishheisenberg
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

JAVA

VIRTUAL LAB ASSIGNMENT - 1

Apply an Object-oriented paradigm using java to develop a standalone application for Number
conversion in java. (may be for this we would introduce the basic data types) Level: Intermediate

import [Link];

public class NumberConverterApp {

public static void main(String[] args) {

Scanner scanner = new Scanner([Link]);

[Link]("Number Converter");

[Link]("================");

while (true) {

[Link]("\nEnter a number (0 to quit):");

int number = [Link]();

if (number == 0) {

[Link]("Exiting...");

break;

NumberConverter converter = new NumberConverter(number);

[Link]("\nChoose conversion type:");

[Link]("1. Decimal to Binary");

[Link]("2. Decimal to Hexadecimal");

[Link]("3. Binary to Decimal");


[Link]("4. Hexadecimal to Decimal");

int choice = [Link]();

switch (choice) {

case 1:

[Link](number + " in binary: " + [Link]());

break;

case 2:

[Link](number + " in hexadecimal: " + [Link]());

break;

case 3:

[Link](number + " in decimal: " + [Link]());

break;

case 4:

[Link](number + " in decimal: " + [Link]());

break;

default:

[Link]("Invalid choice. Please try again.");

break;

[Link]();

class NumberConverter {

private int number;

public NumberConverter(int number) {


[Link] = number;

public String decimalToBinary() {

return [Link](number);

public String decimalToHexadecimal() {

return [Link](number).toUpperCase();

public int binaryToDecimal() {

return [Link]([Link](number), 2);

public int hexadecimalToDecimal() {

return [Link]([Link](number), 16);

OUTPUT:

You might also like