How do you call classes that is created by the programmer.

how do you call a class in java program? I am creating a program that

Page 1 of 1

1 Replies - 1500 Views - Last Post: 13 December 2009 - 08:45 PM Rate Topic: -----

#1 shariqnaqvi86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 13-December 09

How do you call classes that is created by the programmer.

Posted 13 December 2009 - 03:56 PM

How do you call classes that are created by the programmer. This is just one of my classes. I just want to create a class that calls the classes i have created. Can I see some sample coding and algorithm.

import java.util.*;

public class firstadd {
/**
* @param args
*/
public static void main(String[] args) {
Random rnd = new Random();

int num1 = rnd.nextInt(10); 
int num2 = rnd.nextInt(10);
Scanner sc = new Scanner(System.in);
System.out.print(num1 + " plus " + num2 + "= ");
int result = sc.nextInt();
if(result == (num1+num2))
System.out.print("You're correct!");
else
System.out.print("You're wrong!");
}

} 


this is my second class
import java.util.*;

public class firstsubtraction {
/**
* @param args
*/
public static void main(String[] args) {
Random rnd = new Random();

int num1 = rnd.nextInt(10); 
int num2 = rnd.nextInt(10);
Scanner sc = new Scanner(System.in);
System.out.print(num1 + " minus " + num2 + "= ");
int result = sc.nextInt();
if(result == (num1-num2))
System.out.print("You're correct!");
else
System.out.print("You're wrong!");
}

}


*** MOD EDIT: Added code tags. Please :code: ***

This post has been edited by JackOfAllTrades: 13 December 2009 - 04:11 PM


Is This A Good Question/Topic? 0
  • +

Replies To: How do you call classes that is created by the programmer.

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: How do you call classes that is created by the programmer.

Posted 13 December 2009 - 08:45 PM

the main() method is used toi test a class

class Dog {
   int age;

   // constructor
   Dog(int age) {
	   this.age = age; 
   }

   int getAge() {
	   return age;
   }

   // to test my class
   public static void main(String[] args) {
	   Dog fido = new Dog(5);
	   System.out.println("Fido age is: " + fido.getAge());
   }
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1