Program To Determine Number Of Days In A Year Up To And Including The Current Day

Nov 23, 2014

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.

View Replies


ADVERTISEMENT

Program That Returns Number Of Days Between Two Dates - Incorrect Values

Mar 24, 2014

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;

[Code] ....

View Replies View Related

Calendar (Days Enum) - Determine If Day Is Weekday Or Weekend

Oct 17, 2014

The instructions state: Create the following values for the enum (and make sure that they are spelled correctly, case matters):

a. SUN
b. MON
c. TUE
d. WED
e. THU
f. FRI
g. SAT

Create a private constructor for the Day enum that takes a boolean value. This boolean will determine if the day is a weekday (if it is true) or weekend (if it is false). Document it with a JavaDoc. This value will need to be stored as part of the object. Update the enum values so that they correctly call the constructor. Saturday and Sunday are the only days considered part of the weekend.

Implement the following methods:
a. boolean isWeekday()
i. Returns true if the day is a weekday.

b. Boolean isWeekend()
i. Returns true if the day is a weekend. (How could you determine that?)

c. String toString()
i. Returns the full name of the day for the enum value (i.e. Monday or Tuesday). Use either a set of nested ifs or a switch statement.

Hint: You will want to compare the this reference against the possible values in the enum.

View Replies View Related

Number Of Days Between Dates

Jun 29, 2011

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.

View Replies View Related

Find Day Number Of The Year?

Apr 15, 2014

figuring out the logic to print the day number of the year. The directions for my homework are: Write a program that prints the day number of the year, given the date is in the form: month day year. For example, if the input is 1 1 05, the day number is 1; if the input is 12 25 05, the day number is 359. The program should check for a leap year . I have a basic outline of the program but i am having trouble with figuring out the logic to display the day number of the year given the date. This is what i have so far

import javax.swing.JOptionPane;
 public class Practice4 {
public static void main(String[] args){
String monthStr;
String dayStr;
int inputMonth;

[code]....

View Replies View Related

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.

Enter your choice:
6
Enter the rainfall for day 6

View Replies View Related

How Does Program Know To Calculate For Only One Year

Mar 26, 2015

how does the program know to calculate for only one year?

public class Interest2 {
public static void main(String[] args) {
double principal; // The value of the investment.
double rate; // The annual interest rate.
double interest; // The interest earned during the year.

[code]....

View Replies View Related

Program To Check If A Year Is Leap

Feb 5, 2015

I am doing an assignment for my class and I wish to know if there is anything I did wrong or what would make it easier to read, the assignment is to make a program to check if a year (the user provides the year) is a leap year.

import java.util.*;
public class Assignment1
{
public static void main(String[] args) {
int year;
System.out.println("Please enter a year.");
 
[Code] .....

View Replies View Related

For Loop Program - Calculate Total Earnings For 30 Days

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

Assign Current Null Value To Current Date?

Mar 6, 2014

How can i assign current  null value to current date, I only what to assign this if the current value coming from database is null otherwise i must use value from database

public static String getDate(Calendar cal){
        return "" + cal.get(Calendar.DATE) +"/" +
                (cal.get(Calendar.MONTH)+1) + "/" + cal.get(Calendar.YEAR);
    }
try {

[Code] .....

View Replies View Related

Determine If User Input Is Fibonacci Number Or Not

Oct 20, 2014

Part A: While Loop Program

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();

[Code] ....

View Replies View Related

Read Amount Of Minutes / Displays Approximate Number Of Years / Days For Minutes

Sep 7, 2014

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.

View Replies View Related

Parallel Arrays - User Input Integer 1-12 / Output Name Of Month And Number Of Days In That Month

May 11, 2015

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};

[Code] ....

After I enter the user int it just ends.

View Replies View Related

How To Detect Current Memory Free And Used In Java Program

Aug 29, 2014

I would like to know how much of memory is free and used my java program.I have used Runtime.totalMemory and freeMemory() functions. However, how come used memory is so different than java.exe process show in windows task manager?

View Replies View Related

Simple For Loop - Determine Factorial Of A Number Entered By User

Jun 28, 2014

I'm trying to learn Java and my current project is to write a short program to determine the factorial of a number entered by the user. I haven't looked. There may be a method that will do it, but I want to use a for loop specifically.

What I have compiles just fine. I'm actually pretty thrilled just with that. Here is what I have:

class factorial {
public static void main( String[] args) {
Scanner scan = new Scanner(System.in );
int num;
int product = 1;

[Code] ....

View Replies View Related

Determine Number Of Subsets Of K Items Chosen From A Set Of N Distinct Objects

Sep 22, 2014

Part of my program requires writing a function that determines the number of subsets of k items that can be chosen from a set of n distinct objects ("n choose k" or n!/((n-k)! n!)). The only errors I am getting are from the first line of the function:

// n choose k: distinct subsets of k items chosen from n items
public static int choose (int n, int k) {
if (k <= 0)
return 1;
else
return choose(n--, k--) * (n/k);
}

View Replies View Related

Arrays And Number Generator - Determine And Print Largest And Smallest Values

Dec 4, 2014

/*
Purpose: To write the methods and the rest program. The program should fill a 4 X 4 2 dimensional array with random numbers between 100 and 200. The program should then determine and print the largest and smallest values within the array using two Methods Largest and Smallest. The program should then determine and print the number of values within the array that are even using a function called Even. The program should also enter a loop that will only terminate when the user inputs a -1 as a choice. The loop should continue to ask the user to guess a number that was randomly generated. The program should call the Findit function to determine if the number was in the array. The program should print out the values in the array when the user selects a -1 and then terminate.
*/

import java.util.Scanner;
import java.util.Random;
public class LNFI_2DArray
{
public static void main(String[] args) {
int guess;
int[] array = new int[4];

[Code] ....

I just had this code working, then all of a sudden i was hit with a 'keyboard leak' error code.

View Replies View Related

Java GUI ActionListener - Determine Factors Of Input Placed At Number Text Field

Oct 12, 2014

I just started Java a few days ago and I'm having trouble with ActionListener..

Here are my codes so far , i'm having trouble with the

btnDetermineAction10686696_842067395825457_2521361553839739125_n.jpg:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
 
public class NumberAnalyzer extends JFrame{
private JButton btnDetermine, btnClear;
private JTextField txtNumber, txtFactors, txtPrime;
private JLabel lblNumber, lblFactors, lblPrime;
private JPanel pnlNumber, pnlNumber1,

[Code] ....

The output should be the one in the picture:

Input is placed at the NUMBER text field.

Identify its factors, write it at FACTORS text field.

Determine if it is prime. If prime, output at PRIME text field is “Yes”, “No” otherwise.

View Replies View Related

Difference In Days Between Two Days?

Feb 19, 2014

How to find out number of days elapsed between two days. I know that if hours elapsed between two days is above 24, its the next day. But this is not always the case for e.g.

02-19-2014 17:30:00 PM and 02-20-1014 13:15:00 PM

In the above case hour difference is <24.

View Replies View Related

Allowing User To Determine When A Program Is Stopped?

Nov 8, 2014

I was tasked with building a program that counts vowels in a phrase or word. I have this working properly, but the problem arises in the next situation. Here is my code:
 
Scanner userInput = new Scanner(System.in);
int userDecision;
String Choice;
String Phrase;
int vowelCount = 0;
System.out.println(" This program will count the number of vowels in it.

[Code] ....

As you can see, I used a 'for' statement to declare how long the program should run. However, I need the user to be able to say when it ends. For example, at the end of the program it must say "There are ______ number of vowels in your word. Please press '1' to run the program again, or any other number to exit."

I understand a do-while loop is needed here, but every time I try and create an adequate loop with no logic errors, I either break my existing code, or the program does not work correctly.

Basically, my question is, what is the best way to perform this task? Is a do-while loop necessary, or is there a better way?

View Replies View Related

Write A Program To Determine Sum Of Following Harmonic Series For A Given Value Of N

May 9, 2014

write a program to determine the sum of the following harmonic series for a given value of n:1+1/2+1/3+.............................+1/n the value of n should be given interactively through the keyboard.

View Replies View Related

Program That Will Determine Total Weight And Center Of Gravity

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

How To Create JavaScript To Find Current Month And Current Day Of Month

Mar 17, 2015

I want to be able to use the current date to solve a math problem, specifically as follows:If today is March 17, the math problem of the day should be:

(Month times Day of Month) + 99 = Answer of the Day

(3 x 17) + 99 = 150

How can I create a java script to find the current month and the current day of month, multiple those two together, then add 99 and display the answer as a result.

View Replies View Related

Program To Determine Max Amount Of Units Sold And Display It In Dialog Box

Feb 9, 2014

I am trying to write a program that basically determines the max amount of units sold and displays it in a dialog box. Also, the program will display the winning sales associate out of 10. I have wrote the program successfully so far and I can see the maximum number of units sold displayed in the dialog box, but I cannot seem to link the winning sales person.

Here is the code I have typed so far.

//Program to find maximum of three number

import javax.swing.JOptionPane;
import java.util.Scanner;
public class Sales
{
public static void main (String[] args)
{
//Declare variables
int num1, num2, num3, num4, num5, num6, num7, num8, num9, num10;
int large;
int winner;

[Code] ......

View Replies View Related

Create 2D Array Out Of CSV File And Find Number Of Elements To Determine Array Size

Mar 24, 2015

I am taking the Class Algorithms and Datastructures and got an assignment for Lab that really throws me off. The goal is to create an Array out of a given CSV file, implement several Methods that get the size of array, etc.

I am still stuck in the first part where the CSV has to be imported into the Array. My problem is that I need a mechanism that figures out the needed size for the Array, creates the array, and only then transfers the data from the CSV.

The list consists of the following wifi related values:

MAC-Adress, SSID, Timestamp, Signalstrength.

These are on the list, separated by comma. The Columns are each of these, and the rows are the four types of values making up the information on a certain wifi network.

The catch is, we are not allowed to use any of the following:

java.util.ArrayList
java.util.Arrays
and any class out of java.util.Collection.

So far I used the BufferedReader to read in the file and tried to implement the array, but I get an arrayindexoutofboundsexception.

Below is my Code (Its still an active construction zone):

public class WhatsThere {
public WhatsThere(String wifiscan) throws IOException {
}
public static void main(String[] args) throws IOException {
// WhatsThere Liste = new WhatsThere(String wifiscan);
String[][] arrayListe = new String[0][0];

[Code] ....

View Replies View Related

String Including Parameter

Mar 25, 2015

I am taking a parameter of type String and checking if either the city or state contains the "keyword", whatever it may be. I am using an arrayList of 10,000 customers and adding any customer that lives in a city or state that contains the keyword to a new arrayList and then returning that arrayList. I thought my solution was correct, but when using the JUnitTest provided, it is not quite passing the test. My solution is as follows.

Java Code:

public ArrayList <Customer> getMailingList(String keyword){
ArrayList <Customer> key = new ArrayList<Customer>();
keyword = keyword.toLowerCase();
for(Customer c : data){
if(c.getState().contains(keyword) || c.getCity().contains(keyword)){
key.add(c);
}
}
return key;
} mh_sh_highlight_all('java');

View Replies View Related







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