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


ADVERTISEMENT

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

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

Create A Program That Allows User To Enter A Day Using A Number

Oct 13, 2014

so I had to create a program that allows the user to enter a day using a number and then enter a year and after they did that it would create an entire calendar for that year ..so I have that but the only issue is I can not get the numbers to line up neatly.how to do the entire thing in loops, I tried a couple in here..what this would look like as loops instead of switches and cases and if else

import java.util.Scanner;
public class Calendar {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
 
[code]....

View Replies View Related

Averaging Grades Program - Take Input From User Until They Enter Negative Number

Feb 2, 2015

Ok so I have my program working for the most part. In this program I am supposed to take input from the user until they enter a negative number and that works, the problem is that it doesn't work if I enter a negative number on the first prompt. For example if I enter a 100 it would prompt me again and if I enter a negative number it would quit and give me the average, but if I enter a negative number the first time I am prompted the program just gives me an error. How do I fix that?

import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;
public class Application {
public static void main(String [] args){
Scanner input = new Scanner(System.in);
List<Integer> grades;

[Code] ....

View Replies View Related

User Enter 5 Digit Number And In Return List Each Number On Their Respective Lines

Sep 16, 2014

So I am currently writing my first assignment and have run into problems with my coding. The task was to have someone enter a 5 digit number and in return, I list each number on their respective lines. We also must create an error if a number other than 5 digits was entered. My problem is that when they enter a 1 or 2,3,4,6,7,8 digit number.. the error message occurs along with the rest of the messages (listing the numbers, etc). I want the program to end (or even re-ask to enter the numbers) if they incorrectly enter the data.

View Replies View Related

Java Lotto - Randomly Generate Five-digit Number And Prompts User To Enter Five-digit Number

Sep 25, 2014

1. Write a Java program that randomly generates a five-digit lottery number and prompts the user to enter a five-digit number. Each digit in the number is in the range between 0~9. The program should determine which prize the user wins according to the following rule:

- The user wins the first prize if the user input matches all five digits in the lottery number in exact order.
-The user wins the second prize if the user input matches any four digits in the lottery number in exact positions.
-The user wins the third prize if the user input matches any three digits in the lottery number in its exact position.
-The user wins the fourth prize if the user input matches any two digits in the lottery number in its exact position.

- The user wins the fifth prize if the user input matches any one digit in the lottery number in its exact position.here is my code. I have tried replacing the && statements with || and it always returns either case 1 or case default.

import java.util.Scanner;
import java.util.Random;
class Hw5 {
static int getPrize(int g1, int g2, int g3, int g4, int g5,
int u1, int u2, int u3, int u4, int u5) {

[code]...

View Replies View Related

ProductCatalog That Prompts User To Enter Number Of Products

Feb 11, 2015

Write a program called ProductCatalog that prompts the user to enter the number of products in the product catalog. The program should then prompt the user for the name and the price of each product in the product catalog. Once all of the products have been entered, the program should output the product information (name and price) of the most expensive product in the catalog. Your solution must use a for loop repetition structure and should use the Product class included in labfiles05.zip to keep track of the product with the highest price. Here is sample output:

Enter the number of products: 3
Enter the name of product 1: iPod
Enter the price of product 1: 158.99Enter the name of product 2: iPad
Enter the price of product 2: 518.99
Enter the name of product 3: iPadMini
Enter the price of product 3: 304.49
Most Expensive: Product [name=iPad, price=518.99]

Your solution should not use an array to keep track of all the product information entered.

I am having trouble with my code, with the For loop and then calling the methods from the Product class into the ProductCatalog. How should I approach this program.

Here is the Product program.

public class Product
{
private String name;
private double price;
public Product(String theName, double thePrice) {
name = theName;
price = thePrice;

[Code]...

Here is the ProductCatalog class where I call the methods from Product class. The For loop is what I am having trouble with as well.
 
import java.util.Scanner;
public class ProductCatalog
{
public static void main(String[] args) {
double number;
String product = " ";
double productCount = 0;

[Code]...

View Replies View Related

Getting User To Enter Integer (registration Number) Between 500 And 5000?

Jan 6, 2014

I am trying to get a user to enter an integer (registration number) between 500 and 5000. if it is below 500 and over 5000 the user should get a prompt "invalid number" and "non-numeric character". See my code below. it is not working when i enter invalid numbers.

import java.util.*;
public class Infomation{
public static void main(String args []) {
Scanner in = new Scanner(System.in);
System.out.print("Student Number:");
int sn=in.nextInt();

[Code] ....

View Replies View Related

Prompt User To Enter Value Of Their Savings For N Number Of Weeks

Oct 19, 2014

So I have this program where i have to prompt user to enter a the value of their savings for n number of weeks (quarters dimes nickels pennies) and the program outputs the total of savings an average of saving per week and an estimation of saving per year.

I managed to do the first step but the problem is that when they enter the value of their savings i don't know how to save the value of each(quarters dimes nickels and pennies) to make the calculations? Here is what i have so far

import java.util.Scanner;
 public class yearlySavings
{
 public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
int numberOfWeeks = 0; // initialize value of numberOfWeeks
 
[Code] .....

View Replies View Related

Allowing A User To Enter X Number Of People Into Array

Feb 5, 2014

I am starting a program that is dealing with arrays. My issue, allowing a user to enter 'x' number of people into an array. How do I first allow them to enter the size of an array, and then enter strings (list) into that array. In addition to this, I need to specify the number of boxes of cookies sold by each person and keep a tally of the number of people selling cookies in each category (e.g. 1-10, 11-20...etc). Instead of having a number 100000, I want the user to enter that size, 'x'.

import java.util.Scanner;
public class cookie {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int x = 100;
double saleCount[] = new double [x];
String[] girlScout = new String[100000];
 
[code]....

View Replies View Related

Prompts User To Enter 5 Test Scores And Their Names - Calculate And Display Average

Sep 24, 2014

Using Bluejay. Need code that prompts user to enter 5 test scores and their names. Calculate the average and display.

First initial and last name , 5 test scores, and average

View Replies View Related

Create Little Program Which Enter Number / Program Says Triangle Exist Or Not

Mar 16, 2014

i want create little program which enter the number, ant program says triangle exist or not. So code :

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

[code]...

So when i put first num like 1, next num like 2 and next num like 100 , program says Triangle exist.

View Replies View Related

User Enter A Number For Width And Length - Calculate Area And Perimeter

Apr 27, 2014

I am trying to make a program so that the user has to enter a number for the width and length and it will give the area and perimeter:

import java.util.* ;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class jframe extends JFrame {
private static final int WIDTH = 400;
private static final int HEIGHT = 300;

[Code] ....

It is giving me an error saying that the ExitButtonHandler and ebHandler do not have classes but I don't understand why.

View Replies View Related

GUI Program - Enter File Name And Display Text Area

Apr 14, 2014

I have to write a gui program where I can enter a file name and then it gets displayed in a text area when I click Open. Conceptually, I do not get this. I was thinking of appending the text file into a string or something, but I guess I'm confused on how it all works and how I can open the text file. Not asking for the code, but just a compass or something.

View Replies View Related

Write A Program Which Prompts User To Enter 4 Grades Between 0 And 100

Sep 2, 2014

I'm using Jgrasp and my prompt is asking me to write a program where the program prompts the user to enter 4 grades between 0 and 100. And you have to display the grades, and the program has to calculate the minimum grade, the maximum grade and the average.I'm just having problems with the max?

// Import Java Scanner.
import java.util.Scanner;
// Name Class.
public class Practice_4_1

[code]...

View Replies View Related

Program That Allows User To Enter Up To 10 Integer Grades Into Array

Apr 30, 2015

package question.pkg3;
import java.util.Scanner;
public class Question3 {
public static void main(String[] args) {
// TODO code application logic here
Scanner Luka=new Scanner(System.in);
double sum=0;double count=0;
int[] a=new int[10];

[code]....

I'm required to write a program that allows the user to enter up to 10 integer grades into an array. Stop the loop by typing in ‐1. Your main method should call an Average method that returns the average of the grades.I There's something wrong with my program , the count always stays 0 and the sum is always 1 less than the actual sum.Sample input and output :

Enter grade 1: 8
Enter grade 2: 9
Enter grade 3: 10
Enter grade 4: 5
Enter grade 5: 8
Enter grade 6: 9
Enter grade 7: -1
output

Average grade is 8.1666666667On line 13 I had count=count+1 ;

View Replies View Related

Program Will Require User To Enter Needed Values One After Another

Feb 21, 2015

I have to meet certain requirements for this one program, and one of them is as follow: The program will require the user to enter the needed values one after another. If any of the entered values is invalid, then the program will detect that and go into a loop requiring the user to enter a valid value. The program must keep track of the total number of invalid values that the user has entered.

I know how to set a restriction and create a loop to keep asking the same question until it is satisfactory ( in this case I used a while loop) but I am at loss on how I should keep track of the total number of invalid values. I know I can use an increment but how do I set a variable for when the program meets an wrong input from the user.

View Replies View Related

Program Keeps Prompting To Enter Correct Binary Number

Sep 10, 2014

I wrote a java program for my gui number converter app, the main purpose of this program is to make sure that user enters only a binary number for conversion from binary to other number formats. the problem is my program keeps prompting me to enter correct binary number, no matter if i enter correct binary number, it will still keep prompting me to enter correct number. Here is the code

import java.util.*;
public class test {
Scanner key = new Scanner(System.in);
String in;
int b;
public test()

[Code] .....

View Replies View Related

Program That Prompts The User To Enter Loan Amount And Years

Oct 21, 2014

so I had to make a program that prompts the user to enter a loan amount and the years for the loan and I have the conversions and everything my only issue is that when the chart pops up it just looks like a bunch of numbers and its missing the column headers

for example

Interest Rate Monthly Payment Total Payment

import java.util.Scanner; 
public class InterestRate { 
public static void main(String[] args) { 
double monthlypayment = 0; 
double totalpayment = 0; 
Scanner input = new Scanner(System.in);
System.out.println("Enter Loan Amount");

[Code]...

View Replies View Related

Quiz Program - Removing Enter Key Space After User Input

Oct 20, 2014

I am writing a short quiz program, and when the user inputs their answer they hit the enter key (the are int). But the last question on my quiz is asking the user to they want to repeat the quiz, but when I run the program, it won't allow me to input any information. I can briefly remember my lecturer saying something about entering in a code after each int the user inputs but I can't remember what it was.

Here is a snippet of my code:

//Question 3
do{
System.out.println("Question 3- What Hollywood actor did Mila Kunis have a baby with recently?");
System.out.println( question3 + ".Ashton Kutcher 2.Bradly Cooper 3.Leonardo Dicaperio h.Get a hint");
answer3 = stdIn.nextInt();
if(answer3 != question3)

[Code] ....

View Replies View Related

Test Program That Prompt User To Enter N And Displays N-by-b Matrix

Nov 25, 2014

I did a problem from my book which is "Write a method that displays an n-by-n matrix. Each element is 0 or 1, which is generate randomly. Write a test program that prompts the user to enter n and displays the n-by-b matrix".

So if a user would enter 3, and output could be 0 1 1
0 1 0
1 0 1

So here's my question... I was able to get the program to work in the way my book describes (by just writing the code in the class with the main), but for practice, I want to learn how to do this OOP-style...

I'm not sure how to do this, though, since the method is a void method, so I can't seem to call it within a toString method.

import java.util.Scanner;
public class MatrixTest {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter an int");
int number = input.nextInt();
MatrixClass mc = new MatrixClass(number);

[Code] .....

View Replies View Related

User Enter A File On Text Field And Display Its Hex Representation In Text Area

Apr 17, 2015

I'm supposed to write a GUI application letting the user enter a file on the text field and display its hex representation in a text area and vice versa.

Here's my code:

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package hexconvertor;
import java.util.*;
import java.io.*;
public class HexConvertor extends javax.swing.JFrame {

[Code] .....

It's not doing anything, I don't understand why.

View Replies View Related

Write A Program That Prompts User To Enter Two Positive Integers And Prints Their Sum

Jan 9, 2015

Write a program (TwoIntegers.java) that prompts the user to enter two positive integers and prints their sum (by addition), product (by multiplication), difference (by subtraction), quotient (by division), and remainder (by modulation). When the user enters 5 and 3, the output from your program should look exactly like the following:

Enter two positive integers: 5 3
The sum is 8.
The product is 15.
The difference is 2.
The quotient is 1.
The remainder is 2.

import java.util.Scanner;
public class TwoIntegers {
public static void main(String[] args) {
System.out.println("Enter two positive integers: ");
Scanner userInput = new Scanner("System.in");
int integer1 = userInput.nextInt();
int integer2 = userInput.nextInt();

[code]....

View Replies View Related

Program Is To Accept Number And Display New Number After Removing All Zeros

Dec 29, 2014

ex
Sample input:2340980
Sample Output:23498

this is the program i have tried but is dosent work

import java.util.*;
class zero
{
public static void main(String args[])
{

[Code]....

View Replies View Related







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