What type of object will those who go to the cinema will be?
public void addMovieGoers(Human h) {
mGoers.add(h);
}
And use the mGoers attribute to print what is needed
What type of object will those who go to the cinema will be?
public void addMovieGoers(Human h) {
mGoers.add(h);
}
And use the mGoers attribute to print what is needed
The
public void addMovieGoers()
method should have as argument the element you want to add to the list, and not
hardcode it in the method: Family fam = new Family("",0)
You didn't do that:
Your Cinema class should also have a setMovie method which takes a Movie as an argument.
You should have a Movie attribute in your class that is been set by the argument of the above
method. Then treat this Movie like any other attribute in your methods:
showMovie() should show the above attribute and not create one inside it.
And to start, after a quick look, in your Movie class, you have:
String movieRating
private String title
private String mrating
You use mrating at the constructor and movieRating at the set, get methods.
Use only one of them in your class
Where one class ends and the other starts?
Use code tags and have each class separately
Why did you double post at the same time?
What do you think you can accomplish by that?
They sure changed java last time I checked. They made it look like more C. But wait, this is C.
Listen this is a java forum, and your code is in C, but the error you get is confusing:
gabor.java class or interface expected
How are you trying to compile this?
Have you ever written a .java file and compile it by doing:
javac file.java
?
This: Point3D [][]position = new position[x][y];
is only for arrays and it is wrong the way you wrote it.
You will use this to create 1 Point3D instance: Point3D position = new Point3D(x, y, z);
If you want for example an array that will have Point3D objects:
Point3D [] points = new Point3D[5];
points[0] = new Point3D(1,2,3);
points[1] = new Point3D(...);
points[2] = new Point3D(...);
points[3] = new Point3D(...);
points[4] = new Point3D(...);
Also post your code just to see what you did
You will not use an array. You need arrays to store data, not create objects.
You will create a class with attributes the "sizes" of the Recatngular: x ,y, z
Then you will have a constructor that as arguments 3 values and sets the above attributes: x,y,x
You will also have methods that set and get those values. Here is a link that I took from another post by stephen84s:
http://java.sun.com/docs/books/tutorial/java/javaOO/classes.html
http://www.maths.abdn.ac.uk/~igc/tch/mx3015/notes/node50.html
You will 1, or 2 constructors, 3 get Methods, 3 set Methods and a method that returns the volume
What exactly do you want to accomplish?
When you say 3D volume object, you mean Graphics, or just a java class that represents a 3D Rectangular?
Don't you just hate when ignorant people just post to dead threads that have already been answered?
Check the date of the thread!
What kind of help you think you provided?
If you really want to help someone try a more recent thread and don't pick threads at random
I am new to Java applet.. pls help me out....
I have a very short period to complete this task...
Since you [TEX]have a very short period to complete this task[/TEX] you should have started studying and writing code sooner, and not wait till the last moment and decide to cheat
Search this forum and you will find many examples on how to connect to the database, even code on how to do the login check
I think that you meant to write the other way around. The way you have it, the map.get() returns the String "ONE" and you end up doing: int one = Integer.parseInt("ONE")
I think you should try:
HashMap map = new HashMap();
map.put(new String("ONE"), new Integer(1));
map.put(new String("TWO"), new Integer(2));
map.put(new String("THREE"), new Integer(3));
//int one = Integer.parseInt(map.get(new Integer(1)).toString());
int one = map.get("ONE");
and so on...
HashMap map = new HashMap();
map.put("ONE",new Integer(1));
Integer integ = (Integer)map.get("ONE");
int value = integ.intValue();
or
HashMap map = new HashMap<String,Integer>();
map.put("ONE",1);
int integ = (Integer)map.get("ONE");
Try this:
Object[] possibleValues = { "First", "Second", "Third" };
Object selectedValue = JOptionPane.showInputDialog(null,
"Choose one", "Input",
JOptionPane.INFORMATION_MESSAGE, null,
possibleValues, possibleValues[0]);
System.out.println(selectedValue);
I got it from this:
JOptionPane
Also if you had searched the forum, you would have come up with this post about Stack. Others had the same question as you, so you could have searched to see your question answered
How about:
public void setListData(Object[] listData)
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JList.html#setListData(java.lang.Object[])
Also why not use these constructors
public JList(Object[] listData) or
public void setListData(Vector<?> listData)
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JList.html
You can first check if the input is 'Q' or 'q' and then try to convert it into a double
its php, but I am sure java is similar.
Then why aren't you posting this in the php forum
Is this java?
question = questionGenertor (randomValue1, randomValue2);
// asking the user a math question
boolean wrongAnswer=true;
while (wrongAnswer) {
results = JOptionPane.showInputDialog (question,"");
if (results.equals("" + randomValue1 * randomValue2))
{
JOptionPane.showMessageDialog( null, "Very Good");
rightAnswers += 1;
wrongAnswer = false;
}
else
{
JOptionPane.showMessageDialog(null, "No, Please try again.");
} // end if statement
}
If you want to call methods you can only do it inside other methods (a Constructor maybe).
Where you wrote the code that gives you the error you can only put variable declarations.
So you must declare a method (preferably a Constructor) and put the code that gives you the error there
You have a much more complex solution than the original code that nanna wrote, and you didn't provide any explanation.
You think that this: if (e instanceof NumberFormatException)
is a nice solution?? You should have used 2 catch blocks.
And it would be better to do this:
do {
text=keyboard.readLine();
if (!text.equalsIgnoreCase("Exit")) {
//Parse the input if its not a integer it throw an exception
int x=Integer.parseInt(text.trim());
}
}while (!text.equalsIgnoreCase("exit"));
rather than checking in the catch block whether the user entered Exit or something else
Well,
1. That's already been said.
2. The OP has declared the problem solved.
3. You didn't notice that today was declaredtoday=new date()
rather thantoday=new Date()
.
And
4. This thread is 15 days old. Try to solve more current threads
These are the result I get:
Please enter an integer or (Exit) to stop:3
*0*1*2*3
Please enter an integer or (Exit) to stop:0
You must be doing something wrong, or I am missing something, but most likely the problem is from your end
The closer you can get is this:
Try this:
System.out.println(Table.class);
Or this:
Table tbl= new Table();
System.out.println(tbl.getClass());
System.out.println(tbl.getClass().getName());
while(option!=9) {
Name nameBox[]= new Name[500];
}
You create a new nameBox every time you repeat the loop, so the first time you are in the loop you give values to the local nameBox, but when the loop executes again, you create again a new nameBox (new Name[500]) that naturally hasn't anything inside.
Put the declaration of nameBox outside the while-loop
I have search the java.awt package and didn't find the class Picture:
java.awt
I don't believe that it is a class that the JDK has. Try search it in the internet and you will find plenty Picture classes implemented by others
try out this program, i think this would satisfy your requirement.
import java.util.Scanner;
public class Test {
public static void main (String[] args) {int x=1;
int count=0;
Scanner keyboard= new Scanner(System.in);while (x >=1) {
System.out.print("Please enter an integer or (Exit) to stop:");
x=keyboard.nextInt();for ( count = 0; count<=x; count++) {
System.out.print("*" + count );
}System.out.println();
x=1;}
}
}
It is wrong first to go inside the loop and then read the input. Doing this is not correct: x=1;
at the end of the loop.
Try this:
System.out.print("Please enter an integer or (Exit) to stop:");
x=keyboard.nextInt();
while (x >=1) {
for ( count = 0; count<=x; count++) {
System.out.print("*" + count );
}
System.out.println();
System.out.print("Please enter an integer or (Exit) to stop:");
x=keyboard.nextInt();
}
Plus I would suggest the message to say:
System.out.print("Please enter a positive integer in order to continue")
Because you cannot enter: "Exit" and read it using: keyboard.nextInt()
Create an object StudentInfo with attributes the name, the grade, and a boolean that indicates if the student has passed or not.
Read the file like this:
BufferedReader reader = new BufferedReader(new FileReader("fileName.txt"))
String input = reader.readeLine();
The lines of the file will have each one of them data for each student separated by some sort of delimiter so you might want to use the spilt() method of String for each line. String
file:
name;A;PASS
name2;D;FAIL
Also: ArrayList
Just 2 tips about the issueTicket method:
1) You should change this:
if (difference < 0)
.....
else if (difference > 0 && difference < 60)
.....
else if (difference > 60 && difference < 120)
To this:
if (difference <= 0)
.....
else if (difference > 0 && difference <= 60)
.....
else if (difference > 60 && difference <= 120)
Because if the diif is exactly 60 or 120 then you will print nothing.
Also when you are in the PoliceOfficer class and you would want to create a ParkingTicket object that has a PoliceOfficer variable then you can do this: new ParkingTicket(car, this);
PoliceOfficer class: Simulates a police officer
Responsibilities:
- To know the police officer's name and badge number
- To examine a parked car object and a ParkingMeter object and determine whether the car's time has expired.
- To issue a parking ticket (generate a parkingTicket object) if the car's time has expired.
That means that the PoliceOfficer class should have 2 more attributes:
parked car object and ParkingMeter object :
ParkedCar,
ParkingMeter
In your main you did these calculations:
difference = utimeParked - utimePurchased;
if (difference < 0)
The utimeParked is part of the ParkedCar that the PoliceOfficer will have
The utimePurchased is part of the ParkingMeter that the PoliceOfficer will have
So write a method in the PoliceOfficer class that uses the above values taken from the objects ParkedCar, ParkingMeter that PoliceOfficer has.
PoliceOfficer {
ParkedCar car;
ParkingMeter meter;
....
....
public ParkingTicket issueTicket() {
//in here you will do the calculations
//and return a ParkingTicket object
difference = car.getMinutesParked() - meter.getMinutesPurchased();
// do the calculations
instantiate a ParkingTicket object and return it.
}
}
I order for the issueTicket() method to work, the ParkingTicket will have to have these attributes:
ParkedCar,
PoliceOfficer,
AND:
amount of money to be paid.
You will not create ParkingTicket in main. You will get it when you call the issueTicket() and print what is recquired
You were told to use get, set methods in your class and you used only a set method that changes all the variables of your class. In class: policeOfficer for example you have only a set method which is not what was suggested. Plus the attributes are declared private meaning no one is going to be able to read them.
Rewrite your classes using this example, and rename them so the first letter would be a capital one:
import java.util.Scanner;
public class PoliceOfficer
{
private String officerName;
private int badgeNumber;
public PoliceOfficer (String on, int bn)
{
officerName = on;
badgeNumber = bn;
}
public PoliceOfficer (PoliceOfficer cp)
{
officerName = cp.getOfficerName();
badgeNumber = cp.getBadgeNumber();
}
public void setOfficerName (String on)
{
officerName = on;
}
public void setBadgeNumber(int bn)
{
badgeNumber = bn;
}
public String getOfficerName ()
{
return officerName;
}
public int getBadgeNumber()
{
return badgeNumber;
}
public String toString()
{
String str = "Officer Name: " + officerName
+ "\nBadge Number: " + badgeNumber;
return str;
}
}
Pay attention to which letters I chose to capitalize at the methods:
getBadgeNumber
getOfficerName
If my sleepy mind does play tricks on me, you should do it as
(File)vector.elementAt(i).getAbsolutePath()
I think, although it needs to be checked that you should do this: ((File)vector.elementAt(i)).getAbsolutePath()
Just a suggestion, I don't know if it will work, just try it, because resizing the array is bad idea.
Every time you change the vector you will have to create a new array AND store again the data, so try first the above before using the array solution
You could compare the bytes you get from reading the file, but I have never used that way and I don't know how it will work.
As far as the almost identical you will need to decide the ruling.
http://java.sun.com/javase/6/docs/api/java/io/BufferedInputStream.html
http://java.sun.com/javase/6/docs/api/java/io/BufferedReader.html
http://java.sun.com/javase/6/docs/api/java/io/ByteArrayInputStream.html
http://www.andykhan.com/jexcelapi/tutorial.html
This basic tutorial should be enough to understand that the link supplied by masijade has what you need to start. Guess you didn't bother to give a closer look to the API and search what you need.
If you have written code using the API and got stuck somewhere then you might get a better response
Done>false
Read(income)
If(income ==-1)
Done>true
While(!done)
If(income <= 15000)
Done>false
While(!done)
Read(income)
If(income ==-1)
Done>true
Else
//calculate the income tax
EndIf
EndWhile
First you go inside the while loop:
Done>false
While(!done)
EndWhile
Then you read the income. If it is equals to -1 then done is set to true so you will leave the loop. Else do the calculations and repeat. But I would suggest to change the: '==-1' to '<=0'
This is not java. And during your class, have you learned to write classes with main method and run the "Hello World" program?
class Hello {
public static void main(String [] args) {
system.out.println(Hello World);
}
}
Actually this way is a bad idea:
example_array = argument_array;
You don't copy the elements of one array to the other, you say that the 'example_array' is the 'same' as the 'argument_array'. They both 'look' at the same object in memory, so if change the element in one array the other array will change also.
Suppose you have an original array argument_array and you want to make some changes to it, but keep a copy of the original. If you do this:
example_array = argument_array;
and try to change the example_array and keep the argument_array intact, it will not work. When you try to change the example_array, the argument_array will change as well.
So I would suggest, always use the for-loop way to copy arrays because in that way you create a new array and changes made to one of them will be made to other:
String [] example_array = new String[argument_array.length];
for (int i=0;i<example_array.length;i++) {
example_array[i] = argument_array[i];
}
You need a for-loop inside the while statement. The upper limit of the loop will be the input you give
Create a class like this:
class DataClass {
public int intValue;
public String strValue;
public DataClass() {
}
}
And:
DataClass arr [] = new DataClass[2];
arr[0] = new DataClass();
arr[0].intValue = 0;
arr[0].strValue = "value 0";
arr[1] = new DataClass();
arr[1].intValue = 1;
arr[1].strValue = "value 1";.
for (int i=0;i<arr.length;i++) {
System.out.println(arr[i].intValue +" "+arr[i].strValue );
}
In that way you only have 1 array of items.
Another way is to use Hashtable
I think this:
double numberOfMonths = (principal + totalInterest) / ( monthly payments)
Should be:
double numberOfMonths = (principal + totalInterest) / ( MonthlyPayments)
And weren't you taught in math class the algorithm?
Change this:
System.out.println( " Please enter number of rows in integer type ");
try {
String MAX_ROWS = stdin.readLine();
} catch (IOException e) {
e.printStackTrace();
}
To This:
String MAX_ROWS = "";
System.out.println( " Please enter number of rows in integer type ");
try {
MAX_ROWS = stdin.readLine();
} catch (IOException e) {
e.printStackTrace();
}
In that way you will have access to the variable outside of the try.
Why do you need this when you already doing the above:
int MAX_ROWS = Integer.parseInt(args[0])
You read the MAX_ROWS from keyboard and then again from the arguments ????
Use the either the String MAX_ROWS and turn into an int or don't read from the keyboard and pass everything as arguments.
And the try-catch should be around your whole program. If something fails, you don't want to continue with the calculations
This:
for (int i = 1; i <= MAX_ROWS; i++)
{
for (int star = 1; star <= row; star++)
System.out.print ("*");
System.out.println();
}
Should be:
for (int i = 1; i <= MAX_ROWS; i++)
{
for (int star = 1; star <= i; star++)
System.out.print ("*");
System.out.println();
}
Row is not declared and you want the 1st line to have 1 character, the 2nd line 2. That is why the upper limit of the second for-loop is the line you are now prinitng.
And WHY are you using the same variable for all the values. You have …
This: File stuff = new File(stuff.txt);
Should be: File stuff = new File([B]"[/B]stuff.txt[B]"[/B]);
This: Scanner scan = Scanner(stuff);
Should be: Scanner scan = [B]new[/B] Scanner(stuff);
This: place = scan.NextDouble();
I think should be: place = scan.[B]n[/B]extDouble();
Look at this: Scanner
if you are trying to get (for instance) the total of amount for the customers, just insert your customers in an array and loop over that array getting the amount you want
for instance:
double total = 0; for( int i = 0; i < customers.length(); i++ ) total = customers[i].getAmount(); // I'm not sure what field you want to put together, just looked at your code briefly, but // this (I think) is what you're looking for
Don't forget to add each time the new amount to the total. This will give you the sum:
total = total + customers.getAmount()
first of all this:
sides = mSides;
should be like this:
mSides = sides;
And the error you get is because the method:
mRandom.nextInt(mSides)
doesn't take as argument a negative or zero number; as the error message says it must be positive.
The reason you get the error is because when you do:
sides = mSides
the sides is the argument and you simply change its value. The mSides which is the class variable doesn't change and remains to 0 and you get error.
If you had:
mSides = sides
the argument sides will give value to the mSides of the class, and it will take the value you give it, so the call:
mRandom.nextInt(mSides)
will have what you give as argument
Java is case sensitive. When you declare an instance like this:
Circle radius = new Circle(),
this would be wrong: Area = Radius.getArea().
This is correct: Area = radius.getArea()
Also you call a method:
Circle.setRadius(number) and that method doesn't exist. On top of that if it did exist you should declare it non static and call it: radius.setRadius(number)
You declare a constructor: public double Circle(double Rad) . Classes may have the default constructor so if you declare none you can use the:
Circle radius = new Circle() as you do in the code, bit since you declare a constructor you must use only that: public double Circle(double Rad)
or have 2 constructors
And lastly the constructor shouldn't return anything. This is wrong:
public double Circle(double Rad)
{
Radius = number;
return Radius;
}
Remove the return
I don't know for sure by try the full path of the image with the extension