Implement Dialog Class For Leap Year

Apr 1, 2015

This assignment uses the following description to implement a Dialog class for the Leap Year Problem. We need to decompose this problem into 2 classes:

1.The Date.java class: is a public class that represents a date composed of a month , day, and a year. So you need to declare month, day, and year as integers. Date has 1 constructor and 4 methods. Write the constructor for Date which has 3 parameters: int m, int d, int y ; (As an example of a constructor with 2 parameters for example chapter 3 page 152 code listing 3-13 has a perfect example for you to use which is the BankAccount.java.) and the 4 methods:

"dayIs()" which returns a day. It has no parameter.
"monthIs()" which returns a month. It has no parameter.
"yearIs()" which returns a year. It has not parameter.
"isLeapYear()" which returns a boolean value.

"isLeapYear()" has one parameter year and returns a boolean. Write the method isLeapYear() knowing that a year is defined to be a leapyear it is a multiple of 4, and if it is is a multiple of 100, it must also be a multiple of 400. isLeapYear() thus decides when a year is a leap year. (see the discussion on "Hints for Assign5" to discover specific examples of a LeapYear).

The purpose of the Date.java is to decide whether a year is a leap year. Here is a definition of when a year is considered a leap year :

-year y1 is a leap year if it is multiple of 4.
-year y1 is a leap year if it is a multiple of 100, it must be a multiple of 400.
-Otherwise y1 is not a leap year.

2. The DateJDialog.java class: implements the GUI. Please use the Dialog boxes developed in the book in chapter2 in pages 99-100 in the code-listing 2-32 (NamesDialog.java) for input and output.

Remember that you will prompt the user to enter:
-a month;
-a day;
-a year

And out of these 3 you will be able to create a Date. Then you will use the dialog box to tell the user whether the year entered was a leapyear or not a leapyear.

Remember that we defined in 1- what it means a year is a leap year or not a leap year.

Do not forget to compile the 2 java files. To verify that the DateJDialog.java works, in TextPad after you compile DateJDialog.java, Click on Tools, Click on "Run Java Application".

When you have completed the assignment, please remember to submit Date.java and DateJDialog.java.

View Replies


ADVERTISEMENT

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

Swing/AWT/SWT :: Show Year Value In A Class That Extends JSpinner

Mar 15, 2014

I am working on a project where i need to show a year value in a class that extends JSpinner.Its working just fine but when i try to set an alignment value for the editor textfield it all falls apart and i know im missing something really critical here but i can't see or find it all i know is that i can't make a proper reference to the textfield component in the editor i use in the correct way or aproach.

public class JNumberSpinner extends JSpinner {
private String actionCommand;
private boolean isEnabled;
private int startValue;
private int columns;
private int alignment;
private SpinnerNumberModel model;
private JSpinner.NumberEditor numEditor;
private JFormattedTextField jTxtEditorView;

[code]....

View Replies View Related

Java Class Date Method Showing Wrong Year

Dec 31, 2013

We use a Java program to read an XML file and put its content into a database. We also use Date() to get the current date and insert it into a field in database with content from XML file. Everything worked flawlessly until today, the last day of 2013. We are getting 2014 for the year instead of 2013!!! System date shows correct year, so this must not be an issue.

View Replies View Related

Swing/AWT/SWT :: Endless Loop While Calling Dialog Box Via Separate JFrame Class In NetBeans IDE

May 2, 2014

I've used Netbeans IDE to create a simple Swing JFrame container, class NewJFrame.

NewJFrame calls another JFrame with dialog in it. Problem is there is an endless call made to it. Here's the issue relevant piece of code:

//Code for calling class
package p;
public class NewJFrame extends javax.swing.JFrame implements ActionListener {
.........
public NewJFrame() {
initComponents(); //IDE auto generated code for binding

[Code] ....

I searched but i cannot understand why run class is getting called multiple times. I have attached the screen prints for both the screens. 2nd screen print(of called class) is very shallow since screen was blinking unstopped due to multiple calls, but i have attached a faint image of it.

View Replies View Related

How To Implement A Variable Into Another Class

Apr 13, 2015

I would like to implement a variable in a class that is used in another class, how can I do that?

I have a Mall class and a Customer class I would like to associate the position of the customer that is in the Mall class and also implement the same in the Customer class.

Here is a small part of the code without all the methods.

//the two objects
Mall m = new Mall("RandomMall",50,30);
Customer c1= new Customer("Jack",1240);
//the first part of the mall class without the methods
class Mall{
private String name;
private int width,length;
String[][]grid = new String[width][length];

[code]...

View Replies View Related

ERROR When Try To Implement A Class

Dec 6, 2014

I'm writing a simple queue program using a netbeans as a GUI program I've used netbeans GUI editor to create the GUI my main problem was I've written the queuing code to a button function it works but it runs only once and the queue becomes empty on the second run. So I implemented a class which will create the queue outside the button click event but when I do that I get a Symbol not found: method error . The place where I get the error:

addStd1.setText("Add Student");
addStd1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addStd1ActionPerformed(evt);
}

My button function with the class:

class stdQueCls{
Queue stdQue;
public stdQueCls(){
stdQue = new LinkedList();
}
private void addStd1ActionPerformed(java.awt.event.ActionEvent evt) {

[code]....

View Replies View Related

Class Can't Implement Chart

Mar 10, 2014

i'm getting cryptic error messages for the following code:

class MyChar implements CharSequence{
private String s;

public MyChar(String input)
{
StringBuilder b = new StringBuilder(input);
b.reverse();
this.s = b.toString();

[code]....

it's telling me something's wrong with the class modifier and that my class can't implement chart

View Replies View Related

How To Implement Own String Class

Feb 12, 2015

I am a beginner at Java programming. how to implement my own String class, but I have to provide my own implementation for the following methods:

public MyString1(char[ ] chars)
public char charAt(int index)
public int length( )
ublic MyString1 substring(int begin, int end)
public MyString1 toLowerCase( )

[code]....

I have looked through the API, but I don't really understand where to start.

View Replies View Related

How To Implement Class DynamicArrayStack

Feb 9, 2015

While learning how to implement the class DynamicArrayStack, I've run into some operators and syntax I'm unfamiliar with!

public class DynamicArrayStack{
protected int capacity
public static int MINCAPACITY=1<<15;
protected int[] stackRep;
protected int top = -1;
//initializes stack to use an array of default length
public DynamicArrayStack()
this(CAPACITY)

[code]....

View Replies View Related

How To Implement Interface And Extend Class

Apr 12, 2014

how to 'implement' an interface and 'extend' a class. Now I want to try and recall the information by memory without using any reference material.
Implementing an interface...

Java Code: //This interface will hold information for cell phones//Like saying... you can't BE a cell phone unless you have this information, at the very least

public interface CellInfo {
public void model();
public void make();
public void androidVer();

}

//Now I implement the interface for a class called Galaxy, which is a class about a specific phone

public class Galaxy implements CellInfo
public void model() {
System.out.println("I'm a Galaxy S5.");
}

public void make() {
System.out.println("I'm made by Samsung.");

[code]....

View Replies View Related

Java Interface - Implement Method In Another Class

Sep 17, 2014

So I created an interface which has the method

int getCalls();

I am trying to implement this method in another class but I'm not sure how to do so. My attempt is:

public getCalls(){ return getCalls(); }

When I run the program it sends the following exception:

Exception in thread "main" java.lang.StackOverflowError
at FibonacciForget.getCalls(FibonacciForget.java:14)
and it highlights the [return getCalls();] part.

What is the correct way to implement the getCalls() method?

View Replies View Related

Implement Class That Computes All Primes Up To Some Integer N

Feb 5, 2014

I am working on a problem that computes primes. Here is the problem: You are going to implement a class that computes all the primes up to some integer n. The technique you are to use was developed by a Greek named Eratosthenes who lived in the third century BC. The technique is known as the Sieve of Eratosthenes. The algorithm is described by the following pseudocode:

create a queue and fill it with the consecutive integers 2 through n inclusive.
create an empty queue to store primes.
do {
obtain the next prime p by removing the first value in the queue of numbers.
put p into the queue of primes.
go through the queue of numbers, eliminating numbers divisible by p.
} while (p < sqrt(n))
all remaining values in numbers queue are prime, so transfer them to primes queue

You are to use the Queue interface provided. When you want to construct a Queue object, you should make it of type LinkedQueue. These classes are included. You should define a class called Sieve with the following public methods:

Sieve() - Constructs a sieve object.

void computeTo(int n) - This is the method that should implement the sieve algorithm. All prime computations must be implemented using this algorithm. The method should compute all primes up to and including n. It should throw an IllegalArgumentException if n is less than 2.

void reportResults() - This method should report the primes to System.out. It should throw an IllegalStateException if no legal call has been made yet on the computeTo method. It is okay for it to have an extra space at the end of each line.

int getMax() - This is a convenience method that will let the client find out the value of n that was used the last time computeTo was called. It should throw an IllegalStateException if no legal call has been made yet on the computeTo method.

int getCount() - This method should return the number of primes that were found on the last call on computeTo. It should throw an IllegalStateException if no legal call has been made yet on the computeTo method.

Your reportResults method should print the maximum n used and should then show a list of the primes, 12 per line with a space after each prime. Notice that there is no guarantee that the number of primes will be a multiple of 12. The calls on reportResults must exactly reproduce the format of the sample log. The final line of output that appears in the log reporting the percentage of primes is generated by the main program, not by the call on reportResults.

Here is my class Sieve. I am having difficulty getting all the primes into the proper queue:

public class Sieve {
private Queue<Integer> primes;
private Queue<Integer> numList;
private boolean computed = false;
private int max;
private int count = 0;

[Code] ....

When I input say, 20, I only get 2, 3, and 11 back as primes. Somewhere in the algorithm (lines 40-54) I seem to have gone awry, but I'm not certain where. Here are the other classes:

SieveMain:
// This program computes all the prime numbers up to a given integer n. It uses the classic "Sieve of Eratosthenes" to do so.

import java.util.*;
public class SieveMain {
public static void main(String[] args) {
System.out.println("This program computes all prime numbers up to a");
System.out.println("maximum using the Sieve of Eratosthenes.");
System.out.println();

[Code] .....

View Replies View Related

Widget Class That Implement Comparable Interface

Mar 15, 2014

Below is the requirements and code. I am getting the error CODELAB ANALYSIS: LOGICAL ERROR(S)We think you might want to consider using: >

Hints:

-Correct solutions that use equals almost certainly also uses high
-Correct solutions that use equals almost certainly also uses low

Assume the existence of a Widget class that implements the Comparable interface and thus has a compareTo method that accepts an Object parameter and returns an int . Write an efficient static method , getWidgetMatch, that has two parameters . The first parameter is a reference to a Widget object . The second parameter is a potentially very large array of Widget objects that has been sorted in ascending order based on the Widget compareTo method . The getWidgetMatch searches for an element in the array that matches the first parameter on the basis of the equals method and returns true if found and false otherwise.

public static boolean getWidgetMatch(Widget a, Widget[] b){
int bot=0;
int top=b.length-1;
int x = 0;
int y=0;
while (bot >= top)

[code]....

View Replies View Related

Servlets :: How To Know Which Class Will Implement Which Session Listener Interface

Jan 23, 2015

how it is decided which class will implement a session listener interface? Which class will implement HttpSessionListener? Which one will implement HttpSessionActivationListener, HttpSessionBindingListener or HttpSessionAttributeListener?

View Replies View Related

How To Enforce Any Class Which Implements Interface Should Also Implement Comparable Too

Dec 15, 2014

How do you enforce any class which implements an interface should also implement comparable too? Say for instance you may have an interface

public interface Task
{ ... }
public class DoThis implements Task { ... }
public class DoThis1 implements Task { ... }

I want all of the classes which implements the interface Task to implement comparable too. Of course I can just say implements Task, Comparable. But is there something which we could do from interface level, i mean interface Task level?

View Replies View Related

Method That Return Instance Of A Class That Implement Iterator Interface

Apr 14, 2015

I have been researching the Iterator and making a class implement iterable. I have seen this example shown below and was wondering how I could change this so that iterable() is not called upon in the main. I would like to be able to make a method that returns an instance of a class that implements the Iterator interface hopefully an inner class. This is because my program will not have a main and will be supplied with a main that includes a new Object with will use the iterator method.

import java.util.*;
public class IteratorDemo {
public static void main(String args[]) {
// Create an array list
ArrayList al = new ArrayList();
// add elements to the array list
al.add("C");

[Code] ....

This is all I have been able to understand from what I want to do. This does not work and this is what I am trying to achieve

public class MyArrayList implements Iterable {
public static final int DEFAULT_SIZE = 5;
public static final int EXPANSION = 5;
private int capacity;
private int size;
private Object[] items;
 
[Code] ...

View Replies View Related

Implement Equality And HashCode Method If Class Has Reference Type Members?

Jan 16, 2015

I am trying to implement the following example to override the equality and hashCode method if the class has reference type member. I do get the expected result "true" for equal and "false" for non-equal objects. But the print statement in the Circle's equal method is not executed when the objects values are not equal. I don't know what i am missing, though i get the equality result "false" as expected for non equal objects.

class Point{
private int x, y;
Point (int x, int y) {
this.x =x;
this.y = y;

[code]....

View Replies View Related

Implement Functionalities Of Set Class Using A Private Data Member Of Type ListReferencedBased

Feb 9, 2015

Okay, I am supposed to implement the functionalities of the Set class using a private data member of type ListReferencedBased<E>,how the ListReferenceBased works with what I am trying to accomplish.I am trying to complete Set.java, and I have barely started and much of the code doesn't work. ListReferenceBased was given to me completed.

import java.util.Iterator;
pubic class ListReferenceBased<E> implements ListInterface<E>, Iterable<E>{
/** reference to the first element of the list */
private Node<E> head;
/** number of items in list */
private int numItems;

[code]....

View Replies View Related

Swing/AWT/SWT :: Error At Class Name - Type JTextField Must Implement Inherited Abstract Method

Oct 27, 2014

This code is directly from Swing: I'm using Eclipse and keep getting an error on line 10 saying :

"The type JTextField must implement the inherited abstract method ActionListener.actionPerformed(ActionEvent)."

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

[Code] ......

View Replies View Related

Find The First Day Of Any Year?

Jan 25, 2014

write a program in java to enter a year and find out the first day of that year

View Replies View Related

Get Month And Year From Calendar

Aug 8, 2014

I have Georgian Calendar object

GregorianCalendar date = (GregorianCalendar)pageContext.getAttribute("datetime");
System.out.println("date :::: "+date);

It prints :

date :::: java.util.GregorianCalendar[time=1408045500000,areFieldsSet=true,
areAllFieldsSet=true,lenient=false,zone=sun.util.calendar.ZoneInfo[id="GMT+05:30",
offset=19800000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],
firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2014,MONTH=7,

[Code] ....

I want month and year from this like August 2014. How can i do the same.

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

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

Day Of Year With Users Input

Apr 8, 2014

I'm doing a problem where I convert users input for the date (MM/DD/YY) into a written out date and year. That part is fine. The part I'm struggling with is then indicating what day that is in that year. how to use the user inputted MONTH, DAY, and YEAR to then get the day of year.

import java.util.Calendar;
import java.util.Scanner;
import java.util.regex.MatchResult;
import javax.swing.JOptionPane;
public class ConvertDate {

[code]...

View Replies View Related

Calculating Rainfall Quarterly Per Year

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







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