Program To Add 2 Roman Numerals Together And Return The Results

Feb 26, 2014

Writing an program to add any 2 given Roman numerals together and return the results.

[I don't want to convert Roman numbers to decimal numbers & then add together, then convert in to Roman numerials ]

Is there any direct way to add roman numerials?

For example: I + I = II
III + I = IV

View Replies


ADVERTISEMENT

How To Convert Integer To Roman Numerals

Aug 20, 2014

I don't need the code , I just want to try on my own ....

View Replies View Related

How To Write Conversion Method From Roman Numerals To Arabic

Nov 8, 2014

I am a student taking a Java programming class. My assignment is to write a program that converts a roman numeral input as entered by a user and converting it to it's integer value (arabic number). These are the methods that I must have in it:

1. Write a method that takes input from the user and passes it to a conversion method.
2. Write a method that yields the numeric value of each of the letters (conversion method).
3. Write a method that outputs the number the user entered and the converted number.
4. Write a main method to test the 3 methods.

I have written the first method, at least I think. Here is what I did there:

public static String romanInput(String number) {
Scanner numberInput = new Scanner (System.in);
System.out.print("Enter a roman numeral: ");
String userInput = numberInput.next();
return userInput;
}

I returned the userInput and I think that is passing it to the conversion method? Now I am working on this conversion method and to be honest I don't know where to begin. I am told how to convert a string in my assignment by the professor. I am told:

- Look at the first two characters. If the first has a larger value than the second, then simply convert the first.
- Call the conversion method again for the substring starting with the second character.
-Add both values. If the first one has a smaller value than the second, compute the difference and add to it the conversion of the tail.

I am also told to use a single-dimensional array. But, I don't know what I am to use a single dimensional array for? So this is what I wrote so far for this method:

public static int numberConversion(int number) {

int romanConv = 0;
char[] romanNum = {'I', 'V', 'X', 'L', 'C', 'D', 'M'};
char[] arabicNum = {1, 5, 10, 50, 100, 500, 1000};
romanNum = arabicNum;
}

I have written a character array for the roman numerals, and then one for arabic numerals, then I set them equal to each other. I also declared an integer variable set to 0 because I think that is what I will be returning at the end of the method. Now I don't know where to start for the conversion algorithm here. I know this is what I have to do, but I don't know how to do it:

1. Add the numbers together if they are in decreasing value or are equal in value. For example: VI is read as 5 + 1 = 6 XVI is read as 10 + 5 + 1 = 16 XXXVIII is 10 + 10 + 10 + 5 + 1 + 1 + 1 = 38
2. Use subtraction if a number is less than the number that follows it. For example, I is less than V, so when I is in front of V, you subtract its value.
3. For example: IV is 5 1 = 4 IX is 10 1 = 9 XL is 50 10 = 40 MCM is 1,000 + (1,000 - 100) = 1,900

I can't use hashtables or enums because I haven't learned about that yet. I have a feeling I need to use a for loop. I know I haven't done any of the actual programming work but I don't know how to begin writing this conversion method.

View Replies View Related

Ask User To Enter Number From 1 To 10 And Program Will Display Roman Numeral

Feb 6, 2014

I am trying to write a program that asks the user to enter a number from 1 through 10 and then the program will display the roman numeral for that number.

I am also adding a error message in which i haven't yet because im still trying to figure out how to the program will do the roman numeral.'

I have used the if and else if. but when i input a number it just repeats the number back to me.

The program cimpiles but it doesn't do what i want. here is what i have so far. how can i get the program to display the roman numeral after the number is entered.

import javax.swing.JOptionPane;
public class Romannumeral
{
public static void main(String[] args)
{
double number;
 
[Code] .....

View Replies View Related

Java Program To Convert Integer To Roman Numbers And Vice Versa?

Aug 20, 2014

java program to convert integer to Roman numbers and vice versa?

View Replies View Related

Exam Results - Code Should Split Results In Stars In 4 Categories

Nov 30, 2014

I'm doing a program where a user enters in exam results for students. Once he's entered the code, the code should split the results in stars in 4 categories.

I am working with a while loop that prints out infinite results. What I want to do is, if the user enters 2 digits, say "12", it should output 1 "*".

If the user enters "21" and "22", it should output "**".

There are 4 categories of marks which are marked with ints range1, range2, range3 and range4, which are user enter digits. Part 1 of the code is to split the user entered digits into its correct ranges. the ranges are 0-29, 30-39, 40-69 and 70-100. I've done the part where when the user enters a digit, it goes into the correct variable. After that when the user enters a digit over 100, the enter results should show up as stars. For example

Enter number =

21
22
44
66
44
23
11
111 (the 111 is where the program breaks and moves on)

So it should then display

0-29 ****

30-39

40-69 ***

70-100

Whatever I'm trying, it displays an infinite amount of stars. If I try to use break, It only outputs a single star, no matter how many digits I enter

Here is the code

int mark = 0;
int range1 = 0, range2 = 0, range3 = 0, range4 = 0;
int count1 = 0, count2 = 0, count3 = 0, count4 = 0;
while (mark >=0 && mark <=100) {

[Code] .....

"The problem is with the while loop, the one above is something I was experimenting with "

View Replies View Related

Java Program For Retrieving Results From LDAP

Jan 23, 2014

I'm trying to run the following java program by using the instructions provided here URL....The program tries to connect to LDAP directory, searches for an objectGUID and returns sAMAccountName...But when I compile the java program I get 19 errors as given below.

/a1/utils/seek.java:2: cannot find symbol
symbol : class string
location : class seek
public static void main (string[] args) {

[code]....

View Replies View Related

Unable To Print Out Results Of Program That Calculate Number Of Seats

Nov 11, 2014

I'm trying to print out the results of a program that calculates the number of seats the parties will get in an election.I have to print the partial results and the national results.

I can print te number of seats per party in each constituency, but how can i sum all seats per party in each constituency and print the national results?I'm working with vectors, which I know it might not be the best option, but everything is working, except the fact that I can't loop throuhg the vector and retrieve the total sum per party.Like, adding the seats for labour party in Constituency A and B and C, etc, and print the sum. And do the same for conservative party.Is it possible, or doIhave to create a method in Parties class to solve the problem?

This is what I have now.

for (Parties p : h.geral) {
show += String.format("Constituency - %5s - %5s - %d%n",
p.getConstituency(), p.getParty(), p.getNum_seats());
}

View Replies View Related

Java Program Using Nested Loop To Compute / Display Average Of Test Results For Each Experiment

Apr 2, 2015

Four experiments are performed, each consisting of six tests. The number of test results for each experiment is entered by the user. Write a Java program using a nested loop to compute and display the average of the test results for each experiment.

You can run the program by entering the following test results:

Experiment 1 results:23.231.516.927.525.428.6
Experiment 2 results:34.845.227.936.833.439.4
Experiment 3 results:19.416.810.220.818.913.4
Experiment 4 results:36.939.549.245.142.750.6

View Replies View Related

Method Must Return Int Type - If Given Integer Is Strong Return A / If Not Return B

Sep 7, 2014

I want to use a method, which takes for example an int and also returns an integer. For example, if the the given integer is strong return a, if it is notstrong return b. How would you write that in a Code?

I want to use that in a more general way. I want to give a method mlong the value X of the type date and let it return an int. Type date consists of 3 int, one of them is the int month.

mlong should return an int depending on the X.moth. at the moment my code looks like this:

// File1:
public class date {
public int day;
public int month;
public int year;
}

// File 2:
public class monthlength {
public int mlong(date X) {
int t;
t = X.month;
if (t == 1 || t == 3 || t == 5 || t == 7 || t == 8 || t == 10 || t == 12)
{ return 31; }
if(t == 4 || t == 6 || t == 9 || t == 11)
{return 30;}
}
}

View Replies View Related

Argument Program - Missing Return Statement

Jan 22, 2015

I am trying to compile the arguments program but it is giving missing return statement error. how to correct the error message.

public class Arguments {
public static Void main ( String args[])
{
int count, i=0;
String sdata;

[code]...

View Replies View Related

Roman To Arabic Numbers Converter

Oct 5, 2014

I'm trying to do a program to convert roman numbers to arabic numbers. My problem is that I don't have the right to use Methods and Arrays. Only loops and if/else.

View Replies View Related

Roman To Arabic Converter Says Everything Equals 1

Mar 25, 2015

Im working on a roman numeral to arabic converter and all I had to do was fill out the conversion method romanToDecimal. But for some reason no matter what number I enter It always says my number is equal to one.

//Quiz 1 EC
import java.util.*;
class Roman {
private String romanNum;
private int decimalNum;
public Roman(){
romanNum = "I";
decimalNum = 1;

[code]....

View Replies View Related

Roman Numeral Conversion To Decimals

Jul 29, 2014

I have made a program that is supposed to convert roman numerals to decimals. It is NOT supposed to convert decimals to roman numerals. The only problem it seems there is with the program is that it only adds and does NOT subtract. This causes some roman numeral conversions to be flawed. What can I try to fix this. Keep in mind that the reason some methods exist is because the directions for the code say that I have to make it this way.

Instructions:

Write a program that converts a number entered in Roman numerals to decimal. Your program should consist of a class called Roman. An object of type Roman should be able to do the following:

1) Store the number as a Roman numeral.
2) Convert and store the number into decimal.
3) Print the number as a Roman numeral or decimal number as requested by the user. (Be sure to over-ride the toString function).
4) Your class must contain the method romanToDecimal to convert a Roman numeral into its equivalent decimal number.
5) Test your program using the following Roman numerals: MCXIV, CCCLIX, and MDCLXVI.

This is what I have so far. It compiles and there are no errors, but it does not subtract I from X, or I from V and so on. For example,CMXLVII should be 947, but the program outputs 1067.

import javax.swing.*;
import java.util.*;
public class Roman{
private String roman;
private int decimal;
public int romanToDecimal(String s)

[Code] .....

View Replies View Related

Arabic To Roman Numeral Converter

Sep 12, 2014

I got part of this converter built and running fine but now it's getting weird. Specifically I am getting to the part where I have to count above ten which means things like attaching Vs to Is and Xs and suchlike.

I know I have to use an .append someplace, I am just not certain how to go about it. I've been playing with it some, but this is honestly the biggest thing I've built so far that actually *ran* so I'm afraid to poke too many holes in it... where do I start? It's not like I can invent another return string and concatenate them. R is what I've got.

package hello;
public class RomansatHomans {
public static void main(String[] args) {
// input fed on this line loops through toRo and comes back as a String
// R
String R = toRo(23);
// int D = froRo("x");

[Code] ......

View Replies View Related

User Input Random Numbers Then Program Sort Them In Different Ways - Missing Return Statement

Apr 7, 2014

I have been assigned to write a program that has a user input random numbers then the program is to sort them in different ways. I have the coding for the different sorts but, I have an error saying that I am missing a return statement in the "Bubble" method. I am trying to return "arr[i]" in the "for loop" which gives me this error, and when I try to take the "return arr[i]" outside of the "for()" loop the error reads the it cannot locate variable "i".

import java.awt.* ;
import java.awt.event.*;
import javax.swing.*;
public class SwingSorts extends JFrame implements ActionListener
{
JRadioButton bubble;
JRadioButton selection;

[Code] .....

View Replies View Related

Convert Roman To Ordinary Conversion Without Using Any Predefined Methods

Feb 25, 2015

convert roman to ordinary conversion without using any predefine methods,where we are giving input thru command prompt

View Replies View Related

How To Return Values In Object Return Type Function (method)

Apr 2, 2014

How do i take input values for TwoDPoint (which are objects) and return it back in numerical values also print them.

When i create an object in main method and pass values to my function of return type TwoDPoint,it gives error:- found int,int need TwoDPoiint,TwoDPoint.

// Here is what i tried to do:

Created class TwoDPoint that contains two fields x, y which are of type int. Defined another class TestTwoDPoint, where a main method is defined.In the main method created two TwoDPoint objects.

Then I modified the class TestTwoDPoint and add another function to it. This function takes two TwoDPoints as input and returns the TwoDPoint that is farthest from the point (0,0).

Then I added another function to TestTwoDPoint. This function takes two TwoDPoints as input and returns a new TwoDPoint whose x value is the sum of x values of the input TwoDPoint's and whose y value is the sum of the y values of the input TwoDPoint's.

class TwoDPoint {
int x = 2;
int y = 4;
}
class TestTwoDPoint {
public static void main(String args[]) {
TwoDPoint obj1 = new TwoDPoint();
System.out.println(obj1.x);
System.out.println(obj1.y);

[Code] ....

View Replies View Related

Allow User To Enter Roman Numeral And Then Outputs Integer Number Value - While Loop

Feb 7, 2015

Write a program called RomanNumeralHelper that allows a user to enter a roman numeral and then outputs the integer number value. Use a Scanner to accept command line input from the user and continually ask for a roman numeral until the user enters Q (or q) to stop. Your solution should NOT use a switch statement.

Here is sample input / output:

Enter a roman numeral [Q | q to quit]: III
>> 3
Enter a roman numeral [Q | q to quit]: IV
>> 4
Enter a roman numeral [Q | q to quit]: V
>> 5
Enter a roman numeral [Q | q to quit]: Q
Good Bye!

This is what I have so far in my code, but I cant get what the user inputs when I want it to output the number.

import java.util.Scanner;
public class RomanNumber4
{
public static void main(String[] args) {
// obtain input from command window
Scanner input = new Scanner(System.in);
 
[Code] ....

View Replies View Related

ProcessBuilder No Results

Feb 23, 2014

try {
ProcessBuilder PB=new ProcessBuilder("find","/","-iname",""vim"");
PB.redirectOutput(Redirect.INHERIT);
PB.redirectError(Redirect.INHERIT);
PB.start();
}
catch (Exception e) {
e.printStackTrace();
}

It shows nothing. But when I tried

new ProcessBuilder("uname");

I gets a result ....

View Replies View Related

Why Terminal Not Returning Results To IDE

May 14, 2014

i am trying to run a command in terminal the code is below if i run the command in terminal it works fine however when i run it from netbeans with code below nothing gets printed. however if i run a different command such as (ip addr) it works fine?

public static void a() throws IOException{
ArrayList lister=new ArrayList();
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("ps -ef | grep firefox");// the command i am trying to run to get pid of application
InputStream stderr = proc.getInputStream();

[Code] ....

View Replies View Related

Printing Results From A Method

Apr 27, 2014

I need to print certain information from an arraylist depending on the arguments the method has. I'm trying to print the last 3 methods from the database class but nothing is printing and I don't know what the problem is.

package hw3;
import java.util.*;
public class Driver {
public static void main(String[] args){
/* Comments required
PersonFileReader pfr = new PersonFileReader("person.dat");
ArrayList<Person> testData = pfr.readData();
Database db = new Database(testData);
*/

[Code] .....

On the driver class I just print what the methods from the database class do.

View Replies View Related

If Given Integer Is Even Return 1 / If Not Even Return 0

Sep 7, 2014

I want to use a method, which takes for example an int and also returns an integer. For example, if the the given integer is even return 1, if it is not even return 0. How would you write that in a Code?

I want to use that in a more general way. I want to give a method mlong the value X of the type date and let it return an int. Type date consists of 3 int, one of them is the int month.

mlong should return an int depending on the X.moth.

At the moment my code looks like this:

// File1:

public class date {
public int day;
public int month;
public int year;
}

// File 2:

public class monthlength {
public int mlong(date X) {
int t;
t = X.month;
if (t == 1 || t == 3 || t == 5 || t == 7 || t == 8 || t == 10 || t == 12)
{ return 31; }
if(t == 4 || t == 6 || t == 9 || t == 11)
{return 30;}
}
}

View Replies View Related

JSF :: Jsf2 Search Results Not Displaying?

Apr 27, 2014

I develop a little app in javaee6 and jsf2. I have a search page which has a search form with 2 fields and a search button when i click search button the results should be displayed in searchresults page.

Here is my code,

search.xhtml page
<h:form id="searchform">
<h:inputText id="deptId" value="#{searchBean.departmentId}"></h:inputText>
<h:inputText id="deptName" value="#{searchBean.deparmentName}"></h:inputText>
<h:commandButton value="Click to Search" action="#{searchBean.searchEmployees}">

[code]...

Issue: searchresults page is is not displaying records though it fetched records from table I'm able to achieve this using search bean as session scope but i want to use the scope as Requestscope.

View Replies View Related

Swing/AWT/SWT :: Displaying Results In A Message Box?

May 8, 2014

how to display results in a PLAIN_MESSAGE. My program is converting hex to decimal and displaying the results. Here's the code:

package pkgfinal;
import javax.swing.JOptionPane;
import java.util.Scanner;
public class Final {
public static int Convert(String userInput, int base){
int running_sum = 0;

[code].....

View Replies View Related

Swing/AWT/SWT :: Using SetText To Display GUI Results

Feb 15, 2015

I have the code here to populate a GUI. I have the math and then print out and return a single number. I have tried to use setText in the class CalculateButtonHandler.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class RectangleProgram extends JFrame {
private JLabel lengthL, widthL, areaL, perimeterL, averageL;

[Code] ....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved