How To Make A Model Of Solar System - Have Sun And Earth Revolving Around It
Oct 25, 2014
I'm attempting to make a model of the solar system. Up till now, I have a Sun and the Earth revolving around it. The problem I have is when I add inheritance to the program. The moon that I created does not orbit the Earth.
Here's my code for the classes I've created
public class Driver {
public static void main(String[] args){
SolarSystem model = new SolarSystem(700, 700);
/* Create new instances of each object in the solar system */
SunObject sun = new SunObject();
PlanetObject earth = new PlanetObject(140, 30, 15, "BLUE", 2);
MoonObject moon = new MoonObject(15, 30, 2, "WHITE", 1.5);
[Code] ....
Note that SolarSystem is a class given to me. That contains all the paint methods. I'm just creating new instances with the drawSolarObject()
And the drawSolarObjectAbout takes an extra two parameters:
centreOfRotationDistance - the distance part of the polar co-ordinate about which this object orbits.
centreOfRotationAngle - the angular part of the polar co-ordinate about which this object orbits
I have a PlanetObject class:
public class PlanetObject extends PointInSpace {
private double distance;
private double angle;
private double diameter;
private String colour;
private double speed;
[Code] ....
And a MoonObject class, which is EXACTLY the same as the PlanetObject class. The main problem I'm having is when I extend my PlanetObject class to a PointInSpace class below:
public class PointInSpace {
private double distance;
private double angle;
public double getPointDistance(){
return distance;
[Code] .....
What I'm trying to do is use the distance and angle in the PointInSpace class so that my Moon can orbit those two coordinates . I get it working when I method override when drawing the moon - using earth.getDistance() instead of earth.getPointDistance() etc. Have I inherited properly? Should I try a method overloading process instead?
View Replies
ADVERTISEMENT
Dec 5, 2014
Below is all the coding I have done trying to make my own Powerball input system. I am really struggling on how to fix this. I keep getting an ArrayOutOfBounds exception except, I don't know how to fix this to make it where it will check the numbers without screwing up with everything.
Java Code:
import java.util.Scanner;
public class PowerballTest
{
Scanner input = new Scanner(System.in);
public static void main(String[] args)
{
Powerball.readInput();
Powerball.writeOutput();
[Code] ....
This is the problem i keep seeing when the test run happens :
Enter the first Powerball number which should be greater than 0 and less than 60
2
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
at Powerball.checkNumber(Powerball.java:73)
at Powerball.readInput(Powerball.java:23)
at PowerballTest.main(PowerballTest.java:9)
(Don't know if should have formatted that^)
View Replies
View Related
Oct 24, 2014
I want to create a program where i can output a number. ex. 3452 And the program will output 3000: three thousand 5: five 53: fifty-three
How can i make the program understand the 10-number system?
View Replies
View Related
Apr 20, 2014
I am trying to make a custom texture system for a block in Minecraft, I am not too advanced with Java and am not sure how to make this work the way I want it to.
/** The list of the types of step blocks. */
public static final String[] blockStepTypes = new String[] {"stone", "sand", "wood", "cobble", "brick", "smoothStoneBrick", "netherBrick", "quartz"};
private Icon missing;
private Icon icon1;
/**
* From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
*/
[Code] .....
Alright, so basically I figured I could just tell the code to see if the block is made out of Stone, then to set the texture to Stone, or if it's made out of Sand, then set it to Sand.
What I usually get is Eclipse telling me to "insert '!= null' check", "insert '!= null' check", and then just error out saying "Opperator != is undefined for the argument type(s) boolean null"
Is there any way I could make this work for me? Maybe some other way to make it do what I am trying to do?
View Replies
View Related
Jan 24, 2014
How can i use multiple textures on a model? I have the .OBJ loader and .MTL loader and everything is working fine. I can use a single texture. But i have a model that has 2 textures. How can i use both of the textures?
View Replies
View Related
Oct 13, 2014
Boolean retrieval model using skiplist. I don't know how to code it. I have modified it but I'm not sure it work out. What are the modifications I can made.
/**My requirement is to implement two methods for Boolean Retrieval:
● index(String dir)
○ index()supposed to go over all files under "dir". There will be no subdirectories inside it.
● retrieve()
○ retrieve() supposed to return name of all the documents under "dir" that satisfies the given query. Note that, only basename of the files are to be returned, not the full path.
○ Query can be of two forms:
■ OR: returned doc should contain at least one term from the query.
■ AND: returned doc should contain all the terms from the query. **/
import java.util.HashSet;
import java.util.Vector;
public class BooleanRetrievalModel implements DocSearch {
// begin private class
private class SkipList {
// Node in skip-list
[Code] ....
View Replies
View Related
Apr 11, 2015
I have some paired values stored as a hashmap in my model, for example sake, we'll say the 'key' is a Manager's ID and the 'value' is the name of their department, so 'betty123' could be a key to a value 'IT', and 'dave345' could be a key for the value 'Finance'. This hashmap is populated from a database. In my form, I have two "Select" dropdown fields, one for "Department" (with fields which match the values in the hashmap), and one for "Manager ID". I want to autopopulate the "Manager ID" field when the "Department" field is changed, based on the values in the Hashmap. I understand that I can't access dynamically elements of the hashmap in a script, so, for example, I can't do this:
var specificDepartment= $("#department");
var managerId = ${departmentHash[specificDepartment]};
$("#manager").val(managerId);
Because this code is dynamic based on the value of "department" at the time it's run, whereas the departmentHash object is generated when the page is loaded.
Is there some other way I can do this? Am I approaching it the wrong way? FWIW, I'm using Spring 4.1.1 and jQuery 1.8. I understand the conceptual block with code I wrote above, but I can't for the life of me think of an obvious solution although I'm sure this is a fairly commonplace problem in web development.
View Replies
View Related
Sep 23, 2014
I understand how vectors work I'm currently using one to store my id's from my txt file but how do you put them in a defaultComboBoxModel?
DefaultComboBoxModel defaultComboBoxModel = new DefaultComboBoxModel();
//declare a vector object that will hold a string (only thing that works with comboboxmodel
Vector<String> myVector=new Vector<String>();
//try statement
try{
FileReader fr = new FileReader(file);
[Code]...
Any example of how a vector is used with a defaultComboBoxModel so I can then use that to populate my JComboBox?
View Replies
View Related
Nov 14, 2014
public PurchaseTableModel() {
try{
//establish connection
conn = DriverManager.getConnection("jdbc:odbc:SupplierDS");
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
[code]....
I get the value from database and display in table , price value will show 6 decimal and date value will show date and time.What to do to show only 2 decimal places and only date e.g. 1/1/2014 in the table ?
View Replies
View Related
Dec 18, 2014
I have 2 different bespoke table models.
When one is needed I simply add it to the table. In this case however whilst updating the model via table update in tableChanged method I have the impression of 2 identical models because the update happens twice (use of audio).
Is it not true that adding a new model cancels out the other ? I test for which model is attached to table and add the correct one depending on the data required.
assert (!(this.getTableModel() instanceof KeywordBeanTableModel));
this.initKeywordBeanTableModel();
View Replies
View Related
Oct 11, 2014
/*
*
* You need to implement BooleanRetrievalModel using SkipList.
* You should have everything within this file.
*/
import java.util.HashSet;
import java.util.Vector;
public class BooleanRetrievalModel implements DocSearch {
// begin private class
private class SkipList {
// Node in skip-list
[Code] ....
View Replies
View Related
Oct 1, 2014
I want to create a new instance of a Java model class for each new request coming to a servlet.
How to do that without doing that in doGet() or doPost().
View Replies
View Related
May 6, 2014
I am working on an project in which some data needs to be received through socket , do some processing on it and then store on the database. After that it will display on GUI. GUI should be updated automatically.
I am able to implement basic model in which data is storing in the database and displayed then on the GUI. I tried to implement MVC design patter as well.
Now i need to create a GUI which can be used by several users at a time means several jvm session for the GUI. I got struck at this point.
Some detail: i have one jvm session in which i am receiving , processing and storing the data. Now i want to fire an alert whenever any new entry is made into the database. Also each time new GUI is opened it should be registered with the model so that model send updated data alert to all this users.
When i am trying to open several GUI and trying to register with the Model then it is not increasing count of registered user. For each time it is showing 1 count only and whenever a new entry is made count is showing 0. Is it because both are running in different jvm sessions ?
Some code for the model which is running in different package and jvm
GUI..
private void runApp() {
//some gui code
WindowListenerClass windowListener = new WindowListenerClass(this);
frame.addWindowListener(windowListener)
//registering viewer with the model
Model.setNewAlarmEvent(this);
tableModel = windowListener.getDefaultTableModel();
[Code] .....
View Replies
View Related
Sep 9, 2014
I'd like to create my own Table Model to handle data from an SQLite database using JSwing, but I'm having difficulty. How to confirm the following:
-- A table model is an object that contains methods for manipulating data in the table, right?
If that's the case, then how should I create a Table Model to handle data coming from a database. From what I understand...
My custom Table Model needs to subclass AbstractTableModelI then override 3 methods from AbstractTableModel (getRowCount(), getColumnCount(), getValueAt())
As it relates to drawing data from a database, how should I be thinking about this problem (i.e. creating a Table Model that can work with a database)?
View Replies
View Related
Mar 12, 2014
Here is a link to the program: [URL] ....
I am trying to model a galaxy so that I have multiple stars certain distances away from each other and with different masses.
The accretion and than cylinder expansion happens with just about every galaxy.
I have a few questions.
First My computer only runs this if the number of particles is in the 500s. If that's the case How can I increase the probability that I will when I get to it have a red giant?
Second how can I modify this so that I have a timescale during which white dwarfs form from some stars and you see in the single stars either no supernova or nova just degeneration or a type 2 supernova and in binaries a type 1a supernova which is like a type 2 supernova of 1 star when it is a red giant, that giant becoming a white dwarf, the other star becoming a red giant, and then the white dwarf sucking gas from the giant until it explodes and ejects its companion?
Third how can I make this compacted and taking up less space in case I want to expand it to a few galaxies or even start with a big bang?
Basically what I am asking is how can I make this like a universe?
View Replies
View Related
Jan 16, 2014
I have a AbstractTable and would like to import a txt file into it. I know how to do it for a Default Table but I am not allowed to use it.
// Import Filechooser
public static ActionListener importChooseFileButtonListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser jfc = new JFileChooser();
int returnVal = jfc.showOpenDialog(jfc);
ImportPopup imp = new ImportPopup();
[Code] ....
What do I have to do to import the file into the table?
View Replies
View Related
Dec 11, 2014
I have a requirement where we have an ETL jobs that runs in the backend which will get the up to date data from various sources , here we have both structured and unstructured data and the data capacity is massive which is in petabytes. Based on the data that is fetched we need to come up with a consolidated data view for the data which we retrieved. My queries are:-
1) How to create a consolidate data view , in what form it will be in (XML, JSON, etc)? whether we need to come up with a unified data model as the data is both structured and unstructured format? If so how we can go about it?
2) Since the data is really massive, how we can construct the consolidate data view? whether we need to create it in small chunks or whether we need to store these data in a cache or DB from where we will retrieve it and form the consolidated data view?
3) To process these data whether we need to have any Hadoop clusters to process these data parallel? As we are talking about massive data in the form of structured and un structured format?
4) Whether there is a need for NoSQL database to support unstructured data? If we are supposed to store the data?
View Replies
View Related
Jul 16, 2014
I have tried to implement MultipleSelectionModel with mostly success in TreeView, but definitely with quirks. I've looked at the implementation in TreeView and it's off putting to say the least. Hopefully it doesn't need to be that complicated. For now, all I need is it to handle SINGLE SELECTION, but it needs to be solid. I've put in a lot of println's to see what gets called. Most don't seem to be called. I'm relying on TreeView to look up the object being selected, I'm not sure if that's appropriate. The internal implementation seems to worry about tree state a lot.
It baffles me as to why there isn't a base class from which to extend or reuse? I'm doing this so I can delay a selection (make it vetoable), also to handle drag/drop more cleanly (so target won't move because of drag action).
private class VSelectionModel extends MultipleSelectionModel {
List<Integer> baseSelectedIndexes = new ArrayList<>();
ObservableList<Integer> selectedIndexes = FXCollections.observableList(baseSelectedIndexes);
List<Object> baseItems = new ArrayList<>();
ObservableList items = FXCollections.observableList(baseItems);
[Code] ....
View Replies
View Related
May 29, 2014
I have seen in some examples like URL... a good design is to have the model and the action methods in one just single bean and the model not to be a separated class but a few properties like this:
public class CustomerBean implements Serializable{
//DI via Spring
CustomerBo customerBo;
[b]public String name;[/b]
[b]public String address;[/b]
//getter and setter methods
[code]...
Some questions:
1. If you are using hibernate or any other ORM like the above example(URL...), why not to use the hibernate pojo bean directly like it represented the form instead of using properties?:
public class CustomerBean implements Serializable{
//DI via Spring
CustomerBo customerBo;
[b]Customer customer;[/b] //represents the properties of a form
//getter and setter methods
public void setCustomerBo(CustomerBo customerBo) {
this.custom
2. Why is it said that JSF represents the purest MVC? Spring separates the model from the view too and Struts does too. I dont really understand it
View Replies
View Related
May 24, 2014
This is a design question is the same problem in any language.as you do to map the controller to the domain model?We have situations in general larger than ... consider the example objects .
situation.1 - We have a request that has all the parameters of the account ;{ " id" : " 1 " , "name " : "test " , "some " : " xxx " } ............. and other fields .
situation.2 - can request that has to have a certain account parameters , for example in the case of an update;{" id" , " 1" , "name " , " testUpdated "}
situation.3 - We have a request that has some parameters of the account , others have more like id as user together;{ " id" : " 1 " , "user " : " xxx " , "service " : " yyy " } in which case each piece of the request will turn an object .
Java Code:
public class Account {
private Long id;
private String name ;
private String some ;
} mh_sh_highlight_all('java');
I see a few options ;
1 - Can I get AccountForm in the controller and set the properties for the Account object and others in CONTROLLER ;
+ ok for situation.1 situations 2, and situation.3
+ Separates the requisition of the object domain
- Pollutes the controller with code conversion
- Controller is full of setters .. if a higher class as a large object as a request is very confusing .
Java Code:
controller ( AccountForm from ) {
Account account = new Account ( )
account.setNome form.getNome = ();
account.setSome form.getSome = ();
Other outher = new Other ( ) ;
other.setSome ( form.getSome ( ) ) ;
} mh_sh_highlight_all('java');
2 - Can I get AccountRequest in the controller and have a method in itself as AccountRequest.getAccount ( ) to return a mapped model , in this case the mapping is at own Request object .
+ Separates the requisition of the object domain
+ Encapsulates the conversion in a place with easy access .
+ Meets situation.1 situation.2 and situation3 ;
- Request object has two responsibilities represent the request and map to a valid model .
Java Code:
controller ( AccountForm accountRequest ) {
Account account = accountRequest.getAccount ( ) ;
Outher outher accountRequest.getOther = ( )
} mh_sh_highlight_all('java');
3 - Can I get the controller Direct Account which had been filled with nulls .
+ Eliminate object request
- Serves only situation.1 situation.2 .
Java Code:
controller (Account account ) {
account.someMethod ();
} mh_sh_highlight_all('java');
4 - Outsource this mapping request parameters to another object mapper for request ..
+ Isolates logic mapping
- Until complexity for simpler cases are used as standard for all such a find by id .
- One more class for each request ;
In the case of API gets worse response has two further classes. speaking in terms of request for response .... AccountRequest, AccountRequestMapper, Account, AccountResponseMapper, AccountResponse .....I'm doing more testing the Hybrid option 3 for simple cases (find ID or updates) .... with option 2 for example for more complex cases ..
View Replies
View Related
Aug 11, 2014
I am making an application in which I have to make the model (the services) available to the entire application so that all beans can access it and call its methods during the life of the application.
I am using the following technologies:
view: JSF 2.x
beans: Spring 4.x beans
The design problem I am having is the following:I came up with the idea of registering the model services as ServletContext attributes using my ServletContextListener, effectively making the services available to the entire application:
//imports
public class MyContextListener implements ServletContextListener {
//model services
private UserService userService;
private RepairService repairService;
public void initCafe()
{
userService.removeAllUsers();
repairService.removeAllRepairs();
[code]....
Shouldn't I just use @Autowired userService and @Autowired repairservice everywhere I want to use these services application-wide?Or is this a problem because beans have a default scope of Request? I am confused.
View Replies
View Related
Jul 2, 2014
I have been going in circles trying to update a JTable. For now I just need to take input from a textfield after clicking on a JButton and have that text be placed in the JTable. LeftPanel listens, while RightPanel holds the table. Here is what I have so far:
package reminder.views;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class LeftPanel extends JPanel {
]Code] ....
View Replies
View Related
Dec 8, 2014
Sometimes models needs to access blocking devices, like network cards, databases, files, and so on. This should be done by worker threads or services. But who is in charge of that? The controller or the model itself? I tend to say it is the model, as only the model knows about the fact that it accesses a blocking object. On the other hand, it is said that a model should be a POJO, so it would be the controller's job. Is there a best practice or general design rule?
View Replies
View Related
Aug 26, 2014
What is the best way to synchronize a Model representing a complex UI composite w/ a FlowPane's backing list?
Currently I have a change listener on the Model. Upon an add I create a new UI composite and manually add it to the FlowPane's backing list via flowPane.getChildren().add(). Similarly if there is a remove, I iterate over the FlowPane's children, grab the right Node, and remove it. Similarly, if there is a modification detected, I iterate over the FlowPane's children, grab the right Node, remove it, recreate the UI composite, and re-add it to the list. I also need the list to be sorted, so I implemented a UIComposite comparator and call FXCollections.sort() on the FlowPane's backing list. I feel like that is hacky, but it works. It would be cool if I could maintain sort order in my model somehow and have that automatically propogated to the FlowPane's list.
I am correct in assuming that there is no way to have a complex binding in between an ObservableList<CompositeViewModel> and the FlowPane's backing list (ObservableList<T>)?
Some kind of translator that could create a new UIComposite whenever there is a new CompositeViewModel added to the Model list.
View Replies
View Related
May 8, 2014
We are making a tic tac toe game for my CS120 class and I am having trouble figuring out how to make our X's and O's. Is there a way to make shapes besides making two lines for an X and an oval with a white smaller oval inside to make an O? We have only learned the basics so far in class (i.e. events, inheritance, client-supplier, etc.)
These are our instructions:
Write a controller that controls the game. There is one human player (the X player) and the computer player (the O player). The name of the class must be TicTacToeController. In a sense, the controller is the game since the controller will 1) create a TicTacToeModel 2) create a TicTacToeView and 3) create a TicTacToeButton (you must write this class following the design pattern covered in class lectures), a label, and text field such that when the button is pushed, the player moves into the cell selected by the text field. After every player move, the computer moves into a randomly selected empty cell. When the game is over, a text message must be displayed somewhere on the screen the gives the status of the game. While you are free to change the appearance of the controller, the basic elements must be provided (a view of the game, a button, and a text field to enter the cell). A sample screenshot is displayed below.And this is the code i have thus far:
[import java.awt.*;
import javax.swing.JFrame;
public class TicTacToeView extends Rectangle
public TicTacToeView(int x, int y, int w, int h) {
super(50,60,w,h);
this.setBackground(Color.red);
JFrame win = new JFrame("Tic Tac Toe");
win.setBounds(10,10,w+100, h+100);
win.setLayout(null);
win.setVisible(true);
win.setBackground(Color.gray);
[code]....
View Replies
View Related
Feb 25, 2015
I have the Java Development Kit downloaded in my C file and my book tells me to compile the program I need to open command windowand change the directory where the program is stored. I tried the command cd to change directory and received this message "The system cannot find the path specified."
I checked the Environment Variables on Windows 7 and the Path says: C:Program Files (x86)Javajre1.8.0_31in
This is after many tries and i still can't change directory and i keep getting the same message.
View Replies
View Related