public class HelloWorld {
public static void main(String[] args) {
String firstLine;
String startUp;
int hour, minute;
[code]...
Every time I try to run this is eclipse, I only get the first part, so it reads in the console: "Hello, world. The time is now 9:15. I'm tired."I want it to read: "Hello, world. The time is now 9:15. I'm tired. (new line) Today is Wednesday."
In Main.java, How can i call method in CircleCalculationMethod.java ?
Should I put everything in same folder ??Should i do something like "import CircleCalculationMethod.java"Should i do something like create a package ...
I have to implement all the stack methods in java such as push, pop empty, not using the ready methods but have to create them and to execute an exercise but is sth wrong with it
public class Stiva { /** the problem is here how to declare the stack 1 and stack 2 and kreu(head) gjmax(size)*/ int Gjmax; int array[] = new int[Gjmax]; int kreu; private Stiva stiva1; private Stiva stiva2;
I have to implement all the stack methods in java such as push, pop empty, not using the ready methods but have to create them and to execute an exercise but something wrong with it....
public class Stiva { /** the problem is here how to declare the stack 1 and stack 2 and kreu(head) gjmax(size)*/ int Gjmax; int array[] = new int[Gjmax]; int kreu; private Stiva stiva1; private Stiva stiva2;
1. Modify the following class so that the two instance variables are private, there is a constructor that accepts both the player's name and sport and there are get and a set methods for each instance variable:
public class Player { String name; String sport; }
2. You can pass an instance of this class to the JLabel constructor if you want to display text in the label.Select one: a. myLabel b. myText c. String d. JTextField e. JLabelText
how to start making this work?cause i am not familiar with the terms here and want to complete this program and I am new to java programming?
I was doing a project in a usual Java Application, but now maybe I have to use some tools that are contained in javafx.scene.media.MediaPlayer so I wonder if can it all work? Will javafx methods and such works?
I have to use javafx.scene.media.MediaPlayer beacuse I have to create a very simple audio player (one jbutton and one jcombobox).
I am trying to make a 2d graphical animation using the java swing classes in order to make a frame. I had a basic version working when all of the code was under the main method, but when I moved some into another method it broke it. With y understanding of java my code should work as I create a variable of the method containing the code and then assign the size and exit button. However this causes many problems such as my BeaconFrame method informing me that it is unused when I have used it. Here is my code:
import javax.swing.*; import java.awt.*; public class BelishaBeacon { public void BeaconFrame() { JFrame frame = new JFrame(); JPanel panel1 = new JPanel();
1. The words remain in their places but the letters are reversed. Eg I love you becomes Ievol uoy 2. The words are also reversed. Eg I love you becomes uoy evol IWrite a program that use the java String class methods.
I have a question about a method I have. In my game, I had a move method to move my player left and right, and originally this method was huge, as it also took care checking collisions and a few other things. I broke it up a bit and put the collisions in their own methods and call them from again another method... Here is an extract which I hope illustrates my point:
private static final double MOVE_SPEED = 0.2; private static final double MAX_MOVE_SPEED = 3.5; private static final double STOP_SPEED = 0.18; private double xPos; private double yPos;
[Code] .....
Something I thought might be a good idea is to check the direction collision when im doing the calculations for that direction:
Then I thought instead i can check it after both of these steps:
if(moveLeft || dx < 0.0) { checkLeft(); }
I guess my question is quite general: How much is acceptable to break up a method? How many chains of method calls is acceptable? Is it ok to call the same method from different nearby places?
I will try to explain what i want to code , a HiLo game where the user can choose up to 3 different levels(1-10, 1-100, 1-1000) with these 3 methods
public static void main(String[] args) {...} public static int playGame(int maxNumber) {...} public static void giveResponse(int answer, int guess) {...}
with no Random , i will use the:
int number = (int)(Math.random() * max) +1; to generate numbers
I have tried so many times , but i don't get it ....
My code so far :
import java.util.Scanner; public class HL{ public static void main(String[] args ){ Scanner s = new Scanner(System.in);
This program is basically complete. It compiles and runs. It is a college course assignment that I pretty much completed but for the last part in which I'm suppose to change the values of all fields and display the modified values using a toString method. Modifying the values of the fields is where I am stuck. I don't think I need to create a new text data file to do this. The instructor only asked that all the values of fields be changed and this was the last part of the assignment so I don't think it involves creating additional ObjectOutputStream and ObjectInputStream objects. I'm getting a NullPointerException error on line 161.Here is the code. I'm also including the input data file.
//create program so that objects of class can be serialized, implements interface Serialiable //create constructor with 4 parameters with accompanying get and set methods, Override toString method //create text file with 5 records, create Scanner object,ObjectOutputStream, and ObjectInputStream //create new ItemRecord object, change values of all fields in ItemRecord object using object's set methods //modify ItemRecord object using toString method
[hightlight =Java]import java.io.Serializable; public class ItemRecord implements Serializable
----jGRASP wedge2: exit code for process is 1. ----jGRASP: operation complete.
Here is the data file: A100 99.99 10 Canon PowerShot-135 A200 149.99 50 Panasonic-Lumix T55 A300 349.99 20 Nikon- D3200 DSRL A400 280.99 30 Sony- DSC-W800 A500 97.99 20 Samsung- WB35F
Here is the data file for the modified field values. B100 98.00 10 ABC1010 B200 97.00 15 DEF1020 B300 96.00 10 GHI1030 B400 95.00 05 JKL1040 B500 94.00 01 MNO1050
In this project each individual will create a data analysis program that will at a minimum,
1) read data in from a text file, 2) sort data in some way, 3) search the data in some way, 4) perform at least three mathematical manipulations of the data, 5) display results of the data analysis in numeric/textual form, and 6) display graphs of the data. In addition, 7) your program should handle invalid input appropriately and 8) your program should use some "new" feature that you have not been taught explicitly in class.
(Note: this is to give you practice learning new material on your own - a critical skill of today's programmer.) If you do not have a specific plan in mind for your project, below is a specific project that meets all of the qualifications as long as 7) and 8) are addressed in the implementation.
Everything is done except I need to call my methods in my GradeTester.
GradeBook:
/** *This class creates an array called scores. *This class determines the length of the array scores and determines the last grade in the array scores. *This class sorts the array using a bubble sort, and searches the array. *This class calculates the mean, standard deviation, and the median of the grades in the array scores. *Once the grades in the array is sorted, the class then calculates the highest and lowest grades in the array. */
public class GradeBook { public final int MAXARRAY_SZ = 20; double [] scores = new double [MAXARRAY_SZ]; int lastGrade = 0; double mean = 0;
I have written two methods called "contains" and "overlaps". The method "contains" is to detemine whether a point (x, y coordinate) is within the surface area of a square object. The location of the square objects is determined by the location of the upper left corner of the square.The method "overlaps" is to determine whether two square objects overlap each other.
I have written these as two separate methods. However I want to change the method "overlaps", so that it uses the method "contains" within it. I.e. using a method within a method. Thereby hopefully making the "overlaps" method a bit more clear and easy to read.
Java Code:
/** Returns true of the point with the coordinates x,y, are within the square. */ public boolean contains(int x, int y){ int sx = location.getX(); //"location" refers to a square object int sy = location.getY(); // getX() and getY() are to find it's coordinates // "side" is the side length of the square if (x >= sx && x <= (sx + side) && y >= sy && y <= (sy + side)){
Below is the main class of a project ive been working on, the goal is to start a countdown specified by the user. When the countdown reaches zero the base drops in the song that is being played. (Its not done yet) The main problem that arises is the fact that my song plays, and AFTER that, the timer starts.
Output:
Please input countdown in HH:mm:ss format. 00:00:41 Start? Yes
The name of of the song is: Skrillex & Damian "Jr Gong" Marley - "Make It Bun Dem"
The time of base drop is: 00:00:41 //Song starts here
//Song is done //Then timer starts 00:00:41 00:00:40 00:00:39
I have following code. In this code CSClient is an interface. All methods of CSClient are implementaed in CSClientImpl class. Do I not need CS Client Impl imported in this code ?
How can I call getBranch() of CSClient, which is not implemented in CSClient as " this. getCsClient(). get Branch (new CSVPath(vpath), true);" ? This code works fine without any error in eclipse.
How can a method getBranch(), which is implemented in CSClientImpl class be used in this code without importing CSClientImpl ?
Write the header for a method named send that has one parameter of type String, and does not return a value.Write the header for a method named average that has two parameters, both of type int, and returns an int value.
I have had to create a text analyser. I have created the program but it is all within the main method. The specification states that I have to have at least two methods within my Program.
import java.io.*; import java.text.SimpleDateFormat; import java.util.*; import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; public class Analyser { public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException {
I'm working on a side project, which will eventually hopefully be a Pokedex, and I've just been going to it at the end of every chapter and using the stuff I've learned to work on it.So I just read chapter 3, which is all about variables and teaches how to use arrays.
my question is, does an array have to be declared inside a method? Because I'm trying to create an array inside a class without any methods and without the main, and I continuously get errors. Here's a quick working of my code that won't compile.
class blah { blah a[] = new blah[7]; a[0] = new blah(); }
The error message focuses on a[0] = new blah(); Telling me the 0 should be a ], the = is an illegal start of type, so on and so forth. The program compiles completely fine if it's within a method, like this:
class blah { void a() { blah a[] = new blah[7]; a[0] = new blah();
}
}
Or if I have public static void main (String[]args); But I'm trying to practice working outside of main.So does an array have to be within a method,