creating class and methods 1 Answer(s) 3 years and 6 months ago
Posted in : Java Beginners
View Answers
December 22, 2009 at 12:16 PM
Hi Friend,
Try the following code:
import java.util.*;
public class Computer{ static String name; static int size; static int speed; static String make; static double price; static int quantity; public Computer(String n,int s,int sp,String m,double p,int q){ name=n; size=s; speed=sp; make=m; price=p; quantity=q; } public String getName(){ return name; } public int getSize(){ return size; } public int getSpeed(){ return speed; } public String getMake(){ return make; } public double getPrice(){ return price; } public int getQuantity(){ return quantity; } public void valid(){ if((price==0)||(price<0)){ System.out.println("Please enter price"); System.exit(0); } else if((quantity==0)||(quantity<0)){ System.out.println("Please enter quantity "); System.exit(0); } else{ displayData(); } } public void displayData(){ List<Computer> list = new ArrayList<Computer>(); list.add(new Computer(name,size,speed,make,price,quantity)); for (Computer s : list){ System.out.println("Computer Name: "+s.getName()+ "\nRAM Size :"+s.getSize()+"\nProcessor Make: "+s.getMake()+"\nProcessor Speed: "+s.getSpeed()+"\nQuantity: "+s.getQuantity()+"\nTotal Price of Computers: "+s.getPrice()); } } public static void main(String[]args){ System.out.println("Enter details"); Scanner input=new Scanner(System.in); name=input.next(); size=input.nextInt(); speed=input.nextInt(); make=input.next(); price=input.nextDouble(); quantity=input.nextInt(); Computer c=new Computer(name,size,speed,make,price,quantity); c.valid(); } }
Thanks
Related Pages:
creating class and methods - Java Beginners creatingclass and methods Create a class Computer that stores... of the Computers.
This class contains following methods,
- Constructor method... ( ) method that creates array of 4 objects of Computer
class and that takes input
Creating methods in servlets - JSP-Servlet Creatingmethods in servlets I created servlet and jsp file.I Instantiated 3 objects and Defined 2 methods in my servlet, first method should write...;
/**
*
* @author mihael
*/
public class mlNewServlet3 extends HttpServlet
methods
methods PrintStream class has two formatting methods,what
methods
methods PrintStream class has two formatting methods,what
methods
methods PrintStream class has two formatting methods,what
Creating Class in JRuby CreatingClass in JRuby
 ...
that how one can define a class in JRuby and can define methods in class as well... will create a new
instance of Employee class . Now we can access it's methods
Java :Thread Methods
Java :Thread Methods
This section explains methods of Thread class.
Thread Methods :
Thread class provides many method to handle different thread... and allow other
threads the temporal executing thread object.
Some other methods
java object class methods
java object class methods What are the methods in Object class? There are lots of methods in object class.
the list of some methods are as-
clone
equals
wait
finalize
getClass
hashCode
notify
notifyAll
to create a java class and methods
to create a java class and methods How to create a java class without using the library class to represent linked lists of integers and also provide it with methods that can be used to reverse a list & append two lists.Also
creating a own interceptor - Struts
of defining the interceptor methods in the bean class.
For more information...creating a own interceptor
i want to create own interceptor
how i will create and which class i want implement Hi friend
what is class methods in objective c
what is classmethods in objective c What is classmethods in objective c? Explain the class method of objective c with the help of an example
what is class methods in objective c
what is classmethods in objective c What is classmethods in objective c? Explain the class method of objective c with the help of an example
creating web services - WebSevices creating web services Actually i am new for web services so Plz tell...
Project Name: WebServiceTutorial
Class Name:-Krishna
Method Name:-giveWishes... stopped publish Window
II. Steps for Creating Web Service
1.Create a new Dynamic
PHP list class methods
Function get_class_methods gives the all methods names of the given class.
It takes input as class name and returns the array of the methods name
PHP LIst ClassMethods Example
<?php
class myclass{
function aa
Static/Class methods
Java NotesStatic/Classmethods
There are two types of methods.
Instance... methods in the predefined Math
class. (See Math and java.util.Random... to specify the class where the
method is defined. For instance methods
using class and methods - Java Beginners
using class and methods Sir,Plz help me to write this below pgm. here is the question:
Assume a table for annual examination results for 10... the following code:
import java.util.*;
public class Student{
int rollNo
Abstract class,Abstract methods and classes
to implement the
methods inherited from the abstract class (base class...
Abstract methods and classes
 ... is used
with methods and classes.
Abstract Method
An abstract method one
Abstract class or methods example-1
;Animal class"); // this
// ...;form Animal class");
}
}
class ...;called form BuzzwordAnimal class");
}
 
Object Class Methods in Java
We are going to discus about Object ClassMethods in Java... or indirectly. There are many methods defined in java.lang.Object
class...(), wait(), etc
Java object classmethods are:-
finalize()
clone()
equals
Getting Methods Information of a class
Getting Methods Information of a class
 ... to retrieve information of all methods of a class (that included
in the program...; Class[] parameterTypes =
methods[i].getParameterTypes
Java GUI code- creating a circle
Java GUI code- creating a circle My assignment is to write a program...*;
import java.awt.event.*;
public class CircleGUI extends JFrame...;
JPanel pNorth, pWest, pCenter, pSouth;
//methods
Creating Bean Class In JSF using NetBeans Creating Bean Class In JSF using NetBeans
 ... illustrates how to create the Bean Class. This is also called
the Backing Bean Class. This bean class is used to store the values of the form
components
Overriding methods
,same argument and same return type as a method in the superclass.
class Animal... for grass");
}
}
class Cat extends Animal {
public void eat(String str) {
System.out.println("Drinking for milk");
}
}
class Dog extends Animal
programes on methods
function
write a program to concatenate two strings entered by user
design a class
Functions and Methods
the day number from the main class. The function uses a switch-case statement... and display it on console.
import java.util.*;
class CubeOfNumbers{
public... using switch case statement.
import java.util.*;
class FindDay
{
public
Functions and Methods
is equilateral,isosceles or scalene.
import java.util.*;
class TypeOFTriangle
class
medals. In this class, you should also define constructors, and assessor, mutator
methods.
Task 2
MedalTally.java is a class to model a medal tally, containing... is a class to represent a country in medal tally. It has an attribute of
country
Creating Views Creating Views
Struts provides their own JSP tag library for creating view... data by model and handle them appropriately. For creating a view you should... class LoginModel implements Serializable {
private String userId;
private
Creating Exception Creating Exception class Myexception extends Exception{
private int detail;
Myexecption(int a){
detail=a;
}
public String toString(){
return "Myexception["+detail+"]";
}
}
class Exceptiondemo{
static void Compute(int a) throws
Writing code with multiple Class Methods and String Arrays
Writing code with multiple ClassMethods and String Arrays So what I... input.
It has to have multiple classes so I will have a main class, and a class... it to do but I'm getting stuck on what to put in the main class "music.java
Writing code with multiple Class Methods and String Arrays
Writing code with multiple ClassMethods and String Arrays So what I... input.
It has to have multiple classes so I will have a main class, and a class....
That's all I need it to do but I'm getting stuck on what to put in the main class
Hibernate Creating criteria instance
Hibernate Creating criteria instance
In this section you will learn about the creating of criteria instance in Hibernate.
An instance of Criteria is created... a POJO/Persistent class to persist
the objects here I have created
new operator for creating the object of inner class
new operator for creating the object of inner class Hi ,
The folliowing is my code :
class Outer
{
class Inner{
void show... ");
}
}
}
class Test
{
public statis void main(String args
need help creating a lift program - Java Beginners
need help creating a lift program Classes, Methods, Constructors... an Elevator class containing various methods.
Then, write a program.... Invoke the various methods of the Elevator
class on these two objects
Class Class, Object and Methods
 ... the class,
object and it's methods. This program uses the several values.... Constructor initiates (initialize)
something related to the class'smethods
Java call method from another class
;
methods of another class. For this we have created two java files... methods inside the class MainClass, an
object of the CallingMethod
class... ClassName();
After creating object of CallingMethod.java
file class
Creating a JTable Component
. The TableModel interface uses the methods of JTable class that
integrates a tabular...
Creating a JTable Component
 ..., the procedure for creating a JTable component is given with the brief
description
Final Methods - Java Tutorials
. The final
keyword is a modifier means the final class can't be extended....
final classes
The class declared as final can't be subclass or extend. The
final class declared as follows :
public
final class
MyFinalClass
final
Abstract class or methods example-2
;defined in the non abstract class
}
abstract class ...;runLion1(); // defined in the non abstract class
factory methods in java?
factory methods in java? what are factory methods in java?
Hi Friend,
Factory methods are static methods that return an instance of the native class like Pattern.compile(), Calendar.getInstance
Call class methods
Call classmethods
This Example shows you
how
to call class method in velocity... through method init().
2: Create object of VelocityContext Class.
3
Graphics class
and imaging
methods in the Java 2 javax.swing.Graphics2D class.
There are also...
Java NotesGraphics class
Description
The Graphics class contains drawing methods.
A Graphics object is passed to your
paintComponent(Graphics g).
You
Callback Methods
Callback Methods
Callbacks methods are the way of managing life cycle of
an instance. Callback methods are generally used by containers. The methods are
called at specific time
Can I have multiple main() methods in the same class?
Can I have multiple main() methods in the same class? Hi,
Can I have multiple main() methods in the same class?
Hi,
No, We cann't use multiple main() method within the same class. If we do this then the program
Class
techniques. A class defines
the properties of objects and methods used.... A class defines the
properties of the objects and the methods used to control... class.
Now
we will learn, how to define a class having methods, objects
methods in the applet - Applet
provides the Applet class with default implementation for all the applet methods. You can implement these methods in the applet class when you want to override... the applet1 class to Applet class, therefore the methods are already