I need instantiating 3 instances of the RetailItem
//Instantiate 3 RetailItems
RetailItem jacket = new RetailItem(); ITS TELLING ME: constructor RetailItem in class RetailItem cannot be applied to given types
jacket= jacket.setDescription("Jacket"); <------- ITS TEllING ME: cannot find symbol
jacket = jacket.setUnitsOnHand(12);
jacket = jacket.setPrice(59.95);
I have to make a cash register class that can be used with a RetailItem class that I did in another assignment. It should simulate the sale of an item. It should have a constructor that accepts a RetailItem object as an argument, and the constructor should also accept an integer that represents the quantity of the items being purchased.
I have no errors but here is the output I am getting:
How many candy bars are you buying? 5 Subtotal : $0.00 Sales tax : $0.06 Total : $0.06 BUILD SUCCESSFUL (total time: 3 seconds)
The code I have so far below:
CashRegister Class package cashregisterdemo; public class CashRegister { private RetailItem retailItem; private int quantityItems; private final double SALES_TAX = .06; private int Subtotal; public CashRegister()
Why does it keep giving me the error saying that RetailItem[] inventory not found(from the parameter) if its stated above?
RetailItem[] inventory = {jacket, jeans, shirt}; //Display the inventory in the console display(inventory) //Process a series of RetailItem sales processSales(inventory);
//Display the updated inventory of Retailitems display(inventory);
I am try to do an application based in multiples JFrames, each one with its particular responsibilities, and use one JPanel as a menu with buttons that connect one JFrame to another, But this menu is instantiated at run in view (layout made by netbeans) the Main Jframe appears with its internal JPanel, but the instantiated JPanel does not appear or does not show it's buttons. (notice only run method in the second class):
JPanel Menu that will be used in all alone JFrames of application:
public class MenuSuperior extends javax.swing.JPanel { public MenuSuperior() { initComponents(); } private void initComponents() {
Currently my application is on Tomcat5.0.16.I use struts1.2, jstl 1.1 , jsp-api 2.0.I tried to migrate my application from tomcat5.0 to tomcat 6.0.26.I didn't see any issue in deployment but when i tried to access jsp pages i got this exception.
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: /pbuilder/login/legacyLogin.jsp(6,4) Failed to load or instantiate TagLibraryValidator class: org.apache.taglibs.standard.tlv.JstlCoreTLV org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40) org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407) org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:88) org.apache.jasper.compiler.Parser.processIncludeDirective(Parser.java:297)
[code]....
i found that jstl1.1 jar didn't have the above mentioned class.I replaced jstl1.1 with jstl1.2 jar.i verified that jstl1.2 jar had JstlCoreTLV calss.but even after this replacement of jar i am facing the same issue.
I have a list of uninstanciated class types and I wanted to call a static function from these "Class<? extends PropControl>" (without using reflection) that would create a new corresponding object instance but it appears I cant do that in java so now I want to create a factory that takes a class type as aparameter to create the corresponding object instance but this code dont compile:
Java Code:
public PropControl Create(Class<? extends PropControl> cls) { if(cls==HouseControl.class) <---- ERROR { here I create a new instance of HouseControl (that inherits PropControl) } } mh_sh_highlight_all('java');
I get this error :
incomparable types: Class<CAP#1> and Class<HouseControl>
where CAP#1 is a fresh type-variable:
CAP#1 extends PropControl from capture of ? extends PropControl
I have a quick polymorphism question. I have a parent class and a sub class that extends the parent class. I then declare an array of parent class but instantiate an index to the sub class using polymorphism. Do I have to have all the same methods in the child class that I do in the parent class? Here is an example of what I mean.
public class ParentClass { public ParentClass(....){ } public String doSomething(){ } } public class ChildClass extends ParentClass { public ChildClass(....)
[Code] ....
Is polymorphism similar to interfaces where the child class needs all the same methods?
I have a class named Base and a private variable named _hopcount i have 10 instances of class base i use _hopcount as creteria to some if but other instances edit _hopcount so i want to prevent _hopcount edit by other instances; I want to have private variable which other instances of same class can't modify it.
public class Base extends TypedAtomicActor { private int _hopcount = 0; if(_hopcount <= 3) { some code; } public function() { _hopCount += 1; } }
Declaring the method as static precludes one from using any sort of object oriented programming, thus the method cannot access instance fields of the object if it needs to.
I created two short classes to sort of find out what this meant, but I feel I do not understand it well enough.
Test class (main):
package votek; public class Test { public static void main(String[] args) { SomeMethod(); } public static void SomeMethod() { Character character = new Character(); character.totalLevel = 50; System.out.println(character.totalLevel); } }
Character class:
package votek; public class Character { private int level = 0; public Character() { level = 50; } }
OR
Does it mean that making a static method in the class with private instances will prevent the method from using the private instances?
I am learning JAVA and understanding some of its specific oddities. For example I notice that JAVA loves instances but not variables.
In Python: x = 1 y = 2 print(x,y) yields (1,2)
then I do y = x and print getting (1,1)
This makes sense to me since x and y are variables and thats how variables work. In JAVA I notice this script:
public class TESTRUN { public static void main(String[] args) { int x = 0; int y = x; System.out.printf("x = %d, y = %d %n", x, y); x = 9; System.out.printf("x = %d, y = %d", x, y); } }
This yields: x = 0, y = 0 x = 9, y = 0
So I get that JAVA doesn't understand variables? Or only takes instances of variables? Is there any way to yield a true variable or you always have to update variable relationships?
"Write a program (save the program as ProductInventory.java) that will read data about 5 products from a text file (Products.txt. The program should use the data read from the file to create instances (objects) of Product.java(Use Product class as a Reference Type)."
I'm yet to discover how I will get the info from the textfile using scanners but I don't know how to "create instances of a reference type".
This is the code of Product.java that came with the exercise.
public class Product { private String productCode = ""; private String productName = ""; private int quantity; private String supplierName = ""; private String supplierAddress = ""; private double price;
[Code] .....
By the way, the exercise also required me to use the abstract class ProductLister. To be clearer, the text file is kinda like this:
54643 Rizer Mouse Mark5s Merchandising Marquee Mall 4 205.50 23412 Acer Ultrabook JohnJade Merchandise Cornal City 2 62200.00 93112 Dell Ultrabook Octagon Marketing Cornal City 3 68900.00 22126 Macbook Air Pro Computerware Services San Beda, Chad 2 93500.00
public class Car { //instance variables ---------------------- private String make; private String model; private int year; private double vehiclePrice; private double downPayment; private double milesPerGallon;
[code]....
I created this class "Car" (also not sure if it's correct) and need to write a driver program that creates two instances of the class Car. One must use the default constructor, and the other must use the non-default constructor. It must demonstrate the methods used in the Car class using those instances.
public class DriverCar { public static void main(String[] args) { Car car1 = new Car("Toyota", "Corolla", 2013, 20000, 3000, 35); Car car2 = new Car("Ford", "Taurus", 2005, 14000, 1500, 25); System.out.println(car1);
What I have to do: Use Applet to create two instances of the Employee class. Display the data on the Graphics object. Display in the applet the names and values of all of the instance variables in each instance of the class. Also display the value of any static variables.
What I'm doing:
import java.applet.Applet; import java.awt.*; public class EmployeeApplet extends Applet { public static int topSalary = 195000; int hoursPerWeek; public static void setTopSalary (int s) { if (s > topSalary)
[Code]...
I'm not able to display hours per week for e1 and e2.
I have to write a test class for a Contacts class called ContactTest and store the instances of Contacts created into a LinkedList.The ContactTest class should implement the addition andremoval of contacts to the Linked List and display its contents.
So far I have this, which stores the information entered into a Linked List, the problem is I don't know how I go about doing the addition and removal part.
Contacts Class
public class Contacts implements InterfaceContacts { String fname; String lname; String phone; String email; //constructors public Contacts( ){ this("****", "****", "****", "****");
How do I use two constructors and I'm having trouble with using char for gender...
Write a program to test the Person class defined below. Your test program should create two instances of the class (each to test a different constructor) and test each of the methods. You are also required to illustrate the error in trying to access private data members from the client class (for clarity temporarily change the private modifier to public and test again). See screenshots below for sample output.
The screen shots are displayed as:
p1 name = Not Given Age = 0 Gender = U p2 name = Jane Doe Age = 0 Gender = F p1 name = John Doe Age = 25 Gender = M
and
PersonTester.jave:20: name has private access in Person System.out.println("p2 name = " + p2.name + "Age = " + p2.age + "Gender = " + p2.gender); PersonTester.jave:20: age has private access in Person System.out.println("p2 name = " + p2.name + "Age = " + p2.age + "Gender = " + p2.gender); PersonTester.jave:20: gender has private access in Person System.out.println("p2 name = " + p2.name + "Age = " + p2.age + "Gender = " + p2.gender);
3 errors
Here is the class given :
class Person { // Data Members private String name; // The name of this person private int age; // The age of this person private char gender; // The gender of this person
I am creating a deck of 52 cards each with their rank(1 2 3...King, Ace) and suit(Clubs... Spades).
I want to be able to print out value of each card after creating them such as - 2 of CLUBS and so on. I am able to do that now. Only problem is, when it comes to the picture cards, I am representing them with numbers 11(Jack), 12(Queen) 13(King) and 14(Ace). I can't quite get around to changing the numbers to be represented as the actual words (King and so on).
I imagine that I should store the jack,queen,king,ace values in an enum too and call it in my loop but can't quite get it. Should I have like a 3rd for loop in my following codes to make it work?
Java Code:
//My main method. The Card class follows below
public static void main(String[] args) { Card[] cards = new Card[52]; int i = 0; for (Card.Suits suit : Card.Suits.values()) { for (int y = 2; y < 15; y++) { cards[i] = new Card(y, suit.name()); i++;
Each numeric value in the file is an indication of the number of occurrences of each feature (e.g., forest, tree) multiplied by a given penalty. To generate instances from such a file, I use the following Java code:
I then add the so-generated instances to my model using the instruction model.addInstances(generatedInstances). The resulting output is described below.
It contains errors caused by the instruction model.addInstances(generatedInstances). Debugging my code showed me that the alphabet associated to the model is null. Am I using the wrong iterator?
Ok, so I've seen alot of things online about writing switch code, but I can't find any involving user input, let alone multiple input scanners.
The goal is I let the user put in two different integers and it will decide based on both of the integers which of the 15 possible results it will display.
I am also not allowed to use if/else statements in this program.
My code's not working and I don't know why. I'm trying to read numerical values from a file and saving all instances where a letter is entered instead of a number to a string to be referenced as an error at a later point on in the code. However, there's an error and like I've stated before, I don't know what caused it.
public static void validateData() throws IOException{ File myfile = new File("gradeInput.txt"); Scanner inputFile = new Scanner(myfile); for (int i=0; i<33; i++){ if(inputFile.hasNextDouble()){ double d = inputFile.nextDouble(); if (d<0||d>99999){
[Code] ....
This is the error that returns.
Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:838) at java.util.Scanner.next(Scanner.java:1347) at Paniagua_Grading.validateData(Paniagua_Grading.java:29) at Paniagua_Grading.main(Paniagua_Grading.java:6)
I have got a pretty good framework working for my hangman game so far, however I am quite stumped on how to find multiple instances of the same letter in a single string. I am using indexOf to find the instance of a character in a string, but it only returns the first instance. So if the words(s) contain(s) multiple instances it doesn't register the rest.
public static void main(String[] args) { String word = "crazy horse"; String answer=""; String space=" "; String dash="-";
So in my parallel array i read from a textfile of strings and if i enter the string into the string array and if strings are repeated i store it in a parallel array that counts repeated instances. I'm supposed to get 27 15 21 23 20 but instead i get 106 0 0 0 0....
The idea is pretty simple; extend StackPane, add an active property, bind the visible and managed properties of the pane to the active property, and, whenever the active property is changed to true, iterate sibling nodes de-activating any siblings that are also of the type Card.
However, this doesn't work with Scene Builder. While trying to debug, I created an ExtStackPane:
import javafx.collections.ListChangeListener; import javafx.scene.Node; import javafx.scene.layout.StackPane; public class ExtStackPane extends StackPane { { getChildren().addListener((ListChangeListener<Node>) c -> { System.out.println("ExtStackPane children change: " + c.toString()); }); } }
All this does is log list change events. However, I was very surprised by the output when working in Scene Builder. I added both controls to Scene Builder and did the following:
0) Added an ExtStackPane 1) Added a Card to the ExtStackPane 2) Added another Card to the ExtStackPane 3) Added a Label to the first Card 4) Added a Label to the second Card 5) Changed the text of the first Label to Hello 6) Changed the text of the second Label to World 7) Set the first Card to active 8) Set the second Card to active
I get the following output:
1) ExtStackPane children change: { [Card@5b9067b3] added at 0 }
2) ExtStackPane children change: { [Card@6b6328bd] added at 0 } ExtStackPane children change: { [Card@6aca8cc5] added at 1 }
[Code] ....
This is what things look like in Scene Builder:
Does Scene Builder recreate the entire hierarchy every time I make a small change? Here's an application that does the same as the manual steps I performed in Scene Builder:
import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.stage.Stage; public class CardApplication extends Application {
[Code] ....
The output when running the above is:
1) ExtStackPane children change: { [Card@6dfaa767] added at 0 }
2) ExtStackPane children change: { [Card@6aa2c411] added at 1 }
[Code] ....
The behavior is obviously a lot different than when I'm working with the control in Scene Builder. What Scene Builder is doing to change the behavior of my Card control so much? Does my Card control break some rule(s) I'm not aware of?
From what i understand static methods should be called without creating an instance of the same class . If so why would they return an instance of the same class like in the following : public static Location locateLargest(double[][] a) , the Location class being the same class where the method is defined . I don't understand this , does it mean that every field and every method in the class must be static ? Meaning that you cannot have instances of the class because everything is static . Or it's just a mistake and the class Location cannot have a static method: public static Location locateLargest(double[][] a) ?