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
ADVERTISEMENT
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Mar 28, 2015
I have a beginning Java Program I have been working on that creates a number guessing program where the computer guesses a number that the user is thinking of within a certain range. I so far have the program below, but need getting rid of a few kinks/ adding features.
-First, I need to set it up so that the user will be prompted and give a range. It should run and produce something like this:
Welcome to this first-ever mind-guessing program!
Please pick a range (higher than 1 and no larger than 50): 32
You will choose a number between 1 and 32... and I will try to guess it.
With each of my guess, you will tell me whether I am too high (h or H), too low (l or L), match (m or M), or you want to quit (q or Q). My objective is to find the number using as few guesses as possible.
-Second, the game is supposed to give up and restart after failing the five, guesses, but for some reason, after it fails the fifth time, it prompts a fifth guess once again instead, then restarts after- I need to prevent this, so that it should look something like this:
My fourth guess is 17: h
My guess is too high?
My fifth guess is 16: h
*** I am unlucky this round. I give up.
Let's play!
My first guess is 10:
etc..
import java.util.*;
import java.lang.Math;
public class numguessprac1 {
// Declaring variables
public static String input;
public static int quit;
public static int guess;
public static int wins;
[Code] ....
View Replies
View Related
Nov 4, 2014
I have been struggling with this program for weeks. This program is supposed to take a user's inputted odd number and then print out all prime numbers lower than that number.
public class PrimeNumber
{
Scanner scan = new Scanner(System.in);
int userNum;
String neg;
public void getUserNum()
[code]...
View Replies
View Related
May 5, 2014
trying to write a program that takes a user inputted number and converts it to a binary number.
Here's what I have:
package com.java2novice.algos;
import java.util.Scanner;
public class Converter {
static Scanner console = new Scanner(System.in);
public void printBinaryFormat(int number){
int binary = console.nextInt();
[Code]...
Bugs on:
Line 13
Line 17
Line 23
View Replies
View Related
Dec 3, 2014
My homework is asking me to write a program that prompts the user to enter a password and displays "valid password" if the rule is followed or "invalid password"
Sample
enter a string for password: wewewx
valid password
It's being graded on
Design of my GUI
Dialog box
User friendliness
Creativity
My current issues with the current code I have written is simply the password doesn't work unless it starts with 2 digits, the other order it displays as wrong. and I have no idea how to add a GUI.
import java.util.*;
import java.lang.String;
import java.lang.Character;
[code]....
View Replies
View Related
Mar 3, 2014
i need to create a program that asks the user for an array and then asks the user to fill in the slots of the array but i have to do it in a method
View Replies
View Related
Nov 14, 2014
So im trying to make a coin flip game in java. Im relatively new to the language and the only other language i knew was javascript so im still learning. Ive already made one before using just one class and putting all the code inside, but im now trying to do it with methods since im trying to learn them. The basic idea of the game is that the user picks how many coins they'd like to flip, they pick heads or tails, then the computer flips the coins and calculates if there was more heads or tails to tell the user if they won or not. Im not quite complete with the program as you can see but ive already run itno an error. I was just doing some tests on the code i already have and i found that when i call the method settingUpCoin in my main class the program terminates. So basically, when i run it, it executes userImp right, transform right, but then it dosent let you enter a value for howManyCoins and terminates before you get to settingUpCoin.
(Notes: this was all done in eclipse luna build or the java ide. The class files are all separate in the actual thing i just put them together here to demonstrate my code.
import java.io.IOException;
public class Coin
{
double myCoin;
int numOfCoins;
int counter;
double arrayOfCoins[] = { };
[code]....
View Replies
View Related