A Program That Stores Total Rainfall For Each Of 12 Months
Apr 29, 2015
Write a program that stores the total rainfall for each of the 12 months into an array of doubles. The program should have methods that return the following:
The total rainfall for the year
The average monthly rainfall
The month with the most rain
The month with the least rain
And the code:
double rain[] = new double [12];
double sum;
double average;
double most;
double least;
[code]....
I'm having a problem with figuring out how to show which month is the least and most.
View Replies
ADVERTISEMENT
Oct 26, 2014
"Create a project called RainFall and a class nameD RainFall. Write a program that stores the total rainfall for each of 12 months into an array of doubles. The program should display total rainfall for the year, the average monthly rainfall, the month with the most rain and the month with the least rain. When outputting the month with the most and least rain, output the name of the month. This is what I have so far.
Scanner keyboard = new Scanner(System.in);
double averageMonthly;
double mostRain;
double leastRain;
int months;
double monthlyRain = 0;
double totalRain = 0;
[Code] ....
View Replies
View Related
Feb 9, 2015
I was wondering how can I calculate total age in months and store it as variable? this is what I have so far:
*
* You will ask the user to provide their name (as a single word, assume first name here)
* You will ask the user their age in full years (no fraction or months)
* You will ask the user how many full months since their last birthday (again, whole numbers here).
*
* You will use this information to calculate the user's age in months and use that information to print out a greeting.
*/
import java.util.Scanner;
[code].....
View Replies
View Related
May 1, 2014
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
. What have i done wrong?
View Replies
View Related
Oct 1, 2014
Is my code right for this pseudocode:
<Declaration of the array for storing random integers and other necessary variables and / or constants. >
private int numbers;
private int max;
private int[] integer;
private Random generator;
public integer ( int n, int m )
[code]....
I need to create a program that draws random numbers and stores them in an array. How many numbers to be drawn is dependent on the array length, which is a parameter in the class constructor. (The entire array to be filled!) The program shall, however, just save the figures are not drawn already. (Ie, the array must contain only one instance of each numeral.) All figures drawn should be in the range of 100 to 1000, both limits included. These limits are defined as named constants. When all the numbers are generated and stored in the array, the program should find the largest, smallest and average value of the numbers in the array. In addition, it should find the value closest gjennomnstittetsverdien.
View Replies
View Related
Mar 29, 2015
//calculates rainfall quarterly program
import java.util.Scanner;
public class SophiaKeyProgram1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int numQuarter; //number of quarters in a year
double rainfall=0; //the amount of rain
[Code] ....
I have everything but the min and max numbers.
View Replies
View Related
Oct 5, 2014
i am very new to java programming what i am doing wrong here. Write a program that calculates how much an employee would earn over a period of time (in months), if, every month, the employee’ pay-per-hour rate is one dollar more than the month before (so if his starting perhour rate is 7.25, next month it will be 8.25, next month 9.25, and so on). The employee is going to work 20 hours per week, 4 weeks per month.
The program should input from the user and validate both number of months (which should be a positive integer larger than 0) and the pay-per-hour rate (which should be a floating-point number larger than $7.25 – the minimum federal wage pay-per-hour rate). For each one of these values; if the value is wrong, the program should repetitively ask for that value until the value entered is correct. The program should confirm/output the correct value.
/*
This program calculates how much as employee would earn if every month the employee pay per hour would increase by a dollar
*/
package nick.employee;
import java.util.Scanner;
public class nickemployee {
[Code]...
what i am doing wrong
View Replies
View Related
Mar 28, 2014
I cannot get the right output for my program. I need to get the total number of pennies in dollar amount for the output of Total Pay. This is my program. The directions are:
Write a program that calculates the amount a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, and continues to double each day. The program should then show the total pay at the end of the period. The output should be displayed in a dollar amount, not the number of pennies. Do not accept a number less than 1 for the number of days worked.
import java.util.Scanner;
import java.text.DecimalFormat;
public class PenniesForPay {
public static void main(String[] args) {
int numDays;
[Code] ....
totalSalary should be total number of pennies / 100....However its not picking up only day 30 of pennies which is 536,870,912 pennies and then dividing it?
View Replies
View Related
Oct 11, 2014
I'm struggling with inheritance in my assignment. The assignment states that I should use the calculatePrice() to calculate the total price and use another method to display the total. The I must overload the calculatePrice() and add a fee in the SpeedOrder() class.
My main class
package useorder;
import javax.swing.*;
public class UseOrder {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Order.display();
[Code] .....
The problem is mainly displaying the TotalPrice field and. I can't display TotalPrice if it's not static but if it's static I can't inherit it to the SpeedOrder class to assign the total in the overloaded calculateprice method. How can I display the total in my order class and use it in my SpeedOrder class?
View Replies
View Related
Sep 18, 2014
You have been given the job of writing a program to assist pilots who fly the Beechcraft Starship-‐‑1 executive aircraft.As with any airplane, it is essential that the pilot know the total weight of the loaded plane at takeoff and its center of gravity. If the plane weighs too much, it won'ʹt be able to lift off. If the center of gravity is outside the limits established for the plane, it might be impossible to control. Your task is to write a program that will determine the total weight and center of gravity of this plane
Inputs: The number of crew members, number of passengers, weight of the forward baggage compartment contents, aft baggage compartment contents weight, and the amount of fuel in gallons are to be accepted as INTEGER values in the order stated. Be sure the input values are within acceptable ranges
Outputs:You must echo the input values, annotated with their appropriate names,calculate and display the total weight, and the center of gravity.
View Replies
View Related
Oct 5, 2014
So I've attempted a for loop for this type of problem:If you receive $0.01 on the first day of your allowance, and the daily rate doubles each day after, calculate the total earnings for 30 days.
Output should be like:
Day ----- Daily allowance - Total allowance
1 -------- 0.01 -------------- 0.01
2 -------- 0.02 -------------- 0.03
3 -------- 0.04 -------------- 0.07
My code so far:
public class Allowance
{
public static void main (String[] args)
{
int day = 0;
double daily = 0.0;
double total = 0.1;
System.out.println("Day Daily Allowance Total Allowance");
for(day = 0; day <= 30; )
[code].....
View Replies
View Related
Sep 29, 2014
a project I am working on. Its a program that creates a singly linked list that stores names and high scores and prints them. For some reason it is printing an entry extra times. Also my remove function is not working properly
GameEntry class:
package project;
public class GameEntry implements Comparable<GameEntry> {
private String name;
private int score;
public GameEntry(String n, int s) {
name = n;
[Code]...
View Replies
View Related
Dec 2, 2014
Recently I have missed a few weeks of my class due to family emergencies. Because of this I have missed very important lectures. My professor has assigned me the following assignment:
Prices Write a Java program that specifies three one-dimensional arrays names price, amount, and total. Each array should be capable of holding 10 elements. Using a loop, input values for the price and amount arrays. The entries in the total array should be the product of the corresponding values in the price and amount arrays. After all the data have been entered, display the following output:
Total Price Amount
==== ==== ======
Under each column heading display the appropriate value.
I know how to display everything using printf, how to create the actual arrays and define the array size, but I am confused on how and what loop to use and how to construct it. This is what I have managed to write up so far:
import java.util.Scanner; // Imports the Scanner class
import java.text.DecimalFormat; // Imports the DecimalFormat class
public class Prices
{
public static void main(String [] args)
{
double[] price = new double[10];
double[] amount = new double[10];
double[] total = new double[10];
// Create a new Scanner object
Scanner keyboard = new Scanner(System.in);
} //End of main method
} // End of public class
View Replies
View Related
Oct 30, 2014
public class MonthsName
{
static String monthsName[];
public static void main(String[] args) {
String[] months = new String[13];
months[0] = null ;
[Code] .....
I keep getting 1 error that tells me this.
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at MonthsName.main(MonthsName.java:22)
Java Result: 1
Just before that netbeans couldn't find the main class. I was wondering if it netbeans or my code that's wrong.
View Replies
View Related
May 20, 2015
I have to create a method to find the current month with the input being a number of milliseconds using System.currentTimeMillis(). Now I was able to solve the problem with the following extremely cumbersome method:
public static int monthLeap(long ms) {
int result = 0;
int jan = 31, mar = 31, may = 31, jul = 31, aug = 31, oct = 31, dec = 31;
int apr = 30, jun = 30, sep = 30, nov = 30;
int feb = 28;
int febLeap = 29;
[Code] ....
I first go through a loop that goes through all the years and subtracting the number of days of a normal year or a leap year in milliseconds from the total milliseconds. At the end I should have a rest value of milliseconds that represents the amount of milliseconds that have passed already this year. Out of this number I then find the month we are currently in.
My problem is that the above method is way to large and I get a checkstyle warning: "NPath Complexity is 12,288 (max allowed is 80)".
I know that this can somehow be solved with a for loop iterating through the time and counting up months until there is no more month left. My problem though is the different lengths of the months. If each month was the same I could just subtract the amount of days in each month from the rest value.
(Since I already got it down to <= 12 months, I shouldnt bother with the extra days to find the month. Yet if I want to find the month when the date is the first or last day of the month it is important to be very precise) ....
View Replies
View Related
Mar 30, 2015
//calculates rainfall quarterly per year
import java.util.Scanner;
public class SophiaKeyProgram2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int numQuarter; //number of quarters in a year
double rainfall=0; //the amount of rain
[Code] ....
View Replies
View Related
May 29, 2014
import java.util.Scanner;
public class days
{ public EnumTest ()
{ this.day = weeks/months/years}
final int daysInMonth = 30; //constants
final int monthsInYear = 12;
final int daysInWeek = 7;
public void convert()
[Code] ....
after compiling it shows invalid method declaration ; return type required.
View Replies
View Related
Feb 14, 2015
How can I get the driest and the Wettest to show correctly with the Wettest took out the driest comes out fine
import java.util.Scanner;
public class Java {
public static Scanner key = new Scanner(System.in);
public static void main(String[] args)
{
// TODO Auto-generated method stub
double [] rainfall = {4.6,5.4,5.7,5.2,4.2,2.7,2.3,3.6,3.9,4.7,5.1,5.6};
double Wettest = 0.0 ;
double driest = 0.0;
[Code] .....
View Replies
View Related
Sep 10, 2014
exception in thread main java.lang.nullpointerexception code 45 and code 116
the lines are highlighted and no the code tags did not show up when I uploaded the file.
I typed '[code]' below:
Java Code: /**
This program demostrates rainfall for a year
*/
[Code].....
View Replies
View Related
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.
Enter your choice:
6
Enter the rainfall for day 6
View Replies
View Related
Feb 23, 2014
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;
[Code] ....
View Replies
View Related
Sep 26, 2014
The code is below and the problem I am having is the numbers after the decimal won't add together for the total I am teaching myself java through liang's 10th edition book and I took one of the sample programs further than what was shown. The one in the book only shows the tax amount I simply wanted to make it so that the purchase amount and the tax amount would add together
package javalearning;
import java.util.Scanner;
public class FindingTax {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Enter Purchase amount: ");
[code]....
View Replies
View Related
Jan 7, 2014
I have a for each loop that outputs the Mechanics salary for the first team in the arraylist, how can I add these figures together instead of having separate value for each?The code in my testing class to get the salary for mechanics:
Java Code: for (Mechanic str1: formula1.get(0)){
System.out.println(str1.getSalary());
} mh_sh_highlight_all('java');
How can I also get the salary for the driver 1 + 2 in the same team and add their salary to this? I have attaached an image showing the classes/fields created
View Replies
View Related
Jul 24, 2014
i have a row of int JTextfields and i want to get a running total of the sum of all boxes in the last total JTextfield, as the user types.I understand its an actionlistener but whats the best way of doing it. What the action to listen out for?
View Replies
View Related
Jun 5, 2014
what I'm missing to calculate the Total Payout that Payroll has given out to two employees. the professor states that we have to use "getTotalPayout" . It would have been easy to do "(employee1.getFinal() + employee2.getFinal())" but he use getTotalPayout.
public class Payroll
{
private String employeeId;
private int hourlyrate, hoursworked;
private int increaseHours = 10;
private double TotalPayout;
[code]....
View Replies
View Related
May 5, 2014
Is it possible to get the value(like numbers) from column of table and get sum or total?
View Replies
View Related