Converting Days Into Weeks / Months / Years - Invalid Method Declaration
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
ADVERTISEMENT
Feb 26, 2015
import java.util.HashSet;
import java.util.ArrayList;
public class Graph
{
double [] [] adj;
graph (double [] [] a)
{
adj= new double [a.length][a.length];
for (int i=0;i<a.length;i++)
for (int j=0;j<a.length;j++)
adj[i][j]=a[i][j];
}
C:UserscDesktopGraph.java:: error: invalid method declaration; return type required
graph (double [] [] a)
View Replies
View Related
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
Oct 26, 2014
Netbeans tells me it's an illegal start of expression during the initialisation of the interactWithUser method.
public class InvertLetter {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
/**
* String mit den Kleinbuchstaben.
*/
final String lowercase = "abcdefghijklmnopqrstuvwxyz";
[Code] ....
View Replies
View Related
Sep 3, 2014
I have one interface with three(more than one) method declaration. In the subclass that implements it I want to define only one method not all three not even blank definition of them.Is there any keyword or method for that. How to do it? Is it possible to do it? In GUI we use adapter classes to achieve it. What for console application?
View Replies
View Related
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
Jun 25, 2014
I am new to Java and trying to learn it.I wrote the following program but while creating the method nav i am getting errors.
Error:- void is an invalid type for the variable nav
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.util.*;
public class YahooHomepage {
private static WebDriver driver;
[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 24, 2014
write a program that reads in the year, month, and day of a couple's wedding date and compute thier next wedding anniversary after March 2, 2011.
TThis has to be input in a message dialog box also.
View Replies
View Related
Mar 14, 2014
Here's the small project... but how can I return the value (amount) in 10 years ? The way I did, the program just doesnt return anything...
import java.util.Scanner;
public class FutureValue
{
public static void main (String []args) {
double amount = 0;
double apr = 0;
System.out.println("How much money would you like to invest?");
[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
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
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
View Related
Apr 18, 2015
For this program I am calculating the annual costs of 5 office supplies (user input) each with a 5.7% inflation. The user inputs the cost of each object and my program must calculate and display the price of each object each year for 5 years. I already have this part. What I need is how to add the total costs of all 5 supplies per year and display each total cost. Here is the program:
import java.util.Scanner;//Using keyboard to enter data
//Start of Class
public class OfficeSupplyCalculator {
//Start of Method
public static void main(String args[]) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter the first item");
[Code] .....
At the moment all I get for the grand total loop is the same number showing up 5 times. I feel like the problem is how I am declaring the grandtotalperyear variable but I'm not sure what is 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
Jan 16, 2014
i have a JTable with data that contains a column with Years.
I want to get the user to be able to sort the data between a range of two years.
Example:
a user sets te filter so he/she can view all the data between the years 1990 and 2000.
I am a beginner in Java and don't know how to code such a filter.
I guess it will be something with an if/Else statement or a loop?
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 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
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
Nov 3, 2014
Compile errors. This is the code I have:
import java.util.Scanner;
import java.io.*;
public class LeapYear {
public static void main(String[] args) throws IOException {
int month1, day1, year1, month2, day2, year2;
[Code] ....
This is the compile error I'm getting:
The total number of days between the dates you entered are: 76882
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:909)
at java.util.Scanner.next(Scanner.java:1530)
at java.util.Scanner.nextInt(Scanner.java:2160)
at java.util.Scanner.nextInt(Scanner.java:2119)
at LeapYear.main(LeapYear.java:16)
View Replies
View Related
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
Dec 5, 2013
I know this has been covered before but none of the answers made sense to me. I'm hoping there is an easy way to do this. I have 2 user inputted strings that I have converted to dates and I just want the difference in days.
My code :
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.Scanner;
import java.text.ParseException;
public class DateTest {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws ParseException {
[Code] ....
Apparently I can't just subtract the dates like I would in VB.
View Replies
View Related
Apr 9, 2015
Let's say within a class I create a method that takes care of creating a java swing layout with labels, buttons etc.. then attach an action listener (inner class) for each button to change a respective label text. All I would need is that the action listener method can access and modify the label as needed.
Have read about static, protected, private, getters and setters but honestly bit confused about which structure should be adopted as a best practice. Global static protected variables for the labels along with private inner classes implementing ActionListeners believe will do the trick and will be able to access the labels but not convinced this is good practice.
View Replies
View Related
Apr 30, 2015
My Question is Suppose I am declaring an String array as
String[] a
or
String a[]
or
Comparable[] a
Will there be any performance or other advantage or disadvantage using these syntax?
View Replies
View Related
Feb 13, 2014
I tried this:
String[][]f = new String[1][1] {{"Harry"}{"Hairy"}};
I also tried this:
String[][]f = new String[1][1] {{"Harry"},{"Hairy"}};
but I get an error
View Replies
View Related
Apr 13, 2014
Ok say you have
public class MyClass {
private int x = 5;
Object myObject = new Object();
public MyClass(){
}
}
When would the myObject be created? Before or after the constructor? And does this mean you can't pass
this into the parameters of that object?
View Replies
View Related