|
|
Edit: Added all instructions the program is now functional but I dont think it fits the requirements of how i was supposed to do it, so if you could point me in the right direction I'd appreciate it! Midterm Part II Problem Statement: Month Class Write a class named Month. The class should have an int field named monthNumber which will ... |
If your parent class declares a single constructor that takes parameters, the child class must call the parent's super constructor as the first call in its constructor. Likely you will pass in the p or price parameter into super. Why are you declaring a static field price in the child class anyway? Are advancedTicket objects going to have the exact same ... |
|
public class SimpleRandomCount extends RandomCount { /** * Constructor */ public SimpleRandomCount(int size) { super(size); } /** * Randomise the array */ protected void randomise() { Integer[] copy = new Integer[array().length]; // used to indicate if elements have been used boolean[] used = new boolean[array().length]; Arrays.fill(used,false); for (int index = 0; index < array().length; index++) { int randomIndex; do { randomIndex ... |
|
|
|
|
public class FrontEnd extends JFrame implements ActionListener { private ArrayList customerArray; private ArrayList- itemArray; private ArrayList orderArray; public FrontEnd(){ } public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("Order List") || e.getActionCommand().equals("Customer List") || e.getActionCommand().equals("Item List")) { addContentPanel(e.getActionCommand()); } } public void addContentPanel(String arg) { mainPanel.remove(contentPanel); if (arg.equals("Order List")){ [B]contentPanel = new ContentPanel(orderArray);[/B] mainPanel.add(contentPanel); } else if (arg.equals("Customer List")){ [B]contentPanel = new ContentPanel(customerArray);[/B] ...
|
|
I am having a problem with my program calling the constructor: heres the code: package p2ip; /** * * @author Ernest */ public class main { /** * @param args the command line arguments */ public static void main(String[] args) { Basic theBasic = new Basic (5.50 , "Basic" , "fName" , "lName" , "eMail","date"); //instantiates basic Premium thePremium = new ... |
|
hello, i have to ceate a constructor named fish that randomly initializes species to shark, gold fish, or cat fish, randomly initializes size and speed to a number between 1 and 10 inclusive, sets condition to true and randomly sets type to herbivore or carnivore. these r my instance variables: String species // indicates the name of the fish species (shark, ... |
Trying to create a constructor that creates a character array with the contents of java.lang.String. And if the string is larger then INITITIAL_CAPACITY, the array should be doubled greater then the length of the string. I got this, does it look right? And then I want to know how to test it? public Magic(java.lang.String tr) { int newCap; this.data = new ... |
Hello I am new to java and I am confused on a project that I am working on. I have to design and implement a class called Sphere that contains instance data that represents the spheres diameter. I have to design the Sphere constructor to accept and initialize the diameter and include getter (getDiameter) and setter (setDiameter) methods for the diameter. ... |
class Cube1 { int length; int breadth; int height; public int getVolume() { return (length * breadth * height); } Cube1() { length = 10; breadth = 10; height = 10; } Cube1(int l, int b, int h) { length = l; breadth = b; height = h; } public static void main(String[] args) { Cube1 cubeObj1, cubeObj2; cubeObj1 = new ... |
|
|
I am little confused about no-arg consturctor and need help in understanding exactly what it is. I have googled this topic and is more confused. I have created a class Rectangle. One of my methods is called public double Rectangle(){} which I thought was a no arg constructor. But when I compile I am getting an saying missing return statement line ... |
Hi there. I am a student at uni who is doing a a few java topics. I have been asked to create a gui which represents a microwave. I have set the interface and gotten the buttons to respond by using a listener. However I keep having trouble trying to initiate a timer. I get this error message: Symbol: Constructor Timer(int, ... |
Java Code: private double balance; /** Constructs a bank account with a zero balance. */ public double BankAccount() { balance = 0; return balance; } /** Constructs a bank account with a given balance. @param initialBalance the initial balance */ public double BankAccount(int initialBalance) { balance = initialBalance; return balance; } /** Deposits money into the bank account. @param amount the ... |
i have another problem with constructors. here is the problem: Complete the class, named Rectangle, that creates a new rectangle, given the integer height (h) and width (w) of the rectangle. This means that the constructor has two parameters. Recall that a square is a special case of a rectangle, with its height equal to its width. Hence, a square can ... |
|
import java.text.SimpleDateFormat; import java.util.Date; import java.text.ParseException; public abstract class Personi{ private String emri; private char gjinia; private Date date; public Personi(String emri,Date date,char gjinia) throws KompaniaException{ if(emri == null || emri.equals("")) throw new KompaniaException("Emri duhet ti ket se paku dy karaktere"); if(gjinia != 'M' && gjinia != 'F') throw new KompaniaException("Nuk mund te ket tjeter gjini pos Femer dhe Mashkull [F,M]"); ... |
When I try to compile normally, I get an unchecked/unsafe error, and when I ignore it I get an error for each insance where I try to use my Car constructor. The error is Car.java:35: not a statement, with the little arrow pointed at the 'c' in car1, car2, and car3. My code is: Java Code: class Car { String plateNumber; ... |
/* there is a problem in this code guys i know what the problem is but i dont know how to fix it .as you see there are 2 case i get inputs and i call constructors and initialize and set inputs. but in case 3 ( cl=new Investment() and cl.getFutureValueMontly()) this lines mess up everything the constructor initialize them as ... |
|
import java.awt.*; import javax.swing.*; public class Visitor extends JFrame { JPanel basePane, leftPane, rightPane; JLabel cardTitle, firstName, lastName, nationality; JLabel entryDate, departDate, stayLength, visitPurpose; JTextField forFname, forLname, forNationality; JTextField forEntryDate, forDepartDate; JComboBox forStayLength, forPurposeChooser; String strFname, strLname, strNat; String[] stay = {"less than 5 days" ,"one week", "about 10 days", " about two weeks", "more than two weeks"}; String[] purpose = ... |
|
Constructors don't have a return type. It's hard to give an exact answer without seeing some of the code from the subclasses, but I'm assuming it has to do with your lack of a constructor (besides of course, the default one) in the coin class. Remove the 'void' Also, use correct java naming conventions, all classes should have the first letter ... |
My teach dinged me for not providing a constructor, also I was supposed use toString () ??? please help me revise this so that it meets their standards Java Code: import java.util.Random; public class Card { public String cardGeneration() { Random generator = new Random(); int x; // random integer representing suit int y; // random integer for card value String ... |
|
|
output is intended to do various things: it writes content to a file, it is able to format things (object instances and primitive values), and it uses buffering so that the disk is not being hammered for each byte being written. The question is how to organise these different aspects of functionality - and other functionality that you or others may ... |
public Track(String artist, String title, String album, int year, Genre genre) { // check parameters and assign data fields assignValues(artist, title, album, year, genre); } public Track(String artist, String title, String album, Genre genre) { // TODO: put specified parameters alongside with default values // for the unspecified ones into the master constructor // (or into a higher tier minor constructor) ... |
|
|
} public static void main(String args[]) { prac p = new prac(); p.find_area(); /* output is 0.0 dont know why * as u can see that default value * of radius is 99 * ????!!!!!!! * thats the first question */ prac p1 = new prac("circle" , 12); //the line above code genrates error } } P.S can any1 refer me ... |
|
I think what you have is called a circular reference, but I may not be right. LawsonUser calls the super constructor of Employee (which it has to do one way or another), and Employee calls the LawsonUser's constructor from within it. And so it will keep going on and on forever. It smells funny to me that a base class should ... |
wow, uhm, well, im not good at java really :P ive only got school java. So im a bit confused now. Ill look at the bit of code u posted so long thank you. ill try and figure something out and post if im stuck again. OK so im confused a bit. where it says "your action code here" i am ... |
|
|
main() is just a method like any other. It has to have a certain signature (return type, arguments etc) if it is being used to kick off an application but other than that there are no restrictions on its use. Your question is a bit ambiguous: do you mean to declare and define the constructor within the body of this method? ... |
If you define a constructor in a class (as you have in your Music class), the compiler will not implicitly create a no-arg constructor for you. So, when you create a new instance of Music, you'll need to pass the required arguments to the constructor (or explicitly provide a no-arg constructor). ~ |
No it doesnt take a string. It takes a Directory. Make a Directory Object, probably stuff a string in that. Edit: Just to Re-iterate, the Javadoc states here: SpellChecker(Directory spellIndex) A Directory is NOT a string object; as the compiler is explaining to you. I havent looked at the directory object, but maybe something like new SpellChecker(new Directory(".... your string here... ... |
import javax.swing.JOptionPane; public class CreateDelivery { public static void main(String[] args) { Delivery newDelivery = new Delivery(); String enterYear, enterMonth, enterDeliveryNum, enterMethod, enterWeight; int inputYear, inputMonth, inputDeliveryNum, inputMethod; double inputWeight; String displayMethod = " "; enterYear = JOptionPane.showInputDialog(null, "Please enter the year.\n2001 thru 2009 are the only valid entries."); inputYear = Integer.parseInt(enterYear); while(inputYear < 2001 || inputYear > 2009) { enterYear ... |
Hi Vijay, I'm sorry for not making myself clear. I want the coding of run method. But, as per my assumtion, you are using a loop in which you are creating this object ob AbcDlg class. Try to remove that code from loop and paste outside the loop. If you have problem, then post the coding of run method. Regards Aakash ... |
this.mfact = mfact; this.mo = mo; } public somemethod() { sts.record(); } public void somemethod1() { mo.create(); } } ***************************************************Another Class****************************************************** public class Xyz{ // Some code here // this class calls Mthread and creates 10 such Threads sth like for (int i = 0; i < 10; i++) { mThreads = new MThread(mfact, mo; } } ***********Another Class **************** public ... |
|
|
I am really new to java and i am trying to work on my homework and i don't understand the difference between a class and a constructor, and the book isn't making much sense...Eclipse says my program has not defined...The constructor Robot () is undefined, What does that mean? And could someone explain some of the basics of java, my teacher ... |
|
setSize(400,300); setDefaultCloseOperation(EXIT_ON_CLOSE); setTitle("First test of Frame"); setVisible(true); } } The above program works, and the frame appears. The trouble is, the textbook does not use the method setupFrame, but instead puts those 4 statements in the constructor Testframe() . But when I do that, the frame does not appear. The program appears to run to completion. Can anyone please tell me ... |
I just need some help with some coding. The pseudocode is: Declare a variable called "car" of type "Car", and initialise // its value to a new instance of the "Car" class. // * Declare a variable called "race" of type "Race", and initialise // its value to a new instance of the "Race" class. The "Race" // constructor requires two ... |
|
|
Dear sun forums members/viewers, Please find below code that compiles but gives me errors with bluej ide. I am very newbie to java - please have mercy on me! Thanks in advance tma03 due in tomorrow (sobs) Barrie /** * Constructor that takes two arguments theText and theUrl * changes the instance variable text to the argument supplied * with new ... |
|
If you're still struggling to understand then do an exercise for me... create a DodgeyAccount class your way, with only the default (no-args) constructor, and an [Good]Account class with the "all-args" constructor as specified by the textbook. Now try to find ways to misuse both classes... I bet you'll find it a lot easier to get incorrect/misleading results from BadAccount than ... |
|
Hi, why we dont have no return type for java constructor??????? say example, class Chumma{ public Chumma(){ System.out.println("i am inside test constructor"); } public static void main(String[] args){ Chumma c = new Chumma(); // to do our stuff } } in the above code, why not the constructor return int or string etc... like public int Chumma(){ return 33; } |
|
|
I'm a high school student and trying to review some JAVA homework -- what I got wrong. Using Student class for a client program, are these statements valid or invalid: Student stu2 = new Student("Billy") I thought this was valid but my notes from class today say it's INVALID. Does this mean this has to be : Student stu2 = new ... |
|
1. Bad hobbit! Bad, wicked, naughty hobbit! Places1 is a class I use to hold an object arraylist, as it holds 3 different classes of objects inside. Seriously dude, that's bad programming... it's called a dirty collection, and professional programmers feel about dirty collections as good chefs feel about dirty rats... we cast them into The Pit Of Mordor at the ... |
|
} //SETOUTCOME() handles using the player values to determine outcome of an event, takes args of //the values that will be used to determine outcome public void setOutcome(int m, int c, int p, int q, int pl){ if(m == 0){ Outcome += 0; }else{ Outcome += (int) (Math.random() * getMagnetism() + getMagnetism()); } if(c == 0){ Outcome += 0; }else{ Outcome ... |
Are you asking us for the rules on how to convert the block number into cylinder/head/sector? We can't help you, you must know what your application must do. I assume it's got something to do with that DiskConfig object. Or do you know the rules and don't know how to translate them to Java code? In this case, we might be ... |
What is this? setTime looks like a variable, but it is never declared anywhere. The naming looks like it's a method, but (1) it is not declared anywhere and (2) that's not how one uses a method. Time() looks like a method, but it is never declared anywhere. The naming looks like it's a constructor method, but that's not how one ... |
|
|
Why are you using a constructor to do this? A constructors job is to create an instance of a class. You should create another method to form the new array. When you get the new array what do you want it to do? Copy elements from the old array? It is unclear from your post. |
as a newbie, its nice to be able to ask a question rather than being directed to a site with loads of pages, being new, its hard to understand even what to look for. That's why one would go into a New To Java forum to ask people for help with something that they don't understand, and it would be nice ... |
I am using the cmd prompt to run my program. When I type in a name, hourly pay, and hours worked, I receive the correct information adn it displays correctly. But, how do i know that it is storing the information and how do i recall the information stored. Am I missing something in my code? |
In all fairness to the OP, most introductory classes don't explain how to read errors very well at all, and when I started doing Java, I had a very hard time understanding compiling errors, other than what line it was on. It would be nice if this was one of the earlier things they taught, but it's not always that easy ... |
1. It's always an excellent idea to clearly state what you are trying to do -- what your goal is. You know it, but we're not mind readers. It seems like you want to populate a JComboBox with items from a database table. Creating a new model every time through that loop is never going to work. Consider using JComboBox's addItem ... |
i am new to java so wanted to now bout the necesity to use constructors in java. n also y java doesnt support distructors?? yes offcourse it has concept of garbage collector but whether user will come to know that the object which is not in use has been deleted?? if yes then how?? |
|
default constructor is usually empty in Java and you can declare like this: public className () { } and when you need to declare other constructors make sure you have the same number of parameters like public className ( String parameter1 , String parameter2 , ...... int parameterN ) { this.parameter1 = parameter1 ; this.parameter2 = parameter2 ; ... this.parameterN = ... |
But I'm guessing that's not what you meant. And all that mucking about with reflection isn't, either. I suspect you have code spread across 2 constructors that you want run, so refactor your code so that it does. A constructor can in turn call another constructor, as per my snippet above. Write code so that it does what you want, don't ... |
public WriterBot(City aCity, int aStreet, int anAvenue, Direction aDirection) { super(aCity, aStreet, anAvenue, aDirection); } } END FILE 1 /CODE import becker.robots.*; /** * @author */ public class Main { public static void main(String[] args) { // Construct the initial situation. City nc = new City(7, 21); WriterBot writer = new WriterBot(nc, 1, 0, Direction.EAST, 48); it compiles fine until I ... |
|
|
Yeah, im still working on this, i only have about a day to hand it in aswell, so im trying to make sure most of it is working ok. Im still having a bit of problem with getting the 'getEmptyRooms' method working aswell. i just noticed what i wrote there. Instead i mean setting the length of the Room[] array to ... |
|
|
Here is some general information about constructors. 1. Constructors are not inherited into subclases. 2. A class that has no constructors is given exactly one. A default, no argument costructor of public access. 3. A constructor can call upon other constructors in the class for help, using the this() construct at the begin., of the constructor. 4. A constructor can call ... |
Some classes don't have constructors. I understand that all classes will inherit a default constructor, but some classes don't appear to be objects at all. Classes that have main methods in particular seem to be intended not to define objects but instead simply to instantiate other objects and to execute code...... I'm going through a tutorial that has a plethora of ... |
|
|
|
|
I'm not too sure what you are trying to do or what the problem is but I can see that there is absolutely no magic happening between aDay and basic. Is there supposed to be? If yes then you will need to add code. If no, then why do you create aDay if you never do anything with it apart from ... |
|
|
|
|