The requirements are as follows:Design and implement the class Day that implements the day of the week in a program. The class Day should store the day, such as Sun for Sunday. The program should be able to perform the following operations on an object of type Day:
A. Set the day.
B. Print the day.
C. Return the day.
D. Return the next day.
E. Return the previous day.
F. Calculate and return the day by adding certain days to the current day. For example, if the current day is Monday and we add four days, the day to be returned is Friday. Similarly, if today is Tuesday and we add 13 days, the day to be returned is Monday.
G. Add the appropriate constructors.
H. Write the definitions of the methods to implement the operations for the class Day, as defined in A through G.
I. Write a program to test various operations on the class Day.Should I break down my day.java into several separate classes, one for each of the sections (previous, next, etc)?
import java.util.*;
public class MyDay
{
static Scanner readinput = new Scanner(System.in);
String day;
public MyDay(String day)
{
day = "Sunday";
[code]....
Ideally I would like to create a Gui that would have someone type in the day, and then press a button to return the next day, prior day, or have a text input to test for adding X number of days.
how come you can call non static methods from other classes(objects when they are created from main) but not static methods in the same class as the main method??
example I cannot call the method maximum from the main method aslong as its not static BUT i can call other objects non static methods from main??
class test{ public static void main(String [] args){ Scanner input = new Scanner(System.in); //create new Scanner object //for input int number1; int number2;
Its written that every constructor calls its super class constructor. And we know, constructors are called to create an object. Does it mean that if I am creating an object of a class, I am actually creating objects of all its super class???
I was trying to play around a little bit after learning creating multiple classes and stuff.However,i encountered a strange problem with reading a value from the user and then storing it in a variable.The usual way i do it is
But when i trying to print the contents of the variable "variableName" the compiler throws a lot of errors .I am attaching how i have tried that out in my code
import java.util.Scanner; class laptop{ private String modelNumber; private boolean hasFan; private float ramSpeed; protected int numCores; //private String input;
[code]....
Without the setInfo() in the laptop class the program functions as desired but i intend to ask the user if he wants to modify something and then reflect the same.
Why I have to place two parameters in the Verify constructor. If the numbers are being typed in by the user and passed through the validate method, what is the point of having them in Verify() ?
First, create three exception classes named NumberHighException, NumberLowException, and NumberNegativeException. Both NumberHighException and NumberLowException should be directly subclassed from the Exception class, but NumberNegativeException should be subclassed from NumberLowException. You can use the BadDataException class that was defined in this module as the model for your exception classes.
Next create a class called Verify that will be used to validate that a number is within a specified range. It should have one constructor that has two int parameters. The first parameter is the minimum number in the range, and the second parameter is the maximum number in the range.
In addition to the constructor, the Verify class should have one method that is named validate. The validate method should have a single parameter of data type int. The parameter contains the number that is being validated. If the value of the parameter is less than zero, the method should throw a NumberNegativeException. If the value is less than the minimum value of the range, it should throw a NumberLowException. If the value is greater than the maximum value of the range, it should throw a NumberHighException. If the value is within the specified range, no exception should be thrown.
Once all of these classes are created, create the driver class called Program5. The driver class should instantiate a Verify object with a range of 10 to 100. It should then do the following:
-Prompt the user to input a number within the specified range. -Use a Scanner to read the user input as an int. You can ensure that an int was entered because the nextInt method throws an --InputMismatchException if any non-digits are entered. -Call the validate method to validate that the number is within the range. -Print an appropriate error message if the value is not within the range, or print the value if it is within the range.
What I'm doing about it: googling the shit out of my problems, consulting you fine readers, consulting my friends, and yesterday I signed up for Lynda.com. I'm hoping 30hrs+ or so of watching, rewatching, and analyzing the example code will catch me up before I get too behind in CS302
** Assignment Prompt **
Integer types are very convenient, but their limited width and precision makes them unsuitable for some applications where precision is more important than speed. Develop a class VeryLargeInteger that can handle arbitrary long integer numbers (both negative and positive) and the basic arith- metic operations (addition, subtraction, multiplication, division, and remainder).
Hint: The number could be represented as string, the sign could be represented either as boolean or as part of the string.
Note: Implementations of addition/subtraction through repeated use of a constant incremen- t/decrement will not be accepted. Implementations of multiplication and division that rely only on addition and subtraction will not be accepted.
I know I'm going to have to create a separate tester to call on the VeryLargeInteger class and it's math methods. For the new data type, should I convert the integer/string into an array in order to handle the large length of the number? I know he wants us to use recursion for the math methods. My gut tells me addition and subtraction will be slightly easier than multiplication and division. I know I'll have to reference the other methods for division. We aren't allowed to use the BigInteger class.
How I should construct any of the methods.
Java Code:
import java.util.ArrayList; /** ∗ VeryLargeInteger (VLI) is a class for arbitrary precision integer computation */ public class VeryLargeInteger { private int[] num1; private int[] num2; private int[] num3;
I'm creating a program that will compile and run another java program:Lets say I have a program in directory
D:HelloWorldsrc and compiled program will be in D:HelloWorldin inside src and bin is a folder hello (that's a package)
package hello; public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); System.out.println("Hello World"); } }
This program will be run by another program (that's the program that I am creating).Here is the code of my program:
package runnercompiler; import java.io.IOException; import java.io.InputStream; import java.util.logging.Level; import java.util.logging.Logger; public final class RunnerCompiler {
I am working my way through "Head First Java" and typing the code in the book into Notepad++ as I go. In the first few chapters the code was simple and only had one class (main). Now the code has two or more classes. Originally I would compile the code in the Command Window by typing "javac" and the program's name. After it compiled I would execute the program by typing "java -classpath . " and the program's name. However, now when program has several classes I get the following error: Could not find or load main class. Below is a program I am having issues with... does it need to be saved as two separate files?
class DogTestDrive { public static void main (String [] args) { Dog one = new Dog(); one.size = 70; Dog two = new Dog(); two.size = 8;
I have understood my programming class up to this point and now I have been given a lab that I can't figure out for the life of me. Here what I have to do: Write a program that will call a method (called f) to calculate the following function" f(x)=(x^2)-16...this is what the output should be:
This is a simple project that i was using to test my current java knowledge (kinda like revision) and for that i used two classes to make a simple averaging program. i know i0m making it more difficult but like i said i'm testing myself but i come up with an unexpected error. Here's the code:
- 1st Class
import java.util.Scanner; public class Main { public static int num; public static int total = 0; public static int average;
[Code].....
Now the problem is after inputing the numbers it doesn't give me the average but the value of 0.
At startup, the class containing your main method is loaded. It loads all classes that it needs. Each of those loaded classes loads the classes that it needs, and so on. That can take a long time for a big application, frustrating the user. You can give users of your program the illusion of a faster start with the following trick. Make sure that the class containing the main method does not explicitly refer to other classes. In it, display a splash screen. Then manually force the loading of other classes by calling Class.forName.
I'm not sure if I got this right - the tip amounts to suggesting to load all the classes altogether in the main method while displaying the splash screen?
Second, how can the main method not refer explicitly to other classes? It has to create some objects after all...
I am trying to make a program that takes the information from the main args, and displays them as a email in another class when Java is run.
Ex. From: PersonA To: PersonB Email message is here
I have gotten this far, but every time I append my "email.print()" into the next class, it never can print any of the Strings.
Main Args Class:
public class TestMessage { public static void main(String[] args) { Message email = new Message("Harry Morgan", "Rudolf Reindeer"); email.append("Dear so and so,"); email.append("It is my great pleasure to"); email.append("write you an email."); email.append("");
I have a problem with this ascii animation program I am working on. I declared a method inside of my class AsciiAnimation extends JFrame implements ActionListener, called
package AsciiAnimation; import java.awt.*; import java.awt.event.*; import java.util.ArrayList; import javax.swing.*; public class AsciiAnimation extends JFrame implements ActionListener{ int currentFrame = 0; ArrayList<String> frameList = new ArrayList<String>();
[Code] ....
Basically I just am trying to figure out how java works with me accessing those 2 data members, currentFrame and frameList inside of my first class ALL in the same package.
For this week's assignment, I am supposed to create a java program that encrypt's a user's sentence, outputs the encrypted message, then decrypts the message, outputting the user's original message.
This is what I have so far. It doesn't compile the last few lines since that is not correct Java syntax.
Java Code:
import java.util.Scanner; import java.io.*; public class Decrypter { public static void main(String[] args) { String sentence; final char REAL_ALPHA[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
[Code] .....
So you can see I have "realAlpha" which are regular letters of the alphabet, and "codeAlpha" which are the letters I want to encrypt with. I want 'a' equal to 'z,' 'b' equal to 'y', 'c' equal to 'x' and so forth in that sort of reverse order, you know? So the word "apple" would encrypt into "zkkov."
I am stuck as to how to replace the letters in this way. You can see I tried fumbling with sentence.replace to switch the letters out between the two arrays. Also, I only barely understand arrays.
I have my CheckerboardViewer done, my component is what I need finishing. My final product needs to be a checkerboard with alternating red and grey squares but the background is already grey. My code for the Viewer is:
import javax.swing.JFrame; public class CheckerBoardViewer { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(300, 400); frame.setTitle("CheckerBoardViewer"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); CheckerBoardComponent component = new CheckerBoardComponent(); frame.add(component); frame.setVisible(true); } }
I was given the assignment of creating a number to word program for my first college java programming homework.
Here is what I have created so far :
import java.util.*; public class PrintNumberInWord { // saved as "PrintNumberInWord.java" public static void main(String[] args) { int number = 5; Scanner sc = new Scanner (System.in); { System.out.println ("Enter a number"); System.out.println(" "); if (number == 1) {
[Code] .....
The first lines were made for us so we could follow a guideline, however, no matter what I type the command prompt displays 5 to me, I know thats because 5 is defined in the beginning but backspacing 5 causes the program not to work at all, how can I get this program to work properly?
I have a project that is asking me to create a program that will handle a Golfer and his scores. The program will be comprised of three classes: a Golfer class that will manage all the golfer's scores, a Score class and a Tester class to drive the other classes. To accomplish this task the program will use a partially filled array to store the golfer's scores. I have the majority of the code written. It compiles fine, but when I compile and run it only gives the following output.
Tiger ID Number: 1001 Home Course: Pebble Beach Score Date Course Course Rating Course Slope [LScore;@15db9742
I am not sure what I am doing wrong. I have been over and over the code. It is also only printing one golfers information. I have tried creating a for loop for the for the toString in the Golfer class but I am getting the following error Golfer.java:117: error: missing return statement.
I am at a loss here is the code I have for the three sections.
public class Golfer { private String name; private String homeCourse; private int idNum; private Score[] scores; private static int nextIDNum = 1000;
I am trying to create a program that reads a sentence, such as: "abba is running to the radar" scans this sentence, and then prints out all the palindromes. I am running into issues with my arrays and for statements. Here is my code:
static String palindrome, backwardsLower, palindromeLower, palindromeClean, backwards2, backwards = ""; static String[] words; static int counter; public static void main(String[] args) { palindrome = JOptionPane.showInputDialog("Please enter a phrase. " +
[Code] ...
I am aware that there is a few "useless" variables in there at the moment, I will clean them up (as well as some useless statements, I see those too). The issue comes at about line 17. The variable backwards REMOVES all the spaces from the array, so when it comes time to compare the strings, it is comparing individual words to the ENTIRE string, thus no words will ever be a palindrome.
I need getting started designing and creating a program that calculates simple and compound interest. Simple interest in this case means that interest is only applied to the original amount. For instance, if a person deposits $1000 at 10% annual interest, then after one year they would have $1100 (the original $1000 plus the $100 interest) and after two years they would have $1200 (the original $1000, plus the $100 earned the first year, plus the $100 earned the second year).
With compound interest, the interest is applied to all money earned. So, starting with $1000 at 10% annual interest, after one year the user would have $1100 (the original amount plus $100 interest) and after two years the user would have $1210 (the $1100 they started with at the beginning of the year plus the $110 interest).
The requirements of this program are:
-Create a class that will hold methods to calculate the interest. Do not include the main method in this class. -In the class that is used to calculate the interest, include a method to print to the screen, by interest period, the starting amount for the period, the interest earned for the period, and the total amount at the end of the period. Note that each period represents the time frame for how often it is updated. If annual is selected the period is every year. If it is semi-annual it is every six months. If it is quarterly it is every three months. -Create a demo class that will use your interest calculation class. Prompt the user for the original amount, the type of interest (simple or compound), the annual interest rate, and whether it is updated annually, semi-annually, or quarterly. Use method calls to your calculate interest class to do all calculations and display the result. Loop the program until the user chooses to quit.