Same class in different package

I am facing a design decision, I have a set of classes which defined the values of all variables. However, I realized that I need to prepare
separate set of these classes for different countries (as they may vary), i.e
my.package.us
     PriceList.java
my.package.ca
     PriceList.java
PriceList.java
===============
Public class PriceList {
public final static Price directFlightPrice = new Price(13500,2); // where 0 is the decimal places
public final static Price connectFlightPrice = new Price(11000,2); // where 0 is the decimal places
I am not sure how I can achieve this, would you guys please help? Thank you!

Isn't this more what you need? You don't want to create a new class, you should create a new instance of a class.
class PriceList {
    private Price directFlightPrice;
    private Price connectFlightPrice;
    private String country;
    public PriceList(String country, Price directPrice, Price connectPrice) {
        this.country = country;
        directFlightPrice = directPrice;
        connectFlightPrice = connectPrice;
    ... methods to use pricelist variables
class PriceListTest {
    public static void main(String[] args) {
        Map<String, PriceList> pricesPerCountry = new HashMap<String, PriceList>();
        // This is where you could load data from file and put it into a PriceList object...
        PriceList plUK = new PriceList("UK", new Price(...), new Price(...));
        PriceList plAu = new PriceList("Australia", new Price(...), new Price(...));
        pricesPerCountry.put(plUK.getCountry(), plUK);
        pricesPerCountry.put(plAu.getCountry(), plAu);
        // Use pricelist UK
        PriceList list = pricesPerCountry.get("UK");
}

Similar Messages

  • Same class name, different packages

    Let's say I have two classes called Team, and each are in their own package. I go to import a.Team and b.Team, what do I have to do to make this work?

    Import them both if you need them both. When you go to use them, refer to them by their fully qualified name.a.Team aTeam = new a.Team();
    bTeam bTeam = new b.Team();You don't really need the import statements from a programatic point of view, but it helps make your code more legible to other developers.

  • Accessing a dll from classes in different packages

    Hello java community,
    I am new to Java and especially the jni so your help is greatly appreciated.
    I am having trouble accessing a Windows native dll from classes in different packages. I placed the .dll in my ClassPath. I am able to loadLibrary successfully from class X in my 'common' package. However, when I try to access the same .dll from another class Y in package 'notsocommon'. I get an unsatisfied link error. I changed the X.h file to include common in the function definition (eg. Java_common_X_functionName) and I did the same to the Y.h file (Java_notsocommon_Y_functionName). I am able to work with the dll from the X class but not the Y class. I don't know what I am doing wrong. I am very new to Java, so any help is appreciated.
    Thank you.

    I apologize to everyone for posting this. I figured out my mistake, it was in the dll and not in the java. Also using
    javah -jni notsocommon.Y
    creates the correct header file.

  • Files with same name in different packages

    I have a file with the same name defined in two different packages.
    When I generate the javadoc, I get an error saying that
    Class com.eg.toolkit.Email already defined in com.eg.common.Email.java
    Does javadoc expect all files to be of different names acroos packages?
    Thanks
    Chintu

    You can use the same class name in different packages.
    The Java API does that (java.awt.List, java.util.List).
    This is odd. What version of javadoc are you using,
    and what command are you passing in, with what classpath setting?
    -Doug Kramer
    javadoc team

  • Create Classes In Different Packages With Error-free Importing

    Hello,
    I'd like to create a class which inherits from another class from some other package. So I use "import" keyword to involve the class to build my new class on. However, I hope my new class can be in its own package which is different with one the base class is in. To make it clear, please see the example below:
    There are two folders, with name c08 and c09 respectively, in C:\Java which I created for this case. I set the environment variable as C:\Java. There is no problem. Then I saved file "Inter.java" in C:\Java\c08. It's source code is as below:
    package c08;
    public interface Inter {
         void play ();
         void action ();
    And another "Test.java" is saved in C:\Java\c09. Source code as below:
    package c09;
    import c08.*;
    public class Test {
    protected class PC implements Inter {
              public void play () {
                   System.out.println("Play()");
              public void action () {
                   System.out.println("Action()");
    It was successfully compiled for "Inter.java". But when comes to "Test.java", it failed with error message of something like "Cannot find the interface Inter". I tried some other ways and I didn't get any results.
    I hope to create a class using classes from some other packages while keeping the new one in a different package. How can this be done? (I am currently doing this in J2SE 1.4.01 under Windows XP Home Edition)
    Thank you!
    Best Regards
    Felix

    I copied and pasted your code as well as made c08 and c09 directories. I had no errors compiling. I am using NT, but it appears that your problem is Classpath related. You can try to CD to the C:\Java directory and compile using "javac c09\Test.java" That's the command I used.

  • Moving Bean-class to different package

    Hi,
    For deployment reasons i need the Bean-class in a different package, seperated from package where the Remote and Home are located. I'm not sure how to do this in VisualAge 3.5p2. Simply moving doesn't work.
    Hope someone can help,
    Maarten

    It sounds a little bit strange. Do you want them in packages with different names, like you have bean-class in com.mycompany.project1.mybeanclasses and have the Remote and Home classes in com.mycompany.project2.myremotehomeclasses? It seems possible if you right-click the class you want to move and select 'move', you can move it to a new package. This will be able to separate them.
    Just curious, I think VAJ is very powerful concerning deploying EJBs already so what kind situation makes you want to separate the bean-class and interfaces?
    PC

  • Moving Model Class to different package

    Hi,
    How can i move the model class to a different package in CE 7.1
    Regards,
    Senthil

    Hi Senthil
    I thinks this should be possible to realize on the file system level.
    - Find the folder where your model as well as the model classes are located.
    - Search for all files (.) that contain the model class name. Typically it'll find (*.wdmodel and *.wdmodellclass). Change manually the package name within/near the found lines.
    But why do you need to change the model class package separately from the model package?
    BR, Siarhei

  • RMIClassloader same class name different versions

    I am writting a system so that I can have a task server send tasks off to a computing node and return the results. The plan is to set these clients up on a bunch of unused pcs around my university. Something that I am starting to wonder about though is if I run a distributed application once, then change parts of that application, will the RMIClassloader on the client know to redownload the applicable jar or will it try to use the old jar file which (I assume) it has cached or loaded already? The reason is, is that I I am in a development stage and my codebase might be changing although once the client and server are built I don't plan on making many changes to it after it is degugged.
    Thanks,
    RDL

    The same JVM will use the same downloaded class, but a new JVM will do a new download. There is no caching between JVM invocations. You do need to consider the effect of local HTTP proxy caches as well if there are any in the network.
    EJP

  • Command Line Compilation of  a Project with different packages

    Hi,
    I am trying to compile a project through command line, which has different packages with many classes in it. Now If I try to compile package by package It's complaining about other referenced classes of different packages. So I created .bat file, which includes all the packages, but it's complaining input line is too long.
    D:\jdk1.3.1\bin>app.bat
    My bat file is
    javac -d d:\Application\build d:\Application\source\com\ibc\rules\login\*.java d:\Application\source\com\ibc\rules\lookup\*.java .................d:\Application\source\com\ibc\wid\events\*.java d:\Application\source\com\ibc\wid\frames\cust\*.java ...
    and so on............
    Is there any solution for this problem?
    Thanks in advance....

    I think the prefered and more elegant way to compile project including packages should be writing makefiles including their compilation, installation, deploying - rules ..
    Make is really powerful, the maybe only weak-point is that there are some distribution of them, gnu-make, microsoft nmake .. which are slightly different, that made porting among platforms difficult.
    The jakarta-ant was a new approach to this which uses xml parser to proof the dependencies, etc ..
    Because I'm not familiar yet with xml & ant and as a in-blooded unix user, "make" is still my prefered way to do roject.
    The easiest way to get unix environment required for using make in Windows platforms is to download the "unxutils". It includes make, bzip2, diff, ... and other unix-tools. Refer to this (found from search by google) :
    http://www.weihenstephan.de/~syring/win32/
    http://www.weihenstephan.de/~syring/win32/UnxUtils.zip
    http://sourceforge.net/projects/unxutils/
    For more documentation on how to write makefile, use make -tool, see
    http://www.gnu.org/manual/
    http://www.gnu.org/manual/make-3.79.1/html_mono/make.html

  • How to load the same classes of the same name, from different jars

    Hi,
    I have several different versions of my project in respective jars. I am trying to develop a configuration app, which will have the most current version of my app packaged within it. Then the user will make a selection, and if that selection is an older version, a specific class from one of the jars...which will continue to load other classes within that same jar. If it is the current version, the class will be found within the codebase.
    My question is if this is even possible? Can I load a class from a jar file which has the same file name and package as what is in my current code?

    nasch_,
    So I have been searchin around, and found some good tutorials on classloaders, But i still see a problem.
    Whether I use the same classloader for different sources or not, the problem lies within the reference to the class i am loading. Since this class (a different version of it), is also in the classpath, how does the code know which class is being returned?
    I am having trouble putting this into words, but basically. i don't see how my application will know that i am returning an instance of a class which is not in my classpath.

  • How to convert the class in the one package to same class in the other pack

    How to convert the class in the one package to same class in the other package
    example:
    BeanDTO.java
    package cho3.hello.bean;
    public class BeanDTO {
    private String name;
    private int age;
    * @return
    public int getAge() {
         return age;
    * @return
    public String getName() {
         return name;
    * @param i
    public void setAge(int i) {
         age = i;
    * @param string
    public void setName(String string) {
         name = string;
    BeanDTO.java in other package
    package ch03.hello;
    public class BeanDTO {
    private String name;
    private int age;
    * @return
    public int getAge() {
         return age;
    * @return
    public String getName() {
         return name;
    * @param i
    public void setAge(int i) {
         age = i;
    * @param string
    public void setName(String string) {
         name = string;
    My converter lass lokks like
    public class BeanUtilTest {
         public static void main(String[] args) {
              try
                   ch03.hello.BeanDTO bean=new ch03.hello.BeanDTO();
              bean.setAge(10);
              bean.setName("mahesh");
              cho3.hello.bean.BeanDTO beanDto=new cho3.hello.bean.BeanDTO();
              ClassConverter classconv=new ClassConverter();
              //classconv.
              System.out.println("hi "+beanDto.getClass().toString());
              System.out.println("hi helli "+bean.toString()+" "+bean.getAge()+" "+bean.getName()+" "+bean.getClass());
              Object b=classconv.convert(beanDto.getClass(),(Object)bean);
              System.out.println(b.toString());
              beanDto= (cho3.hello.bean.BeanDTO)b;
              System.out.println(" "+beanDto.getAge()+" "+beanDto.getName() );
              }catch(Exception e)
                   e.printStackTrace();
    But its giving class cast exception. Please help on this..

    Do you mean "two different layers" as in separate JVMs or "two different layers" as in functional areas running within the same JVM.
    In either case, if the first class is actually semantically and functionally the same as the second (and they are always intended to be the same) then import and and use the first class in place of the second. That's beyond any question of how to get the data of the first into the second if and when you need to.
    Once you make the breakthrough and use one class instead of two I'd guess that almost solves your problem. But if you want to describe your architecture a little that would help others pin down want you're trying to do.

  • Multiple windows of the same class with a different argument

    Suppose I have a main window with a list of users. If I click on any one user, the "chat window" should open with the argument as that "user".
    If i click on another, a similar "chat window" should open but with a different user.
    I can't have so many stages because I don't know how many users are there.
    How do I open multiple windows of the same class but with a different argument?

    Here is a sample (opens, at random locations, a bunch of child windows parameterized by color).
    Could be simpler, but hopefully you get the gist.
    import java.util.Random;
    import javafx.application.Application;
    import javafx.geometry.Rectangle2D;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.layout.StackPane;
    import javafx.stage.*;
    public class ColoredStages extends Application {
      final String[] colors = { "firebrick", "palegreen", "azure", "chocolate", "goldenrod" };
      final Random random = new Random(42);
      Rectangle2D screenBounds;
      public static void main(String[] args) { launch(args); }
      @Override public void start(Stage stage) {
        screenBounds = Screen.getPrimary().getVisualBounds();
        stage.setTitle("Primary");
        stage.setScene(new ColoredScene("cornsilk"));
        stage.show();
        for (String color : colors) {
          Stage coloredStage = new ColoredStage(stage, color);
          coloredStage.show();
      class ColoredStage extends Stage {
        ColoredStage(Stage owner, String color) {
          super();
          initOwner(owner);
          initStyle(StageStyle.UTILITY);
          setX(screenBounds.getMinX() + random.nextInt((int) screenBounds.getWidth()));
          setY(screenBounds.getMinY() + random.nextInt((int) screenBounds.getHeight()));
          setScene(new ColoredScene(color));
      class ColoredScene extends Scene {
        ColoredScene(String color) {
          super(new StackPane());
          StackPane layout = (StackPane) getRoot();
          layout.getChildren().addAll(new Label(color));
          layout.setStyle("-fx-font-size: 20px; -fx-padding: 30px; -fx-background-color: " + color);
    }

  • How to instantiate a class from a different package?

    I am trying to instatiate a class in a package: a.b.c from another class in a different package: d.e.f
    How could I do so?
    I've already been trying many things but didn't manage to get it to work...

    Did you include both jar files in your classpath? Use
    the -cp option of the java interpreter to specify your
    classpath.Well, I tried adding the jar file to the classpath, without any success...
    String path = getClass().getProtectionDomain().getCodeSource().getLocation().toString();
                   String finpath = "";
                   for(int i=6;i<path.length();i++)
                        finpath = finpath+path.charAt(i);
                   System.setProperty("java.class.path",System.getProperty("java.class.path")+";"+finpath+"mm.mysql-2.0.14-bin.jar/");That's what I did and it didn't work...
    If you "unpack" the jars see if there is the correct
    packages-folders symmetry...Yes, the classes are in the package-folders they should be in..

  • How to import a class from a package at the same level

    Hello friends,
    i have a class as Plaf.java
    as
    package org.vaibhav.swing.plaf;
    import java.awt.*;
    import javax.swing.*;
    public class Plaf {
    other code
    }as you see, this is in org.vaibhav.swing.plaf package.
    I have one more class as
    package org.vaibhav.swing.frames;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class StartFrame extends JFrame implements ActionListener {
    other code
    }and this class is in package org.vaibhav.swing.frames
    Please hlp me how to use the class Plaf in StartFrame.java. Rather what import statement should i use in StartFrame.java.
    please help.
    thank you
    Message was edited by:
    vaibhavpingle

    but it then gives me this error
    StartFrame.java:11: package org.vaibhav.swing.plaf
    does not exist
    import org.vaibhav.swing.plaf.*;
    Have you first compiled Plaf.java and saved it in this directory strucuture
    /org/vaibhav/swing/plaf/
    And also have you set your classpath to the parent directory of org folder.
    Message was edited by:
    qUesT_foR_knOwLeDge

  • Class name and package name clashing

    When i have a class and a package with the same name, I cannot access classes in the package. For example I have 3 classes and 1 package as below
    - Test.java
    - PackageName.java
    + PackageName // this is a directory
    - MyClass.java
    Below are the codes of .java files
    Test.java
    =======
    public class Test { PackageName.MyClass a = new PackageName.MyClass ();}
    PackageName.java
    ===============
    public class PackageName{ }
    MyClass.java
    ==========
    package PackageName; public class MyClass { }
    I can compile PackageName.java and MyClass.java but not Test.java. It says
    cannot resolve symbol
    symbol : class MyClass
    location: class PackageName
    PackageName.MyClass a = new PackageName.MyClass ();
    But if I remove the PackageName.java, I can compile Test.java perfectly. I think when I use PackageName.MyClass, java thinks that I try to access an inner class MyClass of PackageName class, and that does not exists. Is there any way to solve this ambiguation, other than making the package name and class name different? Thank you very much.

    This works fine: just add an import to Test.java.
    import PackageName.MyClass;
    public class Test
        public static void main(String [] args)
            MyClass a = new MyClass();
    public class PackageName {}
    package PackageName;
    public class MyClass {}It's a pretty wacky, useless example, but it works.
    Plus I thought inner classes would have a dollar sign in their .class file names. When I compile this:
    public class OuterClass
        public static void main(String [] args)
            OuterClass outer = new OuterClass();
            System.out.println(outer);
        public String toString() { return "I'm an OuterClass"; }
        class InnerClass
            public String toString() { return "I'm an InnerClass"; }
    }I see two .class files: OuterClass.class and OuterClass$InnerClass.class
    Why make up examples like this? It's hard enough writing code, and it's easy to disambiguate for the compiler.

Maybe you are looking for

  • Cinema display does not always wake with MacBookPro Retina

    I have a MBP Retina display and often use Apple 23" Cinema Display, with the rMBP closed, not running both displays. Sometimes the display is slow to come on, but will with a bit of prompting through hitting the esc key (USB keyboard) or my blue toot

  • Quicktime will not download and install

    I had to reinstall windows and all of my programmes i just downloaded the newest iTunes but Quick time appears not to intall along with it. i tried intalling the stand alone quicktime but all i got was the picture viewer.. Am i missing something wher

  • Programming a c application which is calling a *.so built by LabVIEW.

    Hello all, This question probably has been asked, but I can't find the answer.  So here's my question: I have built a LabVIEW *.so in Linux and I want to call it from a "c" application.  The LabVIEW *.so is returning a cluster of strings and I want t

  • Watch TV In which way?

    I wanna ask from all of you, that in which way, You like to Watch TV, If you wanna watch tv online or you still used to watch tv with the cable connection?

  • Color trouble

    I have a Toshiba model # 23HLV86 and the I am having color and picture issues. When the tv is initially turned on~sound is fine, but there are stripes all over the screen so the picture isn't visible. After a few minutes the stripes go away or are ju