Rainfall Analysis For The Number Of Days According To User Input
Feb 24, 2015
I am assigned with a project that will as the user for the amount of days they would like data entered, then loop asking them for these numbers. once it reaches the entered amount of days it will display a menu for which the user can enter the number they want on the list and it will display the data. the menu has 6 items. Total, Average, Determine if its a Drought, Flood or normal rainfall, highest of data entered, lowest of data entered, and 6 is to quit the program.
So far i have total and average working properly. Still looking at how to display drought, flood, and normal.
Main problems, i cannot get highest and lowest to display correct data.
Also when entering 6, or an invalid menu choice, neither "goodbye" or "invalid choice, choose again" gets printed. Rather the loop for entering data continues.
import java.util.Scanner;
public class RainAnalysis {
/*
* Project 1 This program will analyze the rainfall for the number of days a user inputs.
*/
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int numOfDays = 0;
double rainfallAmount = 0.0;
[Code] ....
Here is a sample output to show what happens when i put in 6 after the menu is displayed.
also i noticed that it does not say the correct day when displaying the lowest and highest rainfall. this is because i put count, i did not know what else to put in order to get the correct day.
how many days do you want to monitor rainfall?5
Enter the rainfall for day 1.01
Enter the rainfall for day 2.1
Enter the rainfall for day 36
Enter the rainfall for day 43
Enter the rainfall for day 51
Rainfall Data Display Menu:
1 - Display total rainfall.
2 - Display rain average for the period.
3 - Display if drought, flood, or normal conditions.
4 - Display the day and amount of the highest rainfall.
5 - Display the day and amount of the lowest rainfall.
6 - Quit the program.
Enter your choice:
4
Day5 has the highest rainfall with 6.0 inches.
Rainfall Data Display Menu:
1 - Display total rainfall.
2 - Display rain average for the period.
3 - Display if drought, flood, or normal conditions.
4 - Display the day and amount of the highest rainfall.
5 - Display the day and amount of the lowest rainfall.
6 - Quit the program.
Enter your choice:
5
Day5 has the lowest rainfall with 0.1 inches.
Rainfall Data Display Menu:
1 - Display total rainfall.
2 - Display rain average for the period.
3 - Display if drought, flood, or normal conditions.
4 - Display the day and amount of the highest rainfall.
5 - Display the day and amount of the lowest rainfall.
6 - Quit the program.
I've been working on a question using parallel arrays where the user inputs an integer 1-12 and the output will be the name of the month and the number of days in that month. This is what I have so far
import java.util.*; public class DaysMonth { public static void main (String args[]) { Scanner keyIn = new Scanner(System.in); int[] days = new int[]{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
I have written program for rainfall that will store and give total, average, least and most. The program stores the input of rainfall for each month. However at the end it suppose to print out the month with the least and most rainfall. I am getting this on the print for
The month with the most rainfall: [Ljava.lang.String;@79a7bd3b
and for
The month with the least rainfall: [D@7378aae2[Ljava.lang.String;@79a7bd3b
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;
I'm trying to write a program that computes the number of days between two dates. How I can achieve this. I'm quite sure I'm supposed to use the Calendar class.
When input validation for the first months rainfall is non-negative, this results in correct average rainfall.
When input validation is used for the first months rainfall I'm prompted to input a positive number, which is 2.
When asked to input rainfall, in inches, for each month, I begin with input -3, I am again prompted to re-enter a positive, I enter 3. What happens is, whichever positive integer I input after I had entered a negative for the first months rainfall, the average would be off by the positive number inputted.
package averagerainfall; import java.util.Scanner; public class AverageRainfall { public static void main(String[] args) { int maxYears; int totalMonths;
String temp = "hi this sf hello is new what is this"; String[] cmd = temp.split("s"); int num = cmd.length; System.out.println("number of words are: "+num); mh_sh_highlight_all('java');
However, when i get the input from user , i didnt get the expected result:
Java Code:
System.out.println("Enter the input string to count the words: "); String[] cmd = new Scanner(System.in).next().trim().split("s"); int num = cmd.length; System.out.println("number of words are: "+num); mh_sh_highlight_all('java');
Any better way to write a program that takes a user number input and the program determines whether or not the number is prime or not. It was suppose to be a number between 0 and 8,000,000.
import java.util.Scanner; public class prime1 { public static void main(String args [])
Write a program that detects Fibonacci numbers. Prompt the user to input a positive integer. Upon input, the program will determine if the number is either a Fibonacci number or not. If a Fibonacci number, then the order of the number in the sequence must be output. If not a Fibonacci number, then the Fibonacci numbers above and below it (including their order in the sequence) must be output. Once it finishes, the program will prompt the user for a new number. The program will exit if the user enters a string (such as “quit”) instead of an integer. Use the sample output file, fib-seq-det.txt, to view a sample session
This is my project, I wrote a programs that tells you if the input number is a fibonacci number or not. For some reason it only works for some Fibonacci numbers but not all of them.
import java.util.Scanner; public class While { public static void main(String[] args) { System.out.println("Welcome to the Fibonacci Sequence Detector "); Scanner in = new Scanner(System.in); System.out.print("Please input a number for analysis: "); int input = in.nextInt();
import java.util.*; public class SumOfAllEvens { public static void main (String[] args) { Scanner s = new Scanner (System.in); //for (int i=1; i<4; i++){ int usernumber;
[code]....
I'm supposed to use a for loop that runs until it reaches the number input by the user, but I'm not sure how to tell the program to add the user's number along with all of the even numbers in between the user input and 2.
/* * To change this template, choose Tools | Templates * and open the template in the editor. */
package firstgui; import javax.swing.*; import java.awt.event.*; public class TicTacToe {
[Code] ......
Program is 10x10 board, I need to check if the user's input is a duplicate of any number in that same column, but I can't figure it out. When I tried it, it always check the same box. For example, if I entered 4 in [1][1] (going by 10x10 grid), it automatically checks right after I entered that [1][1] is the same as my input and erases it. My professor wants me to check it with the "CheckWinner" method.
I tried the following when someone told me to pass the reference of the JButton being clicked to ignore it.
I need the user to be able to input a number, and for the program to assign this value to an 'int' variable. I know how to do this with a 'string' variable:
Java Code:
String options = JOptionPane.showInputDialog(null, "In your decision, how many options do you have? " +" (NOTE: The maximum number of options = 5, and you must enter your answer as a numeral.)"); mh_sh_highlight_all('java');
But I need to know how to do this with an 'int' variable.
I have returned with yet another problem but I think this one might be a bit easier to fix.
So the whole MO of this program is to take user input, and display the sum of the digits of the number they entered. I am supposed to do this by utilizing methods. So far this is what I have and when I compile it tells me that it "cannot find symbol", which I don't understand as I define what "m" is in the for loop. The other error is that it says:
"Exercise6_2.java:22: error: incompatible types: possible lossy conversion from long to int return result; ^
I don't understand why it's giving me this error nor do I understand why result seems to inherently be an int. (Also the public static int sumDigits(long n) method was given to me by the book so that is what I am supposed to use).
import java.util.Scanner; public class Exercise6_2 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter a integer"); long n = input.nextLong();
I'm attempting to create a program that employs a method to count the number of 7s a user puts as an input into the program. I'm just getting started, but I'm getting an error when I try to implement a main method that says "Illegal start of expression"
What adjustments could I make to eliminate this error message?
// Add a main method here. public static void main(String[] args) { //Error occurs here public static int countSevens(int n) { // 0. Clean-up. Get rid of any minus signs as that is not a digit. n = Math.abs(n);
Using JOptionPane,ask for 10 numbers from the user.Use an array to store the values of these 10 numbers.Output on the screen the number with the greatest value.
I am trying to write a code that allows a user to input the number of stones in a basket, then put the stones in my pocket, after the stones are in my pocket, the stones must be taken out, one by one, and thrown in a pond. I get stuck at this part because my for statement has to subtract the number of stones in my pocket (one at a time) and add a stone to the pond (one by one) at the same time.I can get the pond stones to increase until the max amount of stones with the following:
how to reduce one and add to other. Is it possible to do this in one for statement? I tried to put stones-- in place of the question mark, but that is not working.
Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits.
Now I have a code for spacing out the integers, and I have a separate code for adding the digits. But I am not sure how to merge them together. Both of them work independently
Spacing code: import java.util.*; public class SumoftheIntegers { static Scanner console=new Scanner(System.in); public static void main(String []args) { int num1, test, rem; int counter = 0;
[Code]...
Now the sum of the integers code:
import java.util.Scanner; public class sum { public static void main(String[] args) { // Create a Scanner Scanner input = new Scanner(System.in); // Enter amount System.out.print("Enter an integer: "); int integer = input.nextInt();
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;
The problem occurs after the user inputs the guess.... it either runs the for loop if guess = numtoguess and reveals the answer even if the user input is wrong.... or it always runs the first if statement in the while loop if guess!= to numtoguess... heres the code
public static void main(String[] args) { String[] Answers = {"yes", "Yes", "No", "no"}; String Name = JOptionPane.showInputDialog(null, "Hello, What is your name?","Random Game", JOptionPane.QUESTION_MESSAGE); String UI = JOptionPane.showInputDialog(null, Name + " do you want to play a game", "Random Game", JOptionPane.QUESTION_MESSAGE);
Write a program that prompts the user for an input number and checks to see if that input number is greater than zero. If the input number is greater than 0, the program does a multiplication of all the numbers up to the input number starting with the input number. For example if the user inputs the number 9, then the program displays the following sum:
9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1 = 362880
That's the question I'm getting and so far all I've got is
import java.util.Scanner; public class Lab4Q3 { public static void main (String[] args) { int keyboard;
How to get used to program control statements. This is an attempt to write a program that returns the number of days between two dates. Sadly, it give incorrect values.
public class DaysBetweenDates { public static boolean isLeapyear(int year) {//This method will determine if a year is a leap year or not boolean isTrue=false; if(year%4==0 && year%100!=0) isTrue=true; else if(year%400==0) isTrue=true; return isTrue;
So basically we have this question to do : Write a method dayNumber that determines the number of days in a year up to and including the current day. The method should have three int parameters: year, month, and day. If the value of any parameter is invalid, the method should print a warning message and return the value zero. The table gives some examples of the action of the method. Accept any non-negative year as being valid. You may want to assume the existence of a method numberOfDays that returns the number of days in a given month of a given year. And you should have a method call isLeapYear, if the user enter a year that is a leap year.
This is what I did so far:
class dayMonthYear { public static void main(String[] args) { System.out.println("Enter a year"); int year = In.getInt(); System.out.println("Enter the month for '1' to be January - '12' to be december");
[Code] ....
It works and compiles but my problem is that: let say I enter "12" for December and December has 31 days, so what my program will do since December has 31 days, it thinks each month has 31 days and add them up which will give me 372 when it's suppose to give me 365. How do I make it that it won't do that and that it will work if the year is a leap year too.
I am writing a code in which a user inputs data as a string and that data must be verified as a valid number. A valid number is anything from 0-100. Then all valid numbers are converted into double numbers.
I am having trouble in how to write the validation part of the code.
Is it suppose to be an if, else statement? And if so how is it suppose to be validated?
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.
and here is my code. I cant get it to print the right statements.
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 for determining the prize comparing (g1, g2, g3, g4, g5) to (u1, u2, u3, u4, u5) if (u1 == g1 && u2 == g2 && u3 == g3 && u4 == g4 && u5 == g5)
Goal is to: Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits.
First I don't know where I made mistakes here, and the only error it finds right now is that str2 was not initialized and I cannot figure out where/when to initialize it.
import javax.swing.JOptionPane; public class DigitsAndSum { public static void main (String[] args) { String str1; String str2; int int1 = 0; int int2 = 0;
I need to write a simple program that reads an amount of minutes and displays the approximate number of years and days for the minutes. For simplicity, assume a year has 365 days and the resulting amount of days is a whole number.