How To Have Multiple Classes But Only One Main Method

Nov 1, 2014

I was reading the book, "Head First Java" and it was talking about how there may be multiple classes in a large application, but there will be only one main method.how does it work that way? How can you have multiple classes, but only one main method?

View Replies


ADVERTISEMENT

Calling Multiple Methods Into Main Method

Sep 30, 2014

This current one is to calculate a planes holding pattern. I have to write a method to prompt user to enter speed in knots, then it converts it to km/hr. Another method to calc. pattern width using the speed, another method to calc. pattern length, than a main method which would call and print out the speed in knots, speed in km, pattern width and length.My current problem is on the second method. It works in that I can enter the values and it gives me the correct answers, however it's asking me to enter the speed twice, instead of just once. Anything I try just results in errors and won't compile.

import java.util.Scanner ;
//main method
public class TitleRemoved {
public static void main(String[] args) {
double airSpeedKm = airSpeedOts () ;
System.out.println("That speed is " + airSpeedKm + " km/hr.") ;

[code].....

I want my code to not only work, but be organized and easily readable as well, so I want to avoid bad habits.

View Replies View Related

How To Draw Multiple Graphics Inside One JPanel Using Multiple Classes

May 5, 2015

I'm very new to Java, and I am creating a program that takes multiple user input to create one face. I have a class for the eyes, nose, lips, and headshape. For some reason, my program is not drawing the graphics. ***for question purposes, I have only included my head shape class and my test class****

my "test" class:

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class FaceTest
{
public static void main(String[] args)
{
String head = JOptionPane.showInputDialog("Would you like a circle, square, rectangle shaped head?: ");

[Code] ....

View Replies View Related

Calling Classes Within Main

Apr 17, 2014

How do I call a class within the main. For example, this is what i have in my code right now. I am trying to call the class BlackJackGame.

package blackjack
public class BlackJack {
public BlackJack() {
BlackJackGame();
}
}

View Replies View Related

No Main Classes Found

Dec 6, 2014

Spoiler

import java.applet.*;
import java.awt.*;
public class JhonnyBravo extends Applet {

/**
*
* @param g
*/
@Override
public void paint(Graphics g) {
Color skin = new Color(241, 210, 169);

[Code] .....

View Replies View Related

How To Open Files When In Classes Instead Of Main Code

Mar 18, 2014

I have looked over other people code relating to files that are related to my actual studies in class. My teacher hasn't worked on a lot of file problems so I want to gain some understanding on it.

1.) I have this class with variables declared

import java.io.*;
public class FileDisplay {
private String filename;
FileWriter outputfile;
File Inputfile;

I'm aware that having a private variable would not allow that variable to be accessed outside the code. Vice versa, public variable would do that. The FileWriter and the File Inputfile is something I don't understand, especially have them in classes. What is the purpose of them?

2.)

public class FileDisplay {
private String filename;
FileWriter outputfile;
File Inputfile;
 
[Code] ....

I have made this code here that opens the output and input file. If I make another method, how would I display the text onto that same file. Hard to clarify for me, but in each method do I just keep creating :

FileWriter outputfile=new Filewriter(filename)

View Replies View Related

Eclipse IDE - 2 Classes And Exception In Thread Main

Aug 31, 2014

I use Eclipse IDE

public class Emp {
 private String name;
private String jobTitle;
 public void setName(String nameIn){
name=nameIn;

[Code] ....

<terminated> TestClass
Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Unknown Source)
at TestClass.payOneEmp(TestClass.java:21)
at TestClass.main(TestClass.java:13)

View Replies View Related

ArrayList Through Multiple Classes?

Oct 25, 2014

I have to make a retail item class that has description, price and quantity. I then have to make a CashRegister class that calculates subtotal, tax, total and displays it (toString). I also have to make a driver class to call the methods from main. I have no clue what I am doing and what I have done does not work. I am trying to make it sort of like a cart, in the CashRegister it should ask the user to enter the description, quantity purchased and the price. Then it would send that to the arraylist of retailitem. I am having trouble using those items in my other methods and then do not know how to call those in the driver class.. So here are my classes:

public class RetailItem {
private String description;
private int quantity;
private double price; 
public RetailItem(){
description = "";
quantity = 0;

[Code] ....

View Replies View Related

Creating Multiple Classes

Apr 25, 2014

I was trying to play around a little bit after learning creating multiple classes and stuff.However,i encountered a strange problem with reading a value from the user and then storing it in a variable.The usual way i do it is

Scanner variableName=new Scanner(System.in);
System.out.println(variableName.nextLine());

But when i trying to print the contents of the variable "variableName" the compiler throws a lot of errors .I am attaching how i have tried that out in my code

import java.util.Scanner;
class laptop{
private String modelNumber;
private boolean hasFan;
private float ramSpeed;
protected int numCores;
//private String input;

[code]....

Without the setInfo() in the laptop class the program functions as desired but i intend to ask the user if he wants to modify something and then reflect the same.

View Replies View Related

Using Multiple Classes In One File

Mar 1, 2015

I have recently start learning about objects and classes in java. I understand that in order to use multiple classes in one file you need one class to be public and the rest are private. But after that I don't understand how to invoke the private class in the public class. I thought if I tried programming on my own I can have a better understanding of it, but had no success.

View Replies View Related

Multiple Classes In One Package?

Jan 31, 2015

I'm having problems with this I've code like:

Java Code:

Public Class{
Objects
Constructor(){}
ActionListener Method(){}
Main Function()}

[Code]....

but I cannot declare variables in this method, how can I do this what can be the simplest method?

In addition: I've a marksheet class, a calculator class, & in main class I've 2 buttons one for marksheet & one for calculator, how can I make it so that if user clicks on marksheet button that class should be called & so?

View Replies View Related

ArrayList Through Multiple Classes

Oct 25, 2014

Alright.. So I have to make a retail item class that has description, price and quantity. I then have to make a CashRegister class that calculates subtotal, tax, total and displays it (toString). I also have to make a driver class to call the methods from main. I have no clue what I am doing and what I have done does not work. I am trying to make it sort of like a cart, in the CashRegister it should ask the user to enter the description, quantity purchased and the price. Then it would send that to the arraylist of retailitem. I am having trouble using those items in my other methods and then do not know how to call those in the driver class...

So here are my classes: [URL] ....

View Replies View Related

How To Map Parameters From Multiple Classes Into One Set Of Parameter

Mar 6, 2014

I have multiple Java classes that holds lots of time based parameters, e.g.: (simplified):

Java Code: class Engine {
float rpm;
boolean enabled;
int runningTime;

[code]....

Is there any simply solution to map all these parameters from my TimeRecord to one list(vector,map) of params that user can choose from and see the value in proper form (floating type, boolean type) ?

I just want that user can pick a paremter's name from list or combobox and choose parameter that he wants to see. I don't want to duplicate the data - just some kind of mapping algorithm between list of parameters names and my TimeRecord. eg. some collection class that holds all names and connections: Parameters params; fill combo/list from this class for ( String name : params ) { combo.add(name);}, then when user picks some field from combo: params.getValue( myTimeRecord, name ) return correct parameter value (just my first thought)

Later, I want to replace all floats,ints,booleans with some kind of templated class eg. Value which will hold all kinds of measurement unit with conversion support - but it's only a plan now.

View Replies View Related

Connecting Multiple Classes In Same Package

Jan 16, 2015

I have multiple classes in one package and was wondering how to I use one class while in another?

What I mean is I have one sheet with a class and another sheet with another class. (Separate tabs in Eclipse).

View Replies View Related

Swing/AWT/SWT :: Splitting GUI Into Multiple Classes?

Sep 12, 2014

I'm trying to create a Java swing chess application, but would like to divide the GUI part of it into at least two different classes (possibly more later, but I'm not sure yet). Currently I have a mainGUI class and a ChessBoard class, both of which extend JFrame. I want the main GUI class to contain a JPanel which will house several components, including a JPanel originating from the chessboard class that contains the actual board.

Is there any way to do this? I tried just creating a ChessBoard object in my main GUI class and then adding it to the component, but I got an illegal argument exception, because apparently you can't add one JFrame to another. How to do what I'm trying to do, or just how to split GUIs into multiple classes in general?

View Replies View Related

When To Use Multiple Main Methods

Apr 7, 2014

I am confused when it is proper to use an application with multiple entry points, or I guess an application with multiple interconnected modules. I have a network application (Netty) as well as a web application (spring). I can bundle them together, in effect tightly coupling them together, or I can modularize them to operate interdependently of each other while still working together to make the application whole.

Is there any specific reason for making an application a single entity vs multiple entities? Is it "desired" to have a self contained application (eg. One main method)?

View Replies View Related

Java Does Not Support Multiple Inheritance Using Classes

Aug 16, 2014

I studied that java does not support multiple inheritance using classes. It is fine practically, but I have still a question in mind:Lets see the below code.

class Test{
------
------
}

class MyTest extends Test{
---------
---------
}

Here, as we know that that Object is Super class for every class in java. and I have already extends a Test class in MyTest.My question is: How is it possible to extend features of two class at the same time?

Theoretically,

MyTest extends Object &
MyTest extends Test.

View Replies View Related

How To Return Array From A Method / Back Into Main Method That Prints Out Stuff

May 27, 2014

I'd like to know how to return a new array, I wrote in a method below the main method. I want to print the array but system.out.print doesn't work for arrays apparently. What structure i should use?

View Replies View Related

Writing A Method That Returns Words Without Four Letters Back To Main Method

May 27, 2014

I have to write a method called censor that gets an array of strings from the user as an argument and then returns an array of strings that contains all of the original strings in the same order except those with length of 4. For example if cat, dog, moose, lazy, with was entered, then it would return the exact same thing except for the words with and lazy.

Currently, my code so far just prints [Ljava.lang.String;@38cfdf and im stuck.

import java.util.Scanner;
 public class censorProgram {
public static void main (String args[]){
Scanner input = new Scanner (System.in);
System.out.println ("How many words would you like to enter?");
int lineOfText = input.nextInt();
 
[Code] ....

I have to make new string array in the method and return words without four letters in the main method

View Replies View Related

How To Call A Method That Exist Within A Class Into Main Method

Feb 13, 2014

I am just trying to test this array, for a locker combination program that involves classes...but the array is printing out the whacky numbers for the location. When I try to call the method in the main, it does not work. How do I call a method that exist within a class into the main method?

public class locker { 
public static void main(String[] args) {
CombinationLock();

[code]....

View Replies View Related

Possible To Check If Classes Contains A Specific Method And Then Run That Method?

Oct 5, 2014

I'm working on a simple 2D Game Framework. Currently it's creating a window, but I'm working on an update method.

I constantly export the framework as a .jar file, and I've added it to the game's build path (using eclipse). I wonder if I can check all classes in the game-project (the project in which I've refecrenced the Framework in) for a specific method (for example update()) and call all found methods with that name from the framework's main class, like this:

public class FrameworkClass1 {
  private void checkForUpdateMethods() {
// Check for update methods on program start
} public void update() {
runAllFoundUpdateMethods(); // Run all update methods found in the scan
}
}

I want to do this because it would be a simple way to update and render the game. If the main game-class look something like this:

public class Game {
public void update() {
// Update the game every time this is ran
}
}

it will be automatically updated, because it contains a method named update(), instead of naming the main game-class with a specific name etc. It will simply be more flexible that way!

View Replies View Related

Main Method Separated From Other Method

Jan 13, 2014

Here's a class called Fibonacci

Java Code:

public class Fibonacci {
public static int fib(int n) {
if (n < 2) {return n;}
else {return fib(n-1)+fib(n-2);}

[code]....

it contains one method called fib() and one main method.If I would want to have the main method in another class than fib(), how would I write the two classes? Only cutting the main method from this class to another one doesn't work.My question is, is the reason it doesn't work because I then would have to have a constructor in the Fibonacci class, and create a Fibonacci object first which I then use the method on?

View Replies View Related

How To Call Method Without Using Inner Classes

Jun 9, 2014

How do i call the method without using inner classes in this example:

jt = new JTable (model) {
public boolean isCellEditable (int row, int col) {
if (col == 5) {
return false;

[Code] ....

View Replies View Related

No Main Method?

Jul 23, 2014

I'm trying to make a TBG (Text Based Game) in Java for Android. Now, when I try to run it, it says No Main Method to run this program. The compiler also checks the program and tell me there are no errors.

View Replies View Related

Outputting 2 Classes - ToString Method

Apr 22, 2014

My current assignment involves me outputting these 2 classes. Yet I'm not really sure in what manner I should go about doing this. I have tried creating a separate class and outputting my toString methods there but for some reason I am getting an error. .

The error message is thus;

Exception in thread "main" java.lang.NullPointerException
at Vehicle.toString(Vehicle.java:91)
at Run.main(Run.java:17)
 Process completed.

import java.util.Calendar;
public class HireContract {
String reference;
Calendar startDate = null;
Calendar endDate = null;
Vehicle vehicle = null;;
String customerRef;
double rate;

[Code] .....

View Replies View Related

Parent / Child Classes - Set And Get Method?

Jan 25, 2014

I have been working on a simple problem, but I am stuck. I am trying to learn parent and child classes and how they work. The program in broken into three classes; the DemoBook class that runs the various methods, the Book class that gathers information and displays it, and finally a child class of Book (called TextBook) that just gets one piece of data and then is suppossed to return that data back to Book. However, this is not working and I know I am missing something; I believe it has to do with Set and Get methods, but I am confused with how these work.

Java Code:

public class DemoBook
{
public static void main (String[] args)
{
Book aBook = new Book();
Textbook aText = new Textbook();

[Code] .....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved