PDA

View Full Version : مجموعه برنامه‌ های نوشته شده به زبان جاوا



hossein71
جمعه 28 بهمن 1390, 08:09 صبح
سلام خدمت دوستان عزیز و مدیر بخش
به نظر من لازمه یک تاپیک در بخش تاپیک های اعلان شبیه بخش C++‎ ایجاد بشه که هرکسی هربرنامه‌ای با جاوا نوشته قرار بده.اگر چنین تاپیکی در بخش جاوا هست بهتره بصورت تاپیک اعلان در بیاد تا همه بتونن به راحتی بهش دسترسی داشته باشن.
بنده در جاوا تازه کار هستم.اولین برنامه(یا تمرین) خودمو که نوشتم براتون قرار میدم.

این برنامه یک عدد از مجموعه اعداد طبیعی را دریافت می‌کند و تمام اعداد اول که بین 1 و عدد گرفته شده قرار دارد را در خروچی چاپ می‌کند.
کلاس PrimeNumber:

import java.util.Scanner;
public class PrimeNumber {

public static void main(String[] args) {
Scanner input = new Scanner( System.in );
Search ObjectSearch=new Search();
System.out.println("What range number?");
int in=input.nextInt();
System.out.println(".................");
ObjectSearch.FindPrime(in);
System.out.printf(".............\nCount is %s\n",ObjectSearch.CPrime());
}
}

کلاس Search:

public class Search {
private int CountPrime=0;
public void FindPrime(int arg)
{
int Number[]=new int[arg];
for (int Count=2;Count<arg;Count++){
Number[Count]=Count;
}
for (int del=2;del<=(arg/2);del++){
for (int Count=del;Count<arg;Count++){
if (Number[Count]%del==0 & Number[Count]!=del)
Number[Count]=-1;
}

}
for (int Count=2;Count<arg;Count++){
if (Number[Count]!=-1){
CountPrime++;
System.out.println(Number[Count]);
}
}
}
public int CPrime()
{
return CountPrime;
}
}

تصویری از خروجی:

82798

82799

....................................
بعد از ویرایش:
دوستانی که از netbeans استفاده نمیکنند میتونند دوتا کلاس خودشون درست کنند و با توجه به کد برنامه نامگذاری کنند. سپس کدها رو داخل کلاس مربوطه کپی کنند.

spiderman200700
جمعه 28 بهمن 1390, 15:59 عصر
سلام به همه.
نظر من هم همینه.
همچین تایپکی برای بخش جاوا لازمه.
منم در خواست دارم که این تایپک به صورت اعلان در بیاد.
با تشکر

hossein71
سه شنبه 02 اسفند 1390, 19:20 عصر
ضمن تشکر از جناب spiderman200700 (http://barnamenevis.org/member.php?133001-spiderman200700) ولی انگار دوستان خیلی تمایلی به گذاشتن برنامه‌های خودشون ندارند.
لطفا دوستان برنامه‌هایی که نوشتند رو در این تاپیک قرار بدند(مخصوصا دوستانی که در جاوا دستی برآتش دارند).

maktoom
چهارشنبه 03 اسفند 1390, 01:30 صبح
سلام
با تجربیات قبلی در این موارد سایر دوستان منتظرن تا ببینن سطح برنامه هایی که بقیه میذارن در چه اندازس.
اونایی که مبتدی هستن احتیاط می کنن تا برنامه های زیادی ساده نذارن.
حرفه ای ها هم شاید می خوان حد و اندازه اینجا رو ببینن.
بهر حال اون تاپیک از سی پلاس پلاس برا این زود رشد کرد که یه عده نه چندان کمی که خیلی حرفه ای هم نبودن همه جور برنامه ای نوشتن.
من خودم واقعا ازون تاپیک استفاده کردم.

قرار هم نیست برنامه های خیلی حرفه ای بی مخاطب بمونه همونطور که برنامه های ساده بدون مخاطب نیستن.
چرتکه ها رو بذارید کنار.

clapton
پنج شنبه 04 اسفند 1390, 19:16 عصر
سلام دوستان.این ماشین حساب هست که اعداد رو در دو خط میگیره و عملگرها رو هم در چهار حالت اصلی جمع و تفریق و ضرب و تقسیم میشناسه.خودم نوشتمش .فکر کنم خیلی ساده اس اما امیدوارم بتونه مفید باشه
import java.util.Scanner;
public class Calculatrice {

public static void main(String args[]) {

Scanner hossein=new Scanner(System.in);
float num1,num2,result=0;
char x;
num1=hossein.nextFloat();
num2 = hossein.nextFloat();
System.out.println("enter your operation");
x = hossein.next().charAt(0);
if (x== '+') {
result = num1+num2;
}
else if (x== '-') {
result = num1-num2;
}
else if (x== '*') {
result = num1*num2;
}
else if (x== '/') {
result = num1/num2;
}
else {

System.out.println("this is not operator");
}
System.out.println("the result is");

System.out.println(result);

}
}

spiderman200700
پنج شنبه 04 اسفند 1390, 23:14 عصر
اینم اولین برنامه ی من.
کوچیک و سادس ولی از هیچی بهتره.

ماتریس ترانهاده

public class TransposedMatrix {

public static void main(String args[]) {
int k = 0;
int matrix[][] = new int[4][4];
int mt[][]=new int[4][4];
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[i].length; j++) {
matrix[i][j] = k++;
if(k>9){
k=0;
}
System.out.print(" " + matrix[i][j]);
}
System.out.println();
}

System.out.println();
System.out.println();
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[0].length; j++) {
mt[j][i] = matrix[i][j];
}
}
for (int i = 0; i < mt.length; i++) {
for (int j = 0; j < mt[i].length; j++) {
System.out.print(" " + mt[i][j]);
}
System.out.println();
}
}
}

spiderman200700
پنج شنبه 04 اسفند 1390, 23:19 عصر
یه برنامه برای رسم این شکل:
*
***
*****
*****
***
*

package javaclass;

public class UpDownTriangle {

static int n = 6;
static int FILL = 1;
static int FIRST = 0;

public static void main(String args[]) {

if (n % 2 == 0) {
FIRST = n / 2;
} else {
FIRST = (int) (n / 2) + 1;
}
int SPASE = FIRST - 1;
int i = 0;
for (i = 0; i < FIRST; i++) {
fillRow(new char[n], SPASE, FILL);
if (n % 2 == 0 && i == FIRST - 1) {
fillRow(new char[n], SPASE, FILL);
} else if (i < FIRST - 1) {
SPASE--;
FILL += 2;
}
}

for (i = FIRST; i < n; i++) {
SPASE++;
FILL -= 2;
fillRow(new char[n], SPASE, FILL);
}
}

public static void fillRow(char[] row, int SPASE, int FILL) {
for (int i = SPASE; i < FILL + SPASE; i++) {
row[i] = '*';
}
System.out.println(row);
}
}

spiderman200700
پنج شنبه 04 اسفند 1390, 23:30 عصر
رسم خطوط مورب زیبا.
با تغییر دادن اندازه ی پنجره ، اندازه ی خطوط به تناسب تغییر می کنه.
این برنامه رو به صورت Applet نوشتم.

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;

public class Lines extends Applet {

int w = 0;
int h = 0;
int x1 = 0;
int y1 = 0;
int x2 = 0;
int y2 = 0;

public void init() {
setSize(800, 600);
setBackground(Color.PINK);
}

public void paint(Graphics g) {
w = getSize().width;
h = getSize().height;
leftDown(g, w, h, w / 30, h / 30);
leftUp(g, w, h, w / 30, h / 30);
rightDown(g, w, h, w / 30, h / 30);
rightUp(g, w, h, w / 30, h / 30);
}

public void leftDown(Graphics g, int w, int h, int wp, int hp) {
x1 = w;
y1 = h;
x2 = 0;
y2 = h;
g.setColor(Color.BLACK); // Drawing line color is red
for (int i = 0; i < w/5; i++) {
g.drawLine(x1, y1, x2, y2);
x1 -= wp;
y2 -= hp;
}
}

public void leftUp(Graphics g, int w, int h, int wp, int hp) {
x1 = w;
y1 = 0;
x2 = 0;
y2 = 0;
g.setColor(Color.BLACK); // Drawing line color is red
for (int i = 0; i < w/5; i++) {
g.drawLine(x1, y1, x2, y2);
x1 -= wp;
y2 += hp;
}
}

public void rightDown(Graphics g, int w, int h, int wp, int hp) {
x1 = 0;
y1 = 0;
x2 = w;
y2 = 0;
g.setColor(Color.BLACK); // Drawing line color is red
for (int i = 0; i < w/5; i++) {
g.drawLine(x1, y1, x2, y2);
x1 += wp;
y2 += hp;
}
}

public void rightUp(Graphics g, int w, int h, int wp, int hp) {
x1 = 0;
y1 = h;
x2 = w;
y2 = h;
g.setColor(Color.BLACK); // Drawing line color is red
for (int i = 0; i < w/5; i++) {
g.drawLine(x1, y1, x2, y2);
x1 += wp;
y2 -= hp;
}
}
}

spiderman200700
پنج شنبه 04 اسفند 1390, 23:38 عصر
رسم اشکال با موس.
package javaclass;

import java.awt.BorderLayout;
import java.awt.Point;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class PaintPanel extends JPanel {

private int pointCount = 0; // count number of points
// array of 10000 java.awt.Point references
private Point points[] = new Point[10000];

// set up GUI and register mouse event handler
public PaintPanel() {

// handle frame mouse motion event
addMouseMotionListener(
new MouseMotionAdapter() { // anonymous inner class {
// store drag coordinates and repaint
public void mouseDragged(MouseEvent event) {
if (pointCount < points.length) {
points[ pointCount] = event.getPoint(); // find point
pointCount++; // increment number of points in array
repaint(); // repaint JFrame
} // end if
} // end method mouseDragged
} // end anonymous inner class
); // end call to addMouseMotionListener
} // end PaintPanel constructor

// draw oval in a 4-by-4 bounding box at specified location on window
public void paintComponent(Graphics g) {
super.paintComponent(g); // clears drawing area
// draw all points in array
for (int i = 0; i < pointCount; i++) {
g.fillOval(points[ i].x, points[ i].y, 20, 20);
}
} // end method paintComponent

public static void main(String args[]) {
// create JFrame
JFrame application = new JFrame("A simple paint program");
PaintPanel paintPanel = new PaintPanel(); // create paint panel
application.add(paintPanel, BorderLayout.CENTER); // in center
// create a label and place it in SOUTH of BorderLayout
application.add(new JLabel("Drag the mouse to draw"),
BorderLayout.SOUTH);
application.setDefaultCloseOperation(JFrame.EXIT_O N_CLOSE);
application.setSize(400, 200); // set frame size
application.setVisible(true); // display frame
} // end main
} // end class PaintPanel

spiderman200700
پنج شنبه 04 اسفند 1390, 23:45 عصر
یه برنامه که توش از JPopupMenu استفاده کردم.
مثال خوبی برای استفاده از JPopupMenu میتونه باشه.

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class PopupTest extends JFrame
{
private JMenuItem items[];
private Color colorValues[] = { Color.blue, Color.yellow, Color.red };

public PopupTest()
{
super( "Using JPopupMenus" );

final JPopupMenu popupMenu = new JPopupMenu();
ItemHandler handler = new ItemHandler();
String colors[] = { "Blue", "Yellow", "Red" };
ButtonGroup colorGroup = new ButtonGroup();
items = new JMenuItem[ 3 ];

// construct each menu item and add to popup menu; also
// enable event handling for each menu item
for ( int i = 0; i < items.length; i++ )
{
items[ i ] = new JMenuItem( colors[ i ] );
popupMenu.add( items[ i ] );
colorGroup.add( items[ i ] );
items[ i ].addActionListener( handler );
}

getContentPane().setBackground( Color.white );

// define a MouseListener for the window that displays
// a JPopupMenu when the popup trigger event occurs
addMouseListener( new MouseAdapter()
{
public void mousePressed( MouseEvent e )
{
checkForTriggerEvent( e );
}

public void mouseReleased( MouseEvent e )
{
checkForTriggerEvent( e );
}

private void checkForTriggerEvent( MouseEvent e )
{
if ( e.isPopupTrigger() )
popupMenu.show( e.getComponent(), e.getX(), e.getY() );
}
} );

setSize( 300, 200 );
show();
}

public static void main( String args[] )
{
PopupTest app = new PopupTest();

app.addWindowListener( new WindowAdapter()
{
public void windowClosing( WindowEvent e )
{
System.exit( 0 );
}
});
}

private class ItemHandler implements ActionListener
{
public void actionPerformed( ActionEvent e )
{
// determine which menu item was selected
for ( int i = 0; i < items.length; i++ )
if ( e.getSource() == items[ i ] )
{
getContentPane().setBackground( colorValues[ i ] );
repaint();
return;
}
}
}
}

spiderman200700
پنج شنبه 04 اسفند 1390, 23:50 عصر
یه برنامه برای ایجاد Rule (یا به قول خودمون خط کش) در برنامه ها.
اینو از سایت Oracle گرفتم.گفتم شاید جالب باشه.
ما معمولا خیلی کم از کلاس Rule استفاده می کنیم.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;


public class ScrollDemo extends JPanel
implements ItemListener {
private Rule columnView;
private Rule rowView;
private JToggleButton isMetric;
private ScrollablePicture picture;

public ScrollDemo() {
setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));

//Get the image to use.
ImageIcon bee = createImageIcon("images/flyingBee.jpg");

//Create the row and column headers.
columnView = new Rule(Rule.HORIZONTAL, true);
rowView = new Rule(Rule.VERTICAL, true);

if (bee != null) {
columnView.setPreferredWidth(bee.getIconWidth());
rowView.setPreferredHeight(bee.getIconHeight());
} else {
columnView.setPreferredWidth(320);
rowView.setPreferredHeight(480);
}

//Create the corners.
JPanel buttonCorner = new JPanel(); //use FlowLayout
isMetric = new JToggleButton("cm", true);
isMetric.setFont(new Font("SansSerif", Font.PLAIN, 11));
isMetric.setMargin(new Insets(2,2,2,2));
isMetric.addItemListener(this);
buttonCorner.add(isMetric);

//Set up the scroll pane.
picture = new ScrollablePicture(bee, columnView.getIncrement());
JScrollPane pictureScrollPane = new JScrollPane(picture);
pictureScrollPane.setPreferredSize(new Dimension(300, 250));
pictureScrollPane.setViewportBorder(
BorderFactory.createLineBorder(Color.black));

pictureScrollPane.setColumnHeaderView(columnView);
pictureScrollPane.setRowHeaderView(rowView);

//Set the corners.
//In theory, to support internationalization you would change
//UPPER_LEFT_CORNER to UPPER_LEADING_CORNER,
//LOWER_LEFT_CORNER to LOWER_LEADING_CORNER, and
//UPPER_RIGHT_CORNER to UPPER_TRAILING_CORNER. In practice,
//bug #4467063 makes that impossible (in 1.4, at least).
pictureScrollPane.setCorner(JScrollPane.UPPER_LEFT _CORNER,
buttonCorner);
pictureScrollPane.setCorner(JScrollPane.LOWER_LEFT _CORNER,
new Corner());
pictureScrollPane.setCorner(JScrollPane.UPPER_RIGH T_CORNER,
new Corner());

//Put it in this panel.
add(pictureScrollPane);
setBorder(BorderFactory.createEmptyBorder(20,20,20 ,20));
}

public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
//Turn it to metric.
rowView.setIsMetric(true);
columnView.setIsMetric(true);
} else {
//Turn it to inches.
rowView.setIsMetric(false);
columnView.setIsMetric(false);
}
picture.setMaxUnitIncrement(rowView.getIncrement() );
}

/** Returns an ImageIcon, or null if the path was invalid. */
protected static ImageIcon createImageIcon(String path) {
java.net.URL imgURL = ScrollDemo.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}

/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("ScrollDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);

//Create and set up the content pane.
JComponent newContentPane = new ScrollDemo();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);

//Display the window.
frame.pack();
frame.setVisible(true);
}

public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}

spiderman200700
شنبه 13 اسفند 1390, 23:20 عصر
مرتب سازی درجی :
public class InsertionSort {

public static void main(String args[]) {
print(insertionSort(new int[]{3, 2, -5, 8, 5, 10, 0, 29, -1}));
}

public static int[] insertionSort(int Numbers[]) {
int i, j, x;
for (i = 0; i < Numbers.length; i++) {
x = Numbers[i];
j = i - 1;
for (; j >= 0 && Numbers[j] > x; j--) {
Numbers[j + 1] = Numbers[j];
}
Numbers[j + 1] = x;
}
return Numbers;
}

public static void print(int Numbers[]) {
for (int Number : Numbers) {
System.out.print(Number + " ");
}
System.out.println();
}
}

spiderman200700
شنبه 13 اسفند 1390, 23:22 عصر
از دوستان تقاضا دارم که برنامه هاشونو بدون چشم داشت اینجا بذارن.
فرق نمیکنه برنامه کوچیک باشه یا بزرگ باشه. فقط سعی کنید تکراری نباشه.
دوستان کمک کنید که تالار جاوا یه کم قوی تر بشه . این تالار هر چقدر قوی تر بشه به نفع خودمونه.
وقتی کسی کدی رو اینجا قرار میده ممکنه به درد ده ها نفر بخوره.
پس لطفا همکاری کنید.
با تشکر.

saban56
شنبه 12 فروردین 1391, 17:34 عصر
برنامه ی JDownload Manager V1.0 همان برنامه یDownload Manager است، که توسط بنده،در پست 13 همین تایپک قرار گرفت.با این تفاوت که در JDownload Manager V1.0 یک سری امکانات جدید به برنامه اضافه شده و هدف از انشار آن، گسترش یک نرم افزار منبع باز جاوا ، توسط ایرانیان عزیز است.


با تشکر از شما دوست عزیز،
با اجازتون امکان کوچکی رو به برنامه شما اضافه کردم که میشه با استفاده از Socks proxy هم دانلود کرد.
متاسفانه هنوز همه ی Exception ها رو handle نکردم اما اگر فایل کانفیگ دستکاری نشود و کاربر اطلاعات درست وارد کند برنامه مشکلی نخواهد داشت.
شاید کد هایی که نوشته ام خیلی اصولی و بهینه نباشد پس لطف کنید خودتون اگر لازم دیدید تغییرش بدید.
به نظرم این برنامه پتانسیل این رو داره که امکانات زیادی بهش اضافه بشه و تاپیکی جدا داشته باشد.

84993

spiderman200700
شنبه 12 فروردین 1391, 22:35 عصر
سلام.
جناب saban56 ، خیلی عالیه.کد هاتون هم خوبه.
اگه زحمت مدیریت Exeption ها رو هم بکشید ، که دیگه عالیه عالی میشه. هر چند تعداد Exeption هایی که ممکنه پیش بیاد و مدیریت نشده باشه خیلی کمه.
پروکسی سرور خیلی امکان عالییه.
و من هم با شما کاملا موافقم. این برنامه میتونه تبدیل به یه برنامه ی کاملا حرفه ای بشه. البته با کمک همه ی دوستان جاوا کار.
واقعا دستت درد نکنه و خسته نباشی. :تشویق::تشویق:


همه ی ما بازم منتظر ایده های دوستان خلاق هستیم.
لطفا این برنامه رو گسترش بدید.
با تشکر

halghe106
دوشنبه 14 فروردین 1391, 11:03 صبح
من برای برنامه های خودم احتیاج داشتم که از یک فایل بیت به بیت بخونم و بنویسم...شاید به دردتون بخوره :)
البته این رو از جایی پیدا کرده بودم و یه سری ویرایش کوچیک کردم ;)




/*
*
* Class allowing to read and write bit per bit
*
*
* Author: parmenti @ sfs . uni-tuebingen . de
*
*/


import java.io.*;
public class BitWriter {

FileOutputStream f;
int nb_bits; // number of occupied bits in the buffer
int aByte; //our buffer, we only write bits when we gathered 8 bits

BitWriter(String file , FileOutputStream f) throws IOException {
this.f = f;
nb_bits = 0;
aByte = 0;
}

void writeBit(int b) throws IOException {
// b must be in {0,1} !!
nb_bits++;

// in all cases, we use the shift operators to append ...
if (b==0) {
// ... either a 0 (shift example: 1 << 2 == 100) ...
aByte = aByte << 1;
} else {
// ... or a 1 (| is the logical or: 1|0 == 1)
aByte = aByte << 1 | 1;
}
if (nb_bits == 8) {
// the buffer is full, we write to disc

System.out.print("writing " + aByte);
System.out.println(" -- \t" + Integer.toBinaryString(aByte));
f.write(aByte);
// and reset
nb_bits = 0;
aByte = 0;
}

}

void flush() throws IOException {
if (nb_bits != 0) {
// we append the necessary 0s
aByte = aByte << (8-nb_bits);
f.write(aByte);
}
// after flushing the buffer, we reset
aByte = 0;
nb_bits = 0;
f.flush();
}

void close() throws IOException {
f.close();
}
}




/*
*
* Class allowing to read and write bit per bit
*
*
* Author: parmenti @ sfs . uni-tuebingen . de
*
*/


import java.io.*;

public class BitReader {
FileInputStream f;
int bits; // the buffer
int mask; // the mask will start with 10000000 and
// be right-shifted to read the stream from left to right

BitReader(String file) throws IOException{
f = new FileInputStream(file);
bits = 0;
mask = 0;
}

int readBit() throws IOException{
// method that reads the next bit in the input stream

if (mask == 0) {
// the buffer is empty (the right-shifts have gone throught the 8 bits)
// we feed the buffer with the next byte
bits = f.read();
// the mask is (re)set to the hexadecimal value 80 = 8.16 = 128 = 10000000
mask = 0x80;
// if the end of the stream is reached, we return -1
if (bits==-1) return(-1);
}

if ((bits & mask) == 0) {
// the current position highlighted by the mask is 0 (0 & 1 == 0)

// right-shift for next reading
mask = mask >> 1;
return 0;
}
else {
// the current position highlighted by the mask is 1 (1 & 1 == 1)

// right-shift for next reading
mask = mask >> 1;
return 1;
}
}

void close() throws IOException {
f.close();
}
}

هانی هاشمی
دوشنبه 21 فروردین 1391, 00:59 صبح
همچین تاپیکی در بخش جاوا SE داشتیم : لینک
(http://barnamenevis.org/showthread.php?155793-%D9%86%D9%85%D9%88%D9%86%D9%87-%D8%A8%D8%B1%D9%86%D8%A7%D9%85%D9%87-%D9%87%D8%A7%DB%8C-%DA%A9%D9%88%DA%86%DA%A9-%D9%88-%D9%85%D9%81%D9%8A%D8%AF-%D8%AF%D8%B1-%D8%AC%D8%A7%D9%88%D8%A7)
اما به خاطر کم لطفیه دوستان به روز نشد

spiderman200700
دوشنبه 21 فروردین 1391, 10:58 صبح
همچین تاپیکی در بخش جاوا SE داشتیم : لینک
(http://barnamenevis.org/showthread.php?155793-%D9%86%D9%85%D9%88%D9%86%D9%87-%D8%A8%D8%B1%D9%86%D8%A7%D9%85%D9%87-%D9%87%D8%A7%DB%8C-%DA%A9%D9%88%DA%86%DA%A9-%D9%88-%D9%85%D9%81%D9%8A%D8%AF-%D8%AF%D8%B1-%D8%AC%D8%A7%D9%88%D8%A7)
اما به خاطر کم لطفیه دوستان به روز نشد

درسته.اما امیدوارم این تایپک به سرنوشت قبلی دچار نشه.
من خودم هر برنامه ای که فکر کنم به درد بقیه میخوره رو اینجا قرار میدم. امیدوارم بقیه ی دوستان هم همین کار رو بکنن.

amir5760
دوشنبه 28 فروردین 1391, 17:10 عصر
با تشکر از همه.
کمک فوری/
من میخام این شکل رو با eclips رسم کنم ولی خیلی مشکله حالا شاید من بلد نباشم.

هر کی با eclips کار کرده لطف کنه این شکل رو برام ترسیم کنه.به وسیله کد در eclips
ممنون.
*/شکل رو ضمیمه کردم/*85844

spiderman200700
جمعه 16 تیر 1391, 22:18 عصر
نمایش متون با ابزار های سطح پایین جاوا.
با کلیک بر روی پنجره ی برنامه تراز بندی متن تغییر میکنه.

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class TextLayout extends JPanel {

private static final int LEFT_ALIGN = 0;
private static final int RIGHT_ALIGN = 1;
private static final int CENTER_ALIGN = 2;
private static final int LEFT_RIGHT_ALIGN = 3;
protected int align;
private Dimension d;
private Font font;
private FontMetrics fm;
private int fontSize;
private int fh, bl;
private int space;
private String text = "Just as you would use your hands to interact "
+ "with objects in the physical world, you can use your mouse to"
+ " interact with items on your computer screen . You can move objects"
+ ", open them, change them, throw them away, and perform other actions,"
+ " all by pointing and clicking with your mouse";

public TextLayout() {
setBackground(Color.ORANGE);

try {
fontSize = 20;
} catch (NumberFormatException e) {
fontSize = 14;
}
align = LEFT_ALIGN;
addMouseListener(new MyMouseAdapter(this));
}

@Override
protected void paintComponent(Graphics g) {
update(g);
}

@Override
public void update(Graphics g) {
d = getSize();
g.setColor(getBackground());
g.fillRect(0, 0, d.width, d.height);
if (font == null) {
font = new Font("tahoma",
Font.PLAIN, fontSize);
}
g.setFont(font);
if (fm == null) {
fm = g.getFontMetrics();
bl = fm.getAscent();
fh = bl + fm.getDescent();
space = fm.stringWidth(" ");
}
g.setColor(Color.black);
StringTokenizer st = new StringTokenizer(text);
int x = 0;
int nextx;
int y = 0;
String word, sp;
int wordCount = 0;
String line = "";
while (st.hasMoreTokens()) {
word = st.nextToken();

if (word.equals(".")) {
drawString(g, line, wordCount,
fm.stringWidth(line), y + bl);
line = "";
wordCount = 0;
x = 0;
y = y + (fh * 2);
} else {
int w = fm.stringWidth(word);
if ((nextx = (x + space + w)) > d.width) {
drawString(g, line, wordCount,
fm.stringWidth(line), y + bl);
line = "";
wordCount = 0;
x = 0;
y = y + fh;
}
if (x != 0) {
sp = " ";
} else {
sp = "";
}
line = line + sp + word;
x = x + space + w;
wordCount++;
}
}
drawString(g, line, wordCount, fm.stringWidth(line), y + bl);
}

public void drawString(Graphics g, String line,
int wc, int lineW, int y) {
switch (align) {
case LEFT_ALIGN:
g.drawString(line, 0, y);
break;
case RIGHT_ALIGN:
g.drawString(line, d.width - lineW, y);
break;
case CENTER_ALIGN:
g.drawString(line, (d.width - lineW) / 2, y);
break;
case LEFT_RIGHT_ALIGN:
if (lineW < (int) (d.width * .75)) {
g.drawString(line, 0, y);
} else {
int toFill = (int) ((d.width - lineW) / wc);

int nudge = d.width - lineW - (toFill * wc);
int s = fm.stringWidth(" ");
StringTokenizer st = new StringTokenizer(line);
int x = 0;
while (st.hasMoreTokens()) {
String word = st.nextToken();
g.drawString(word, x, y);
if (nudge > 0) {
x = x + fm.stringWidth(word) + space + toFill + 1;
nudge--;
} else {
x = x + fm.stringWidth(word) + space + toFill;
}
}
}
break;
}
}

public static void main(String args[]) {
JFrame frame = new JFrame("best");
frame.add(new TextLayout());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.setSize(600, 400);
frame.setVisible(true);
}
}

class MyMouseAdapter extends MouseAdapter {

TextLayout tl;

public MyMouseAdapter(TextLayout tl) {
this.tl = tl;
}

public void mouseClicked(MouseEvent me) {
tl.align = (tl.align + 1) % 4;
tl.repaint();
}
}

sara.sherafati
جمعه 21 مهر 1391, 16:14 عصر
جمع 10 تا عدد
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ex1;

/**
*
* @author sara
*/
public class sum {
public static void main(String args[]){
int sum=0;
// int sum=0,i=1;
// if (i<=100) {
// sum=i+sum;
// i=i+1;
//
// }
// System.out.println("sum ="+sum);
//
for (int i = 1; i <= 1000; i++) {
sum=sum+i;
}
System.out.println("sum ="+sum);

}

}

sara.sherafati
جمعه 21 مهر 1391, 16:15 عصر
قسط ماهیانه

import java.util.Scanner;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author sara
*/
public class ghest {
public static void main(String[] args) {
Scanner sara=new Scanner(System.in);
int mounth;
double vam,karmozd,sood,mablagh,ghest;
System.out.println("cheghadr vam mikhay:");
vam=sara.nextDouble();
System.out.println("dar che modat:");
mounth=sara.nextInt();
System.out.println("che meghdar kamrmozdeshe:");
karmozd=sara.nextDouble();
sood=(vam*karmozd*(1+mounth))/2400;
mablagh=vam+mounth;
ghest=mablagh/mounth;

System.out.println("ghest = "+ghest);




}

}

noura karimi
سه شنبه 25 مهر 1391, 16:14 عصر
سلام یه پروژه به زبان جاوا میخوام با موضوع زیر

برنامه ایی که یک رشته از کاربر بگیرد
1- تعداد کلمات آن را نشان دهد
2- بتواند اندیس کلمه خاص را نشان دهد

این برنامه باید بتواند یک جمله را بگیرد مثل:hello my name is noura karimi and i love computer
خروجی اول بگه این جمله طولش چقدره یا همان تعداد کلماتش
برای خروجی دوم بیات از کاربر بپرسه کلمه خاص شما چیه مثلا وارد میشه noura که باید اندیس این کلمه را برگرداند

خواهش میکنم کمکم کنید:چشمک:

arezoo200
پنج شنبه 24 اسفند 1391, 23:53 عصر
برنامه ای به زبان جاوا بنویسید که یک رشته از ورودی گرفته و اگر طول رشته زوج باشد و در نیمه اول رشته کلمه ali و در نیمه دوم رشته کلمه reza وجود داشته باشد yes را نمایش دهد


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ex1;

/**
*
* @author pars
*/import java.util.*;
public class Ex1 {

/**
* @param args the command line arguments
*/
static Scanner in = new Scanner ( System.in ) ;
public static void main(String[] args) {
// TODO code application logic here
String str1,str2,str3;
int a,b,j=0,c;
System.out.print("Enter a string : ");
str1 = in.next() ;
c = str1.length();
if(str1.length()%2 == 0)
{
str2=str1.substring(0, c/2);
str3=str1.substring(c/2,c);
a = str2.indexOf("ali") ;//index returns -1 on failure.
if ( a >= 0 )
{ j++;
System.out.println(" ali find "); }
b = str3.indexOf("reza") ;//index returns -1 on failure.
if ( b >= 0 )
{
j++;
System.out.println(" reza find ");
}
if (j>=2)
System.out.println(" YES ");
}
}
}





خروجی :


run:
Enter a string : aliareza
ali find
reza find
YES
BUILD SUCCESSFUL (total time: 16 seconds)

arezoo200
پنج شنبه 24 اسفند 1391, 23:55 عصر
برنامه ای به زبان جاوا بنویسید که 10 نمره یک دانشجو را گرفته و معدلش را حساب کند( توسط آرایه)


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ex2;

/**
*
* @author pars
*/
import java.util.*;
public class Ex2 {

/**
* @param args the command line arguments
*/
static Scanner console = new Scanner (System.in);
public static void main(String[] args) {
// TODO code application logic here
double items [] = new double[10];
int i;
double sum;
sum = 0 ;
System.out.println(" **** Please enter student grades ****");
for(i = 0; i< items.length; i++)
{
items[i] = console.nextDouble();
sum += items[i];
}
System.out.println("Average of class is : " + sum/10);
}
}




خروجی:

run:
**** Please enter student grades ****
19
18
17
20
19
19
20
18
17
18
Average of class is : 18.5
BUILD SUCCESSFUL (total time: 22 seconds)




به قرعان نمرات خودم بود !!!

arezoo200
جمعه 25 اسفند 1391, 00:00 صبح
برنامه ای به زبان جاوا بنویسید که شکل زیر را در یک لیبل چاپ کند

http://barnamenevis.org/attachment.php?attachmentid=101333


خط اول 7 تا جا خالی داره و خط های بعدی دوتا دوتا کم میشه یعنی بعدی 5 تا جا خالی داره
به خاطر اجرایه کدهای اچ تی ام ال در خط 20 کد عوض شده است به تصویر نگاه کنید و آن را تصحیح کنید : http://barnamenevis.org/attachment.php?attachmentid=101339


private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:\
String output = "<html><pre>", out = "";
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
output += "*";
}
for (int k = 9 - (2 * i); k >= 1; k--) {
output += " ";
}
if (i != 5) {
for (int s = 1; s <= i; s++) {
output += "*";
}
} else {
for (int s = 1; s < i; s++) {
output += "*";
}
}
output += "<br>";
}
out = output + "</pre></html>";
this.jLabel1.setText(out);
}



خروجی : ( این مثال فقط یه بوتن نمایش داره و یه لیبل )

http://barnamenevis.org/attachment.php?attachmentid=101331

arezoo200
جمعه 25 اسفند 1391, 00:05 صبح
برنامه یک ماشین حساب که به جزء اعمال جبری اعمال توان و لگاریتم و نسبت های مثلثاتی و جذر و قدر مطلق را نیز انجام میدهد.موقع بسته شدن پیام میدهد که آیا مطمئن هستید و دکمه های Yes و No دارد.

لینک دانلود پروژه: اینجا کلیک کنید (http://s2.picofile.com/file/7690270214/calculator.zip.html)


قسمت کنسولی :



/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Gharekhani
*/
public class main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
myGUIform f = new myGUIform();
f.setVisible(true);
}
}

قسمت ویندوزی :


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* myGUIform.java
*
* Created on Mar 11, 2013, 12:41:23 PM
*/
/**
*
* @author Gharekhani
*/
import javax.swing.JOptionPane;
public class myGUIform extends javax.swing.JFrame {

/** Creates new form myGUIform */
public myGUIform() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
//
private void initComponents() {

answer = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jButton6 = new javax.swing.JButton();
jButton7 = new javax.swing.JButton();
jButton8 = new javax.swing.JButton();
jButton9 = new javax.swing.JButton();
jButton10 = new javax.swing.JButton();
jButton11 = new javax.swing.JButton();
jButton12 = new javax.swing.JButton();
jButton13 = new javax.swing.JButton();
jButton14 = new javax.swing.JButton();
jButton15 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jButton16 = new javax.swing.JButton();
jButton17 = new javax.swing.JButton();
jButton18 = new javax.swing.JButton();
jButton19 = new javax.swing.JButton();
jButton20 = new javax.swing.JButton();
jButton21 = new javax.swing.JButton();
jButton22 = new javax.swing.JButton();
jButton23 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowOpened(java.awt.event.WindowEvent evt) {
formWindowOpened(evt);
}
});

answer.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
answerActionPerformed(evt);
}
});

jButton1.setText("1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jButton2.setText("2");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});

jButton3.setText("3");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});

jButton4.setText("4");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});

jButton5.setText("5");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});

jButton6.setText("6");
jButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton6ActionPerformed(evt);
}
});

jButton7.setText("7");
jButton7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton7ActionPerformed(evt);
}
});

jButton8.setText("8");
jButton8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton8ActionPerformed(evt);
}
});

jButton9.setText("9");
jButton9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton9ActionPerformed(evt);
}
});

jButton10.setText("0");
jButton10.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton10ActionPerformed(evt);
}
});

jButton11.setText("+");
jButton11.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton11ActionPerformed(evt);
}
});

jButton12.setText("-");
jButton12.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton12ActionPerformed(evt);
}
});

jButton13.setText("*");
jButton13.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton13ActionPerformed(evt);
}
});

jButton14.setText("/");
jButton14.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton14ActionPerformed(evt);
}
});

jButton15.setText("=");
jButton15.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton15ActionPerformed(evt);
}
});

jButton16.setText("pow");
jButton16.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton16ActionPerformed(evt);
}
});

jButton17.setText("abs");
jButton17.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton17ActionPerformed(evt);
}
});

jButton18.setText("log");
jButton18.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton18ActionPerformed(evt);
}
});

jButton19.setText("sqrt");
jButton19.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton19ActionPerformed(evt);
}
});

jButton20.setText("cos");
jButton20.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton20ActionPerformed(evt);
}
});

jButton21.setText("sin");
jButton21.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton21ActionPerformed(evt);
}
});

jButton22.setText("tan");
jButton22.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton22ActionPerformed(evt);
}
});

jButton23.setText("Exit");
jButton23.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton23ActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILI NG, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.TRAILING)
.addComponent(answer, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 373, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.TRAILING)
.addComponent(jLabel1)
.addComponent(jLabel2))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.UNRELATED)
.addComponent(jButton2))
.addGroup(layout.createSequentialGroup()
.addComponent(jButton4)
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.UNRELATED)
.addComponent(jButton5))
.addGroup(layout.createSequentialGroup()
.addComponent(jButton7)
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addComponent(jButton8)
.addComponent(jButton10))))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILI NG, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addComponent(jButton3)
.addComponent(jButton6)
.addComponent(jButton9))
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, 22, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING, false)
.addComponent(jButton11, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton12, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)
.addComponent(jButton14, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton13, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING, false)
.addComponent(jButton17, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton19, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton16, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton18, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING, false)
.addComponent(jButton15, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton22, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton21, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton20, javax.swing.GroupLayout.DEFAULT_SIZE, 58, Short.MAX_VALUE)))
.addComponent(jButton23, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(21, 21, 21))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(answer, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(jButton16)
.addComponent(jButton20))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(jButton18)
.addComponent(jButton21))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(41, 41, 41)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(jButton19)
.addComponent(jButton15)))
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(jButton17)
.addComponent(jButton22))))
.addGroup(layout.createSequentialGroup()
.addComponent(jButton11)
.addGap(18, 18, 18)
.addComponent(jButton12)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(41, 41, 41)
.addComponent(jButton14))
.addComponent(jButton13)))))
.addGroup(layout.createSequentialGroup()
.addGap(66, 66, 66)
.addComponent(jLabel1)
.addGap(0, 0, 0)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(jButton4)
.addComponent(jButton5))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(jButton7)
.addComponent(jButton8))
.addGap(18, 18, 18)
.addComponent(jButton10))
.addGroup(layout.createSequentialGroup()
.addComponent(jButton3)
.addGap(18, 18, 18)
.addComponent(jButton6)
.addGap(18, 18, 18)
.addComponent(jButton9))
.addComponent(jLabel2))))
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, 30, Short.MAX_VALUE)
.addComponent(jButton23, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);

pack();
}//

private void jButton11ActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
this.jLabel1.setText(this.answer.getText());
this.answer.setText("");
this.jLabel2.setText("+");
}

private void answerActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.answer.setText(this.answer.getText() + "1");
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.answer.setText(this.answer.getText() + "2");
}

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here
this.answer.setText(this.answer.getText() + "3");
}

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.answer.setText(this.answer.getText() + "4");
}

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.answer.setText(this.answer.getText() + "5");
}

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.answer.setText(this.answer.getText() + "6");
}

private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.answer.setText(this.answer.getText() + "7");
}

private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.answer.setText(this.answer.getText() + "8");
}

private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.answer.setText(this.answer.getText() + "9");
}

private void jButton10ActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
this.answer.setText(this.answer.getText() + "0");
}

private void jButton12ActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
this.jLabel1.setText(this.answer.getText());
this.answer.setText("");
this.jLabel2.setText("-");
}

private void jButton13ActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
this.jLabel1.setText(this.answer.getText());
this.answer.setText("");
this.jLabel2.setText("*");
}

private void jButton14ActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
this.jLabel1.setText(this.answer.getText());
this.answer.setText("");
this.jLabel2.setText("/");
}

private void jButton15ActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
int n1 = 0, n2 = 0;
double n3 = 0;
n1 = Integer.parseInt(this.answer.getText());
n2 = Integer.parseInt(this.jLabel1.getText());
if ("+".equals(this.jLabel2.getText())) {
n3 = n2 + n1;
} else if ("-".equals(this.jLabel2.getText())) {
n3 = n2 - n1;
} else if ("*".equals(this.jLabel2.getText())) {
n3 = n2 * n1;
} else if ("/".equals(this.jLabel2.getText())) {
n3 = n2 / n1;
} else if ("^".equals(this.jLabel2.getText())) {
n3 = Math.pow(n2, n1);
}
this.answer.setText("" + n3);
}

private void formWindowOpened(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
this.jLabel1.setVisible(false);
this.jLabel2.setVisible(false);
}

private void jButton17ActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
int n1 = 0, n2 = 0;
n1 = Integer.parseInt(this.answer.getText());
n2 = Math.abs(n1);
this.answer.setText("" + n2);
}

private void jButton16ActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
this.jLabel1.setText(this.answer.getText());
this.answer.setText("");
this.jLabel2.setText("^");
}

private void jButton18ActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
int n1 = 0;
double n2 = 0;
n1 = Integer.parseInt(this.answer.getText());
n2 = Math.log(n1);
this.answer.setText("" + n2);
}

private void jButton19ActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
double n1 = 0, n2 = 0;
n1 = Integer.parseInt(this.answer.getText());
n2 = Math.sqrt(n1);
this.answer.setText("" + n2);
}

private void jButton20ActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
double n1 = 0, n2 = 0;
n1 = Integer.parseInt(this.answer.getText());
n2 = Math.cos(n1);
this.answer.setText("" + n2);
}

private void jButton21ActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
double n1 = 0, n2 = 0;
n1 = Integer.parseInt(this.answer.getText());
n2 = Math.sin(n1);
this.answer.setText("" + n2);
}

private void jButton22ActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
double n1 = 0, n2 = 0;
n1 = Integer.parseInt(this.answer.getText());
n2 = Math.tan(n1);
this.answer.setText("" + n2);
}

private void jButton23ActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
int result = JOptionPane.showConfirmDialog(null,"Are you sure ?",null,
JOptionPane.YES_NO_OPTION);
if(result==0)
System.exit(0);
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClass Name());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(myGUIform.class .getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(myGUIform.class .getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(myGUIform.class .getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(myGUIform.class .getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//

/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {
new myGUIform().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextField answer;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton10;
private javax.swing.JButton jButton11;
private javax.swing.JButton jButton12;
private javax.swing.JButton jButton13;
private javax.swing.JButton jButton14;
private javax.swing.JButton jButton15;
private javax.swing.JButton jButton16;
private javax.swing.JButton jButton17;
private javax.swing.JButton jButton18;
private javax.swing.JButton jButton19;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton20;
private javax.swing.JButton jButton21;
private javax.swing.JButton jButton22;
private javax.swing.JButton jButton23;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JButton jButton7;
private javax.swing.JButton jButton8;
private javax.swing.JButton jButton9;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
// End of variables declaration
}


خروجی : (این برنامه نیاز به 23 تا باتن و دو لیبل و یک فیلد تکس دارد)

http://barnamenevis.org/attachment.php?attachmentid=101401&d=1363096869

mahsa f
سه شنبه 20 فروردین 1392, 21:08 عصر
کلاس dateرا براي تاريخ بسازيد و با استفاده از آن آرايه اي از اشياء از نوع تاريخ را از كاربر دريافت كرده و آنها را به
صورت صعودي مرتب كرده و نمايش دهيد.

import java.io.*;
class Date
{
int d,m,y;
void get()throws IOException
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter day:");
d=Integer.parseInt(in.readLine());
System.out.println("enter month:");
m=Integer.parseInt(in.readLine());
System.out.println("enter year:");
y=Integer.parseInt(in.readLine());
}


void put() {
System.out.println( y + "/" + m + "/" + d);
}

int compare(Date x) {

if(y!=x.y)
return y-x.y;
if(m!=x.m)
return m-x.m;
return d-x.d;
}
}

class Test1 {
public static void main(String []args) throws IOException {

int i,j,n=5;
Date []a=new Date[n];
Date t;
for(i=0;i<n;i++)
{
a[i]=new Date();
a[i].get();
}

for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(a[i].compare(a[j])>0)
{
t=a[i];
a[i]=a[j];
a[j]=t;
}

for(i=0;i<n;i++)
a[i].put();

}
}

mahsa f
سه شنبه 20 فروردین 1392, 21:10 عصر
برنامه اي بنويسيد كه مشخصات 5 دانشجو (نام ، شماره دانشجويي و تعداد دروس گذرانده شده و نمرات دروس) را
دريافت و پس از گرفتن نمره ي هر درس ، معدل دانشجو را محاسبه و همراه با مشخصات وي چاپ كند. همچنين معدل
ميانگين كل دانشجويان را محاسبه نماييد.

import java.io.*;

class Student {

String name;
int ID;
int passed;
float[] mark;

float average()
{
float s=0;
for(int i=0;i<passed;i++)
s+=mark[i];
return s/passed;
}
void get() throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

System.out.print("Enter Name: ");
name = in.readLine();

System.out.print("Enter ID: ");
ID = Integer.parseInt(in.readLine());

System.out.print("Enter Number of passed units :");
passed = Integer.parseInt(in.readLine());

mark = new float[passed];

float sum = 0;
for (int i = 0; i < passed; i++) {
System.out.print("Mark[" + i + "] = ");
mark[i] = Float.parseFloat(in.readLine());
}
}

void put(boolean with_mark_) {
System.out.println("****************************************");
System.out.println("\t" + name + "\t|\t" + ID + "\t|\t" + passed + "\t\t|\t" + average());

if (with_mark_) {
System.out.println("****************************************");
for (int i = 0; i < passed; i++) {
System.out.print(mark[i]+"\t");
}
System.out.println();
}
}
}

class Test3 {

public static void main(String[] args) throws IOException {
int i,n=5;
Student[] stu = new Student[n];

for (i = 0; i < stu.length; i++) {
stu[i] = new Student();
stu[i].get();
}

float s=0;
for (i = 0; i < stu.length; i++) {
stu[i].put(true);
s+=stu[i].average();
}
System.out.println("Average of all students: "+s/stu.length);
}
}

mahsa f
سه شنبه 20 فروردین 1392, 21:13 عصر
کلاس Matrix را براي ماتريس بسازيد. در اين كلاس افزون بر بخش داده اي مناسب، مي بايست توابع دريافت، نمايش،
مقداردهي، سازنده و همچنين توابع جمع، تفريق و ضرب ماتريسي نوشته شده باشد.

class Matrix {

double[][] deraye;

public Matrix(double[][] newDeraye) {
this.deraye = new double[newDeraye.length][newDeraye[0].length];
for (int i = 0; i < this.deraye.length; i++) {
for (int j = 0; j < this.deraye[0].length; j++) {
this.deraye[i][j] = newDeraye[i][j];
}
}
}

public Matrix() {
}

public Matrix(int width, int height) {
deraye = new double[width][height];
}

public double get(int i, int j)
{
if (i<this.deraye.length)
if (j<this.deraye[0].length)
return this.deraye[i][j];
return 0;
}

public void set(int i, int j, double value)
{
if (i<this.deraye.length)
if (j<this.deraye[0].length)
this.deraye[i][j]=value;
}

public void get() throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please Enter The width");
int width = Integer.parseInt(reader.readLine());
System.out.println("Please Enter The height");
int height = Integer.parseInt(reader.readLine());

deraye = new double[width][height];

for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
System.out.println("derayeye[" + (i + 1) + "][" + (j + 1) + "]");
deraye[i][j] = Integer.parseInt(reader.readLine());
}
}
}

public void put() {
System.out.println("Matix:");
for (int i = 0; i < deraye.length; i++) {
for (int j = 0; j < deraye[i].length; j++) {
System.out.print(deraye[i][j] + "\t");
}
System.out.println("");
}
}

public void set(double[][] newDeraye) {
this.deraye = new double[newDeraye.length][newDeraye[0].length];
for (int i = 0; i < this.deraye.length; i++) {
for (int j = 0; j < this.deraye[0].length; j++) {
this.deraye[i][j] = newDeraye[i][j];
}
}
}

public Matrix add(Matrix newMat) {
if (this.deraye.length == newMat.deraye.length) {
if (this.deraye[0].length == newMat.deraye[0].length) {
Matrix RetMat = new Matrix(this.deraye.length, this.deraye[0].length);
for (int i = 0; i < this.deraye.length; i++) {
for (int j = 0; j < this.deraye[0].length; j++) {
RetMat.deraye[i][j] = this.deraye[i][j] + newMat.deraye[i][j];
}
}
return RetMat;
}
}
return null;
}

public Matrix sub(Matrix newMat) {
if (this.deraye.length == newMat.deraye.length) {
if (this.deraye[0].length == newMat.deraye[0].length) {
Matrix RetMat = new Matrix(this.deraye.length, this.deraye[0].length);
for (int i = 0; i < this.deraye.length; i++) {
for (int j = 0; j < this.deraye[0].length; j++) {
RetMat.deraye[i][j] = this.deraye[i][j] - newMat.deraye[i][j];
}
}
return RetMat;
}
}
return null;
}

public Matrix mul(Matrix newMat)
{
if (this.deraye[0].length == newMat.deraye.length) {
Matrix RetMat = new Matrix(this.deraye.length,newMat.deraye[0].length);
for (int i= 0; i < deraye.length; i++) {
for (int j = 0; j < newMat.deraye[0].length; j++) {
double sum=0;
for (int k = 0; k < deraye[0].length; k++) {
sum+=this.deraye[i][k]*newMat.deraye[k][j];
}
RetMat.deraye[i][j]=sum;
}
}
return RetMat;
}
return null;
}
}


class Test2 {

public static void main(String[] args) throws IOException {
Matrix a= new Matrix();
a.get();
a.put();

Matrix b = new Matrix();
b.get();
b.put();

a.mul(b).put();
}
}

spiderman200700
چهارشنبه 21 فروردین 1392, 00:47 صبح
خانم mahsa f (http://barnamenevis.org/member.php?279124-mahsa-f) تشکر از شما. فقط اگه میشه برنامه هاتونو که اینجا قرار میدید در تگ JAVA قرار بدید که به هم ریخته نباشن.
موفق باشید

mahsa f
چهارشنبه 21 فروردین 1392, 20:50 عصر
كلاس عدد مختلط را همراه با توابع دريافت، نمايش، مقداردهي و جمع و تفريق و ضرب پياده سازي كنيد. سپس حاصل
ضرب و جمع و تفريق دو عدد مختلط را محاسبه و چاپ كنيد.
import java.io.*;

class Complex {

double x, y;

void get() throws IOException {
BufferedReader breader = new BufferedReader(new InputStreamReader(System.in));

System.out.print("Enter Real Part (X) : ");
x = Double.parseDouble(breader.readLine());
System.out.print("Enter Imagine Part (Y) : ");
y = Double.parseDouble(breader.readLine());
}

void put() {
System.out.println( x + "," + y );
}

void set(double X,double Y) {
x=X;
y=Y;
}

Complex add(Complex c) {
Complex z=new Complex();
z.x=x + c.x;
z.y=y + c.y;
return z;
}

Complex sub(Complex c) {
Complex z=new Complex();
z.x=x - c.x;
z.y=y - c.y;
return z;
}

Complex mul(Complex c) {
Complex z=new Complex();
z.x=x*y -c.x*c.y;
z.y=y*c.x + x*c.y;
return z;
}
}

class Test4 {
public static void main(String []a) throws IOException {

Complex z1,z2,z3,z4;
z1=new Complex();
z2=new Complex();
z1.set(2,3);
z2.get();
z3=z1.add(z2);
z3.put();
z4=z1.sub(z2);
z4.put();
z1.mul(z2).put();

}
}

mahsa f
چهارشنبه 21 فروردین 1392, 20:56 عصر
با تركيب كلاسهاي ماتريس و اعداد مختلط، كلاسcomplexMatرا بسازيد كه ماتريسي با درايه هاي مختلط است.
از اين كلاس اشيائي ساخته و تواناييهاي آنرا بررسي كنيد.

package HW3;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
*
*/
public class ComplexMat {

Complex[][] matrix;

public ComplexMat() {
}

public ComplexMat(int n, int m) {
this.matrix = new Complex[n][m];
}

public void Get() throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter number of rows : ");
int n = Integer.parseInt(in.readLine());
System.out.println("Enter number of columns : ");
int m = Integer.parseInt(in.readLine());
this.matrix = new Complex[n][m];
for (int i = 0; i < this.matrix.length; i++) {
for (int j = 0; j < this.matrix[0].length; j++) {
this.matrix[i][j].get();
}
}
}

public void Put() throws IOException {

for (int i = 0; i < this.matrix.length; i++) {
for (int j = 0; j < this.matrix[0].length; j++) {
this.matrix[i][j].put();
System.out.print("\t");
}
System.out.print("\n");
}
}

public ComplexMat Add(ComplexMat cmat) {
if (cmat.matrix.length != this.matrix.length || cmat.matrix[0].length != this.matrix[0].length) {
return null;
}
ComplexMat result = new ComplexMat(this.matrix.length, this.matrix[0].length);
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[i].length; j++) {
result.matrix[i][j] = this.matrix[i][j].add(cmat.matrix[i][j]);
}
}
return result;
}

public ComplexMat Mul(ComplexMat cmat) {
int i = 0, j = 0, k = 0;
ComplexMat result = null;
if (this.matrix[0].length == cmat.matrix.length) {
result = new ComplexMat(this.matrix.length, cmat.matrix[0].length);
for (i = 0; i < this.matrix.length; i++) {
for (j = 0; j < cmat.matrix[0].length; j++) {
for (k = 0; k < this.matrix[0].length; k++) {
result.matrix[i][j] = this.matrix[i][k].mul(cmat.matrix[k][j]);
}
}
}
} else {
System.out.println("Invalid matrixes!");
}
return result;

}
}

class Complex {

double x, y;

public Complex(double x, double y) {
this.x = x;
this.y = y;

}

void get() throws IOException {
BufferedReader breader = new BufferedReader(new InputStreamReader(System.in));

System.out.print("Enter Real Part (X) : ");
this.x = Double.parseDouble(breader.readLine());
System.out.print("Enter Imagine Part (Y) : ");
this.y = Double.parseDouble(breader.readLine());
}

void put() {
System.out.println(x + " + " + y + "i");
}

Complex add(Complex c) {
return new Complex(this.x + c.x, this.y + c.y);
}

Complex sub(Complex c) {
return new Complex(this.x - c.x, this.y - c.y);
}

Complex mul(Complex c) {
return new Complex(this.x * c.x - this.y * c.y,
this.x * c.y + this.y * c.x);
}
}

mahsa f
چهارشنبه 21 فروردین 1392, 20:59 عصر
كلاس productرا براي نگهداري اطلاعات محصولات توليدي يك كارخانه بنويسيد كه در آن نام كالا، تاريخ توليد و
تاريخ انقضا نگهداري شود. از اين كلاس اشيائي با نامها و تاريخهاي تصادفي ساخته و مشخص كنيد كه كداميك از آنها
تاريخ مصرفشان گذشته و كدام را هنوز مي توان مصرف كرد.
package HW3;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Calendar;
import java.util.GregorianCalendar;

/**
*
*/
public class Product {

String name;
Date prdDate;
Date expDate;

public Product() {
}

public Product(String name) {
this.name = name;
}

public Product(String name, Date prdDate, Date expDate) {
this.name = name;
this.prdDate = prdDate;
this.expDate = expDate;
}

public boolean IsExpired() {
if (expDate.compareTo(Date.getToday()) == 1) {//
return true;
}
return false;
}

void Put() {
System.out.println("\nProductName:"+name);
System.out.println(prdDate.toString());
System.out.println(expDate.toString());
}
}

class Date {

static Date getToday() {
Date today = new Date();
Calendar cl = new GregorianCalendar();
today.set(cl.get(Calendar.DAY_OF_MONTH), cl.get(Calendar.MONTH), cl.get(Calendar.YEAR));
return today;
}
int d, m, y;
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//-----------------------------------------------------
// This Part Gets The Day & Mounth & Year Of Our Date .
//-----------------------------------------------------

void get() throws IOException {
System.out.print("Please Enter The Day ");
String s = in.readLine();
d = Integer.parseInt(s);
while (d > 31 || d < 1) {
System.out.println("ERROR !! ");
System.out.println("Your Day Is Out Of Range , Please Enter Another Value ");
s = in.readLine();
d = Integer.parseInt(s);
}
System.out.print("Please Enter The Mounth ");
s = in.readLine();
m = Integer.parseInt(s);
while (m > 12 || m < 1) {
System.out.println("ERROR !! ");
System.out.println("Your Mounth Is Out Of Range , Please Enter Another Value ");
s = in.readLine();
m = Integer.parseInt(s);
}
System.out.print("Please Enter The Year ");
s = in.readLine();
y = Integer.parseInt(s);
while (y < 1370) {
System.out.println("ERROR !! ");
System.out.println("Your Year Is Out Of Range , Please Enter Another Value ");
s = in.readLine();
y = Integer.parseInt(s);
}
}

@Override
public String toString() {
return y + "/" + m + "/" + d;
}
//----------------------------
// This Part Print The Date !!
//----------------------------


void put() {
System.out.println("Date: " + d + " - " + m + " - " + y);
}
//-------------------------------------------
// This Part Compare 2 Date With Each Other .
//-------------------------------------------

int compareTo(Date b) {
int x = 0;
if (y < b.y) {
x = 1;
return x;
}
if (y > b.y) {
x = 2;
return x;
}
if (y == b.y) {
if (m < b.m) {
x = 1;
return x;
}
if (m > b.m) {
x = 2;
return x;
}
if (m == b.m) {
if (d < b.d) {
x = 1;
return x;
}
if (d > b.d) {
x = 2;
return x;
}
if (d == b.d) {
x = 0;
return x;
}
}

}
return x;
}
//--------------------------------------
//This Part Set A Date With Your Value .
//--------------------------------------

void set(int D, int M, int Y) {
d = D;
m = M;
y = Y;
}

void Date(int D, int M, int Y) {
set(D, M, Y);
}
//-----------------------------
//This Part Set Add Up 2 Date .
//-----------------------------

void add(Date A) {
int i = 0, j = 0;
d = A.d + d;
while (d > 31) {
d = d - 30;
i++;
}
m = m + i;
m = A.m + m;
while (m > 12) {
m = m - 12;
j++;
}
y = y + j;
y = A.y + y;
}
//---------------------------
//This Part subtract 2 Date .
//---------------------------

void sub(Date B) {
if (y > B.y) {
if (d > B.d) {
d = d - B.d;
}
if (d < B.d) {
m--;
d = d + 31;
d = d - B.d;
}
if (m > B.m) {
m = m - B.m;
}
if (m < B.m) {
y--;
m = m + 12;
m = m - B.m;
}
}
if (y < B.y) {
if (B.d > d) {
B.d = B.d - d;
}
if (B.d < d) {
B.m--;
B.d = B.d + 31;
B.d = B.d - d;
}
if (B.m > m) {
B.m = B.m - m;
}
if (B.m < m) {
B.y--;
B.m = B.m + 12;
B.m = B.m - m;
}
}
if (y == B.y) {
if (m > B.m) {
if (d > B.d) {
d = d - B.d;
}
if (d < B.d) {
m--;
d = d + 31;
d = d - B.d;
}
}
if (m < B.m) {
if (B.d > d) {
B.d = B.d - d;
}
if (B.d < d) {
B.m--;
B.d = B.d + 31;
B.d = B.d - d;
}
}
if (m == B.m) {
if (d > B.d) {
d = d - B.d;
}
if (d < B.d) {
B.d = B.d - d;
}
if (d == B.d) {
d = 0;
m = 0;
y = 0;
}
}
}
}

public static Date generateRandomDate() {
Date newDate = new Date();
newDate.d = (int) Math.random() * 30;
newDate.m = (int) Math.random() * 12;
newDate.y = (int) Math.random() * 5 + 1388;
return newDate;
}
}

mahsa f
شنبه 24 فروردین 1392, 02:10 صبح
سلام.مثل اینکه اصلا برنامه گذاشن و... هیچ فایده ای نداره!!!!!!!!!!!
انگار به درد کسی نمیخوره....هیچ کس هم چیز جدیدی نمیذاره که حداقل دلمون خوش باشه!!!!!!!!!!!

spiderman200700
یک شنبه 25 فروردین 1392, 01:32 صبح
متاسفانه همینطوریه.
منم به همین دلیل دیگه برنامه نذاشتم.
حتی جواب دادن به سوالاتم بی فایدس چون خیلی ها اداعای بزرگی دارن ولی جوابی به سوالات کسی نمیدن و وقتی کسی به سوالی جواب میده تازه میان تو صحنه و علیه جواب های داده شده جبهه میگیرن. در پاسخ به اینجور حرکتا بهترین کار اینه که جواب ادعا هاشونو نداد.
و در پاسخ به بی اهمییت بودن برنامه هایی که در این تاپیک قرار داده میشه ، بهتر اینه که دیگه برنامه ای قرار ندیم.
به هر حال من بازم از زحمتتون تشکر میکنم. امیدوارم که قدر زحماتتون دونسته بشه

saeedfadaoddini
جمعه 30 فروردین 1392, 13:07 عصر
http://barnamenevis.org/showthread.php?394251-%D8%AA%DA%A9%D9%85%DB%8C%D9%84-%D9%BE%D8%B1%D9%88%DA%98%D9%87-%DA%A9%D8%A7%D8%B1%DB%8C%DA%A9%D8%A7%D8%AA%D9%88%D 8%B1-%D8%B3%D8%A7%D8%B2-%D8%A2%D9%86%D9%84%D8%A7%DB%8C%D9%86

esmaeilbf
جمعه 30 فروردین 1392, 22:26 عصر
این تاپیک میتونست یکی بهترین تاپیک ها بشه !! بهترین آموزش به نظرم دیدن کدهای دیگران هست به هر حال باعث تاسف هست که ادامه پیدا نکرد!امیدوارم دوستان حمایت کنند
یه جمله ی کلیشه ای و صدالبته بسیار باارزش هست که میگه:
ذکات علم در نشر آن است.

mahsa f
دوشنبه 02 اردیبهشت 1392, 22:33 عصر
سلام.
دوستان چرا فقط دیگران رو تشویق میکنید؟!
اگه خودتون دست به کار بشید و شرکت کنید و برنامه بذارید,دوباره رونق میگیره تایپیک.
شماها شروع کنید,منم هستم...
فقط شروع کنید!!!!!!!!!!!!!

Edward
چهارشنبه 29 خرداد 1392, 14:22 عصر
سلام
این برنامه یه عکس رو باز می کنه ، تغییر سایز میده و تو یه فایل جدید ذخیره می کنه ...


import java.awt.AlphaComposite;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JOptionPane;

public class Resizer {
private static final int IMG_WIDTH = 160;
private static final int IMG_HEIGHT = 120;
private static BufferedImage resizeImage(BufferedImage originalImage, int type){
BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
g.dispose();

return resizedImage;
}

private static BufferedImage resizeImageWithHint(BufferedImage originalImage, int type){

BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
g.dispose();
g.setComposite(AlphaComposite.Src);

g.setRenderingHint(RenderingHints.KEY_INTERPOLATIO N,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.setRenderingHint(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING ,
RenderingHints.VALUE_ANTIALIAS_ON);

return resizedImage;
}
public static void resize(String ico,String folder) {
try{

BufferedImage originalImage = ImageIO.read(new File(ico));
int type = originalImage.getType() == 0? BufferedImage.TYPE_INT_ARGB : originalImage.getType();

//BufferedImage resizeImageJpg = resizeImage(originalImage, type);
//ImageIO.write(resizeImageJpg, "jpg", new File(folder));

//BufferedImage resizeImagePng = resizeImage(originalImage, type);
//ImageIO.write(resizeImagePng, "png", new File(folder));

BufferedImage resizeImageHintJpg = resizeImageWithHint(originalImage, type);
ImageIO.write(resizeImageHintJpg, "jpg", new File(folder));

BufferedImage resizeImageHintPng = resizeImageWithHint(originalImage, type);
ImageIO.write(resizeImageHintPng, "png", new File(folder));

}catch(IOException e){
System.out.println(e.getMessage());
}
}

}

Neda.T
پنج شنبه 30 خرداد 1392, 20:36 عصر
تبدیل اعداد چهاررقمی به صورت حروفی

*
* in barname baray tabdil yek adad chahar raghami be horof ast.
*
*/

import java.util.Scanner;


public class num_convert {


public static void main(String[] args) {
int a = 0,b = 0,c = 0 , counter=1;
int n=0 , m=0;
Scanner in = new Scanner(System.in);
System.out.print( "Input A Number In Range Of 1000-9999?\n" ) ;
n = in.nextInt();

if ( n >= 10000 || n < 1000 )
{
System.out.print ( "Your Number Should Be In Range Of 1000 -9999\n " );
counter=3 ;
}
m = n ;
while ( counter <= 2 )
{
if ( counter == 1)

n = n / 1000 ;

else if ( counter == 2 )

n = m % 1000 ;
c = n % 10 ;
n = n / 10 ;
b = n % 10 ;
n = n / 10 ;
a = n % 10 ;
n = n / 10 ;
if ( a == 1 )
System.out.print ( "sado " ) ;
else if ( a == 2 )
System.out.print ( "devisto " ) ;
else if ( a == 3 )
System.out.print ( "sisado " ) ;
else if ( a == 4 )
System.out.print ( "chaharsado " ) ;
else if ( a == 5 )
System.out.print ( "pansado " ) ;
else if ( a == 6 )
System.out.print ( "sheshsado " ) ;
else if ( a == 7 )
System.out.print ( "haftsado " ) ;
else if ( a == 8 )
System.out.print ( "hashtsado " ) ;
else if ( a == 9 )
System.out.print ( "nohsado " ) ;
if ( b == 1 )
{
if ( c == 1 )
System.out.print ( "yazdaho " ) ;
else if ( c == 2 )
System.out.print ( "davazdaho " ) ;
else if ( c == 3 )
System.out.print ( "sizdaho " ) ;
else if ( c == 4 )
System.out.print ( "chahardaho " ) ;
else if ( c == 5 )
System.out.print ( "panzdaho " ) ;
else if ( c == 6 )
System.out.print ( "shanzdaho " ) ;
else if ( c == 7 )
System.out.print ( "hefdaho " ) ;
else if ( c == 8 )
System.out.print ( "hejdaho " ) ;
else if ( c == 9 )
System.out.print ( "noozdaho " ) ;
else if ( c == 0 )
System.out.print ( "dah " ) ;
}
else if ( b == 2 )
System.out.print ( "bisto " ) ;
else if ( b == 3 )
System.out.print ( "sio " ) ;
else if ( b == 4 )
System.out.print ( "chehelo " ) ;
else if ( b == 5 )
System.out.print ( "panjaho " ) ;
else if ( b == 6 )
System.out.print ( "shasto " ) ;
else if ( b == 7 )
System.out.print ( "haftado " ) ;
else if ( b == 8 )
System.out.print ( "hashtado " ) ;
else if ( b == 9 )
System.out.print ( "nohsado " ) ;
if ( b != 1 )
{
if ( c == 1 )
System.out.print ( "yek " ) ;
if ( c == 2 )
System.out.print ( "do " ) ;
if ( c == 3 )
System.out.print ( "se " ) ;
if ( c == 4 )
System.out.print ( "chahar " ) ;
if ( c == 5 )
System.out.print ( "panj " ) ;
if ( c == 6 )
System.out.print ( "shesh " ) ;
if ( c == 7 )
System.out.print ( "haft " ) ;
if ( c == 8 )
System.out.print ( "hasht " ) ;
if ( c == 9 )
System.out.print ( "noh " ) ;
}
if (counter == 1 && m >= 1000 )
System.out.print ( "hezaro " ) ;
counter = counter + 1 ;
}

}

}

Neda.T
پنج شنبه 30 خرداد 1392, 20:39 عصر
حذف حروف تکراری از یک جمله وردی


import java.io.*;


public class removechar {



public static void main(String[] args) throws Exception{
{



System.out.println("enter a statement:");

BufferedReader br =new BufferedReader(new InputStreamReader(System.in));

String inputString = br.readLine();

System.out.println("Original String is: "+inputString);

inputString = inputString.replaceAll((String.format("(.)(?<=(?:(?=\\1).).{0,%d}(?:(?=\\1).))", inputString.length())), "");

System.out.println("New String is: "+inputString);



}

m.a.d1992
شنبه 01 تیر 1392, 02:24 صبح
سلام
منم در پاسخ به دوستان خوبی که برنامه های خودشونو میزارن و می خوان این تاپیک توسعه پیدا کنه گفتم چندتا برنامه که خودم نوشتم رو بزارم
قبل از هر چیز یه کلاس میزارم که تقریبا همه جا استفاده میشه، البته توو پروژه های swing (یا خودمونی بگم همون ویندوزی )

این کلاس دو تا متد داره که اولی پنجره یا فرمی که بش پاس میدی میزاره وسط مانیتور، فرقی نمیکنه مانیتورش چه اندازه ای باشه این متد دقیقا فرم شما رو میزاره وسط مانیتور!
متد دوم کارش اینه که فرم رو از حالت خشک و یه نواختی که هست تبدیل به فرم ویندوزی میکنه یعنی کسی متوجه نمیشه که شما این برنامه رو با زبان جاوا نوشتین یا سی شارپ!


من که از این کلاس توو همه ی برنامه های ویندوزی م استفاده کردم امیدوارم برای شما مفید باشه

/*
* class tools 2 ta tabe mohem ke estefade mishe dare
*
* Programer: AbdolsalamDehvari mad
*/
package ToolsPackage;

import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class Tools {

// in tabe baraye gharar dadane frame dar vasate monitor e.
public static void setLocation(JFrame jframe) {
double w = Toolkit.getDefaultToolkit().getScreenSize().getWid th();
double h = Toolkit.getDefaultToolkit().getScreenSize().getHei ght();
w = (w - jframe.getWidth()) / 2;
h = (h - jframe.getHeight()) / 2;
jframe.setLocation((int) w, (int) h);
}

// in tabe baraye windows y kardane frame ha estefade mishe.
public static void setWindowsStyle(JFrame jf) {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
SwingUtilities.updateComponentTreeUI(jf);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
JOptionPane.showMessageDialog(null, e, "WindowsStyle", 0);
}
}
}

m.a.d1992
شنبه 01 تیر 1392, 02:31 صبح
نمی دونم مسئله برج هانوی رو شنیدین یا نه، اگه نشنیدین کافی یه سرچ بزنین خیلی مسئله ی جالبه، برنامه زیر این مسئله رو حل میکنه


package borje_hanoy;
import java.util.Scanner;

public class Borje_hanoy
{
public static void hanoy (int N, char a, char b, char c)
{
if( N == 1 )
{
System.out.println("Disk 1 from " + a + " to " + c );
}
else
{
hanoy ( N-1, a, c, b);
System.out.println( "Disk " + N + " from "+ a + " to " + c);
hanoy( N-1, b, a, c );
}
}
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
int disk;
System.out.println("tedade disk ra vared konid");
disk = s.nextInt();
Borje_hanoy.hanoy( disk, 'A', 'B', 'C' );
}
}

m.a.d1992
شنبه 01 تیر 1392, 02:37 صبح
برنامه ی زیر رو برای یکی از دوستام نوشتم، امید وارم براتوون جالب باشه

کارش اینه یه سری اطلاعات مثل نام، نام خانوادگی، .... شماره بیمه و نوع بیمه رو میگیره و میریزه توو یه آرایه بعد یه نام میگره اگه نام توو آرایه باشه اطلاعات بیمه ش رو چاپ میکنه و اگه وجود نداتشته باشه که هیچی . .

/*
* dty vadte blch
*/
package bimeh;

import java.util.Scanner;


public class Bimeh {
/**
* @param args the command line arguments
*/
static public void Search(String[][] A, String Nam, int tedad) {
for (int i = 0; i < tedad; i++) {
if (A[i][0].equals(Nam)) {
System.out.println("nam: " + A[i][0]
+ " famil: " + A[i][1]
+ " nam pedar: " + A[i][2]
+ " shomare shenasname: " + A[i][3]
+ " shomare bime: " + A[i][4]
+ " no'e bime: " + A[i][5]);
} // end if
} // end for
} // end Search method
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String[][] bimeshodeghan = new String[1000][6];
int tedad; // tedade bime shodeghan vared shode
boolean kontrol = true;

System.out.println("tedad ra vared konid:");
tedad = in.nextInt();

for (int i = 0; i < tedad; i++) {
System.out.println("nam ra vared konid:");
bimeshodeghan[i][0] = in.next();
System.out.println("famil ra vared konid:");
bimeshodeghan[i][1] = in.next();
System.out.println("nam pedar ra vared konid:");
bimeshodeghan[i][2] = in.next();
System.out.println("shomare shenasname ra vared konid:");
bimeshodeghan[i][3] = in.next();
System.out.println("shomare bime ra vared konid:");
bimeshodeghan[i][4] = in.next();
System.out.print("no'e bime ra vared konid:\n"
+ "a:bime rosta'ee\n"
+ "b:bime farhangyan\n"
+ "c:bime tamine ejtema'ee\n"
+ "d:bime khadamate darmani\n");
bimeshodeghan[i][5] = in.next();
} // end for
while (kontrol) {
System.out.println("Search: nam morede nazar khod ra vared konid");
Search(bimeshodeghan, in.next(), tedad);
System.out.println("aya mikhahid dobare search konid?{Y/N}");
if (in.next().equals("y")) {
kontrol = true;
} else {
kontrol = false;
}
} // end while
System.out.println("Program ended");
} // end main
} // end class Bime

m.a.d1992
شنبه 01 تیر 1392, 02:40 صبح
برنامه ی زیر مربع جادویی رو برای شما به اندازه مقداری که وارد می کنید چاپ میکننه

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package magic.table;

import java.util.Scanner;

public class MagicTable {

public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("n ra vared konid");
int n = s.nextInt();
int[][] a = new int[n][n];
int y = n * n;
//
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
a[i][j] = 0;
}
}
int h = 1;
int g = 0;
int d = 0;
while (h != y + 1) {
a[g][d] = h;
h++;
g--;
d--;
if (g < 0) {
g = n - 1;
}
if (d < 0) {
d = n - 1;
}
if (a[g][d] > 0) {
g = g + 1;
if (g > n - 1) {
g = 1;
}
d++;
d++;
if (d > n - 1) {
d = 1;
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
System.out.print(a[i][j] + " ");
}
System.out.println();
}
System.out.println("Program ended (By: abdolsalam dehvari)");
}
}

m.a.d1992
شنبه 01 تیر 1392, 02:46 صبح
برنامه زیر یه عدد حدس میزنه و بعدش از شما یه عدد میگره و به شما میگه عدد وارده ی شما که حدس شما می باشد از عددی که توسط برنامه در نظر گرفته شده کوچیک تره یا بزرگ تر، این کار اونقد ادامه پیدا میکنه تا عدد حدسی شما با عددی که برنامه در نظر گرفته یکی بشه اون وخ برنامه پیغام مناسبی چاپ میکنه

/*
* Random Game Number
* By: Abdolsalam Dehvari
*/
package randomgame;

import javax.swing.*;
import java.lang.Math.*;
//
public class RandomGame {

public static void main(String[] args) {
final int max = 100, min = 0;
int result;
int randomNumber = (int) Math.floor(
Math.random() * (max - min + 1) + min);
//
result = Integer.parseInt(
JOptionPane.showInputDialog("Enter your suggest"));
//
while (result != randomNumber) {
if (result > randomNumber) {
JOptionPane.showMessageDialog(
null, "your suggest is more than magic number");
}
if (result < randomNumber) {
JOptionPane.showMessageDialog(
null, "your suggest is lower than magic number");
}
result = Integer.parseInt(
JOptionPane.showInputDialog("Enter your suggest"));
}
if (result == randomNumber) {
JOptionPane.showMessageDialog(null, "you are win \n"
+ "the magic number is: "
+ randomNumber);
}
}
}

m.a.d1992
شنبه 01 تیر 1392, 02:49 صبح
امیدوارم این چند برنامه ای که براتوون گذاتشم مفید باشه
ایشاالله سعی می کنم برنامه های بیشتری بزارم

m.a.d1992
شنبه 01 تیر 1392, 14:30 عصر
سلام دوستان
چند وخ پیش که تازه استادمون به ما جاوا تدریس می کرد و همین جا ازش تشکر می کنم که جاوا رو به آموخت واقعا استاد خوبی بود
خلاصه ایشون سره کلاساشون مثال آماده توضیح می دادن که مطالب بیشتر جا بیافته، مثال های شی گرایی، وراثت، چندریختی، واسط ها و ... که من تصمیم گرفتم این مثال ها رو بزارم براتوون امید وارم مفید باشه

اولین مثال:
با عنوان composition

/*
*
* AbdolsalamDehvari mad
*/
public class SprinklerSystem {

private String valve1, valve2, valve3, valve4;
private WaterSource source = new WaterSource();
private int i;
private float f;
@Override
public String toString() {
return
"valve1 = " + valve1 + " " +
"valve2 = " + valve2 + " " +
"valve3 = " + valve3 + " " +
"valve4 = " + valve4 + "\n" +
"i = " + i + " " + "f = " + f + " " +
"source = " + source;}

public static void main(String[] args) {
SprinklerSystem sprinklers = new SprinklerSystem();
System.out.println(sprinklers);
}

}

/*
*
* AbdolsalamDehvari mad
*/
class WaterSource {

private String s;

WaterSource() {
System.out.println("WaterSource()");
s = "Constructed";
}

@Override
public String toString() {
return s;
}
}

m.a.d1992
شنبه 01 تیر 1392, 14:32 عصر
مثال دوم:
با عنوان Object Initialization

/*
*
* AbdolsalamDehvari mad
*/

public class Bath {
// Initializing at point of definition

private String s1 = "Happy", s2 = "Happy", s3, s4;
private Soap castille;
private int i;
private float toy;

public Bath() {
System.out.println("Inside Bath()");
s3 = "Joy";
toy = 3.14f;
castille = new Soap();
}
// Instance initialization:

{
i = 47;
}

@Override
public String toString() {
if (s4 == null)// Delayed initialization:
{
s4 = "Joy";
}
return "s1 = " + s1 + "\n" + "s2 = " + s2 + "\n" + "s3 = " + s3 + "\n"
+ "s4 = " + s4 + "\n"
+ "i = " + i + "\n"
+ "toy = " + toy + "\n"
+ "castille = " + castille;
}

public static void main(String[] args) {
Bath b = new Bath();
System.out.println(b);
}
}

/*
*
* AbdolsalamDehvari mad
*/
class Soap {
private String s;
Soap() {
System.out.println("Soap()");
s = "Constructed";
}
public String toString() { return s; }
}

m.a.d1992
شنبه 01 تیر 1392, 14:37 عصر
مثال سوم:
با عنوان Inheritance 1 یا همون وراثت البته قسمت اولش

/*
*
* AbdolsalamDehvari mad
*/
class Cleanser {

private String s = "Cleanser";

public void append(String a) {
s += a;
}

public void dilute() {
append(" dilute()");
}

public void apply() {
append(" apply()");
}

public void scrub() {
append(" scrub()");
}

public String toString() {
return s;
}

public static void main(String[] args) {
Cleanser x = new Cleanser();
x.dilute();
x.apply();
x.scrub();
System.out.println(x);
}
}


/*
*
* AbdolsalamDehvari mad
*/
public class Detergent extends Cleanser {
// Change a method:

@Override
public void scrub() {
append(" Detergent.scrub()");
super.scrub(); // Call base-class version
}
// Add methods to the interface:

public void foam() {
append(" foam()");
}
// Test the new class:

public static void main(String[] args) {
Detergent x = new Detergent();
x.dilute();
x.apply();
x.scrub();
x.foam();
System.out.println(x);
System.out.println("Testing base class:");
Cleanser.main(args);
}
}

m.a.d1992
یک شنبه 02 تیر 1392, 03:47 صبح
سلام خدمت همه دوستان، امیدوارم تا به اینجا از برنامه هایی که گذاشتم لذت برده باشید

برنامه ای که الان براتتون میزازم زو از یه سایت خارجی که دقیقا اسمش رو نمی دونم چی بود چند وخ پبش گرفتم و کارش اینه که لیست تمامی اتصالات شبکه ی شما رو به همراه آی پی و اطلاعات دیگه بهتون نشون میده، امیدورام بتونه مفید باشه

/*
* AbdolsalamDehvari mad
*/
package javaapplication32;

import java.io.*;
import java.net.*;
import java.util.*;
import static java.lang.System.out;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
* @author Administrator
*/
public class JavaApplication32 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
for (NetworkInterface netint : Collections.list(nets)) {
displayInterfaceInformation(netint);
}
} catch (SocketException ex) {
System.err.println("error");
}
}

static void displayInterfaceInformation(NetworkInterface netint) throws SocketException {
out.printf("Display name: %s\n", netint.getDisplayName());
out.printf("Name: %s\n", netint.getName());
Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
for (InetAddress inetAddress : Collections.list(inetAddresses)) {
out.printf("InetAddress: %s\n", inetAddress);
}
out.printf("\n");
}
}

m.a.d1992
یک شنبه 02 تیر 1392, 14:47 عصر
سلام
امروز میخوام ادامه ی مثال ها رو براتوون بزارم
مثال چهارم:
عنوان: ادامه ی وراثت

/*
* AbdolslamDehvari mad
*/
class Game {

Game(int i) {
System.out.println("Game constructor");
}
}

class BoardGame extends Game {

BoardGame(int i) {
super(i);//must be first
System.out.println("BoardGame constructor");
}
}

public class Chess extends BoardGame {

Chess() {
super(11);
System.out.println("Chess constructor");
}

public static void main(String[] args) {
Chess x = new Chess();
}
}

m.a.d1992
یک شنبه 02 تیر 1392, 14:48 عصر
مثال پنجم:
عنوان: وراثت و ترکیب

/*
* AbdolslamDehvari mad
*/

class Plate {

Plate(int i) {
System.out.println("Plate constructor");
}
}

class DinnerPlate extends Plate {

DinnerPlate(int i) {
super(i);
System.out.println("DinnerPlate constructor");
}
}

class Utensil {

Utensil(int i) {
System.out.println("Utensil constructor");
}
}

class Spoon extends Utensil {

Spoon(int i) {
super(i);
System.out.println("Spoon constructor");
}
}

class Fork extends Utensil {

Fork(int i) {
super(i);
System.out.println("Fork constructor");
}
}

class Knife extends Utensil {

Knife(int i) {
super(i);
System.out.println("Knife constructor");
}
}
// A cultural way of doing something:
class Custom {

Custom(int i) {
System.out.println("Custom constructor");
}
}

public class PlaceSetting extends Custom {

private Spoon sp;
private Fork frk;
private Knife kn;
private DinnerPlate pl;

public PlaceSetting(int i) {
super(i + 1);
sp = new Spoon(i + 2);
frk = new Fork(i + 3);
kn = new Knife(i + 4);
pl = new DinnerPlate(i + 5);
System.out.println("PlaceSetting constructor");
}

public static void main(String[] args) {
PlaceSetting x = new PlaceSetting(9);
}
}

m.a.d1992
یک شنبه 02 تیر 1392, 14:51 عصر
مثال ششم:
عوان: پایان وراثت


/*
* AbdolslamDehvari mad
*/
class Villain {
private String name;
protected void set(String nm) { name = nm; }
public Villain(String name) { this.name = name; }
public String toString() {
return "I’m a Villain and my name is " + name;
}
}
public class Orc extends Villain {
private int orcNumber;
public Orc(String name, int orcNumber) {
super(name);
this.orcNumber = orcNumber;
}
public void change(String name, int orcNumber) {
set(name); // Available because it’s protected
this.orcNumber = orcNumber;
}
public String toString() {
return "Orc " + orcNumber + ": " + super.toString();
}
public static void main(String[] args) {
Orc orc = new Orc("reza", 12);
System.out.println(orc);
Orc s = new Orc("d",12);
s.change("sa",12 );
System.out.println(orc);
}
}

m.a.d1992
یک شنبه 02 تیر 1392, 14:52 عصر
مثال هفتم:
عنوان: upcasting

/*
* AbdolslamDehvari mad
*/
class Instrument {
public void play() {}
static void tune( Instrument i ) {
// ...
i.play();
}
}
// Wind objects are instruments
// because they have the same interface:
public class Wind extends Instrument {

public static void main(String[] args) {
Wind flute = new Wind();
Instrument in = new Instrument();
Instrument.tune(in);
Instrument.tune(flute); // Upcasting
}
}

AfshinHonari
چهارشنبه 12 تیر 1392, 02:30 صبح
سلام یه ماشین حساب خیلی ساده با ظاهر گرافیکی
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
import java.awt.Font;


public class Main extends JFrame {

/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTextField txtScreen;
private double result = 0;

private enum Action {
nothing,sum,sub,div,mul
};

private Action lastAction = Action.nothing;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Main frame = new Main();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the frame.
*/
public Main() {
setResizable(false);
setTitle("Basic Calculator");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(200, 200, 266, 290);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);

JButton btn1 = new JButton("1");
btn1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (txtScreen.getText().equals("0") || txtScreen.getText().equals("0.0")){
txtScreen.setText("");
}
txtScreen.setText(txtScreen.getText() + "1");
}
});
btn1.setBounds(10, 171, 50, 29);
contentPane.add(btn1);

JButton btn2 = new JButton("2");
btn2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (txtScreen.getText().equals("0") || txtScreen.getText().equals("0.0")){
txtScreen.setText("");
}
txtScreen.setText(txtScreen.getText() + "2");
}
});
btn2.setBounds(72, 171, 50, 29);
contentPane.add(btn2);

JButton btn3 = new JButton("3");
btn3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (txtScreen.getText().equals("0") || txtScreen.getText().equals("0.0")){
txtScreen.setText("");
}
txtScreen.setText(txtScreen.getText() + "3");
}
});
btn3.setBounds(132, 171, 50, 29);
contentPane.add(btn3);

JButton btn6 = new JButton("6");
btn6.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (txtScreen.getText().equals("0") || txtScreen.getText().equals("0.0")){
txtScreen.setText("");
}
txtScreen.setText(txtScreen.getText() + "6");
}
});
btn6.setBounds(132, 131, 50, 29);
contentPane.add(btn6);

JButton btn5 = new JButton("5");
btn5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (txtScreen.getText().equals("0") || txtScreen.getText().equals("0.0")){
txtScreen.setText("");
}
txtScreen.setText(txtScreen.getText() + "5");
}
});
btn5.setBounds(72, 131, 50, 29);
contentPane.add(btn5);

JButton btn4 = new JButton("4");
btn4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (txtScreen.getText().equals("0") || txtScreen.getText().equals("0.0")){
txtScreen.setText("");
}
txtScreen.setText(txtScreen.getText() + "4");
}
});
btn4.setBounds(10, 131, 50, 29);
contentPane.add(btn4);

JButton btn9 = new JButton("9");
btn9.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (txtScreen.getText().equals("0") || txtScreen.getText().equals("0.0")){
txtScreen.setText("");
}
txtScreen.setText(txtScreen.getText() + "9");
}
});
btn9.setBounds(132, 91, 50, 29);
contentPane.add(btn9);

JButton btn8 = new JButton("8");
btn8.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (txtScreen.getText().equals("0") || txtScreen.getText().equals("0.0")){
txtScreen.setText("");
}
txtScreen.setText(txtScreen.getText() + "8");
}
});
btn8.setBounds(72, 91, 50, 29);
contentPane.add(btn8);

JButton btn7 = new JButton("7");
btn7.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (txtScreen.getText().equals("0") || txtScreen.getText().equals("0.0")){
txtScreen.setText("");
}
txtScreen.setText(txtScreen.getText() + "7");
}
});
btn7.setBounds(10, 91, 50, 29);
contentPane.add(btn7);

JButton btnEqual = new JButton("=");
btnEqual.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
switch (lastAction){
case sum : result += Double.parseDouble(txtScreen.getText()); break;
case sub : result -= Double.parseDouble(txtScreen.getText()); break;
case div :
if (txtScreen.getText().equals("0") || txtScreen.getText().equals("0.0")){
txtScreen.setText("Error");
return;
}
result /= Double.parseDouble(txtScreen.getText());
break;
case mul : result *= Double.parseDouble(txtScreen.getText()); break;
default : break;
}
lastAction = Action.nothing;
txtScreen.setText(String.valueOf(result));
}
});
btnEqual.setBounds(132, 211, 50, 29);
contentPane.add(btnEqual);

JButton btnDot = new JButton(".");
btnDot.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String thisText = txtScreen.getText();
if (!thisText.contains(".")){
txtScreen.setText(txtScreen.getText() + ".");
}
}
});
btnDot.setBounds(72, 211, 50, 29);
contentPane.add(btnDot);

JButton btn0 = new JButton("0");
btn0.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (txtScreen.getText().equals("0") || txtScreen.getText().equals("0.0")){
txtScreen.setText("");
}
txtScreen.setText(txtScreen.getText() + "0");
}
});
btn0.setBounds(10, 211, 50, 29);
contentPane.add(btn0);

txtScreen = new JTextField();
txtScreen.setText("0");
txtScreen.setFont(new Font("Tahoma", Font.PLAIN, 14));
txtScreen.setBounds(10, 11, 232, 29);
contentPane.add(txtScreen);
txtScreen.setColumns(10);

JButton btnMul = new JButton("*");
btnMul.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (!String.valueOf(result).equals(txtScreen.getText( ))){
result *= Double.parseDouble(txtScreen.getText());
}
txtScreen.setText("0");
lastAction = Action.mul;
}
});
btnMul.setBounds(192, 91, 50, 29);
contentPane.add(btnMul);

JButton btnDivide = new JButton("/");
btnDivide.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (txtScreen.getText().equals("0") || txtScreen.getText().equals("0.0")){
txtScreen.setText("Error");
return;
}
if (!String.valueOf(result).equals(txtScreen.getText( ))){
result /= Double.parseDouble(txtScreen.getText());
}
txtScreen.setText("0");
lastAction = Action.div;
}
});
btnDivide.setBounds(192, 131, 50, 29);
contentPane.add(btnDivide);

JButton btnSub = new JButton("-");
btnSub.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (!String.valueOf(result).equals(txtScreen.getText( ))){
result -= Double.parseDouble(txtScreen.getText());
}
txtScreen.setText("0");
lastAction = Action.sub;
}
});
btnSub.setBounds(192, 171, 50, 29);
contentPane.add(btnSub);

JButton btnSum = new JButton("+");
btnSum.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (!String.valueOf(result).equals(txtScreen.getText( ))){
result += Double.parseDouble(txtScreen.getText());
}
txtScreen.setText("0");
lastAction = Action.sum;

}
});
btnSum.setBounds(192, 211, 50, 29);
contentPane.add(btnSum);

JButton btnClear = new JButton("Clear Screen");
btnClear.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
txtScreen.setText("0");
result = 0;
}
});
btnClear.setBounds(10, 51, 112, 29);
contentPane.add(btnClear);

JButton btnBackspace = new JButton("Backspace");
btnBackspace.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String thisText = txtScreen.getText();
if (!thisText.equals("")){
thisText = thisText.substring(0, thisText.length()-1);
if (thisText.equals("")){
thisText = "0";
}
} else {
thisText = "0";
}
txtScreen.setText(thisText);
}
});
btnBackspace.setBounds(132, 51, 112, 29);
contentPane.add(btnBackspace);
}
}

اگه ایرادی داشت خودتون زحمتشو بکشید،با عرض شرمندگی زیاد روش کار نکردم:خجالت:

AfshinHonari
چهارشنبه 12 تیر 1392, 20:24 عصر
سلام
استفاده از ArrayList و HashMap و Iterator برای ایجاد آرایه با طول پویا و چاپ مقادیر

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;



public class Test {


public static void main(String[] args) {

ArrayList<String> list = new ArrayList<String>();
list.add("A");
list.add("H");
list.add("S");
System.out.println(list); //output : [A, H, S]
list.remove(1);
System.out.println(list); //output : [A, S]
System.out.println(list.get(1)); //output : S
System.out.println(list.indexOf("S")); //output : 1

Iterator<String> li = list.listIterator();
while (li.hasNext()){
System.out.print(li.next() + " | "); //output : A | S |
}

HashMap<Integer, String> hm = new HashMap<Integer, String>();
hm.put(10, "Afshin");
hm.put(20, "Honari");
hm.put(30, "A:H:S");
System.out.println(hm); //output : {20=Honari, 10=Afshin, 30=A:H:S}
hm.remove(30);
System.out.println(hm); //output : {20=Honari, 10=Afshin}
System.out.println(hm.get(10)); //output : Afshin

Set<Integer> hms = hm.keySet();
Iterator<Integer> hmi = hms.iterator();
while(hmi.hasNext()){
int str = hmi.next();
System.out.println(str + " " + hm.get(str)); //output : 20 Honari /n 10 Afshin
}
}

}

Mr.Mars
جمعه 14 تیر 1392, 00:51 صبح
رسم نمودار به صورت گرافیکی با تعیین طول بازه
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class rasme_nomodar extends JFrame{
private static final long serialVersionUID = 1L;
private JTextArea zz;
private JTextField z,xx;
JLabel m,n;
private JButton btn;
private Boolean boo=false;
public void paint(Graphics g)
{

super.paint(g);
g.setColor(Color.WHITE);
g.drawLine(400,25,400,597);
g.drawLine(0, 300, 800, 300);
if(boo==true){
for(int i=0;i<=(int)strtodou(z.getText());i++){
String zz="("+xx.getText()+")";
int s=(int) parant(zz,i);
int ss=(int)parant(zz,i+1);
g.setColor(Color.red);
g.drawLine(i*2+401, 301-s,401+(( i+1)*2), 301-ss);

}
for(int i=-(int)strtodou(z.getText());i<=0;i++){
String zz="("+xx.getText()+")";
int s=(int) parant(zz,i);
int ss=(int)parant(zz,i+1);
g.setColor(Color.blue);
g.drawLine(i*2+401, 301-s,401+(( i+1)*2), 301-ss);

}
}

}
public rasme_nomodar(){
this.setTitle("Nomadar");
this.setBounds(100 , 50 , 800 , 600);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
this.getContentPane().setBackground(Color.BLACK);
this.setResizable(false);
this.setLayout(null);
this.setVisible(true);

zz=new JTextArea();
zz.setText("");
zz.setBounds(5 , 0 , 105 , 20);
zz.setBackground(Color.white);
this.getContentPane().add(zz);

z=new JTextField();
z.setBounds(5,55, 100, 20);
z.setForeground(Color.green);
z.setText("Enter Mahdode");
z.setEnabled(false);
z.addMouseListener(new MouseListener() {
public void mouseReleased(MouseEvent arg0) {

}

public void mousePressed(MouseEvent arg0) {

}

public void mouseExited(MouseEvent arg0) {

}

public void mouseEntered(MouseEvent arg0) {
}
public void mouseClicked(MouseEvent arg0) {
z.setEnabled(true);
z.setText(null);
}
});
this.getContentPane().add(z);

xx=new JTextField();
xx.setBounds(5,30, 100, 20);
xx.setForeground(Color.red);
xx.setText("Enter X");
xx.setEnabled(false);
xx.addMouseListener(new MouseListener() {
public void mouseReleased(MouseEvent arg0) {

}

public void mousePressed(MouseEvent arg0) {

}

public void mouseExited(MouseEvent arg0) {

}

public void mouseEntered(MouseEvent arg0) {
}
public void mouseClicked(MouseEvent arg0) {
xx.setEnabled(true);
xx.setText(null);
}
});
this.getContentPane().add(xx);

btn=new JButton();
btn.setText("DRAW");
btn.setBounds(115, 0, 100, 20);
this.getContentPane().add(btn);
btn.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
press(e);

}
});


this.addMouseListener(new MouseListener() {
public void mouseReleased(MouseEvent arg0) {
}
public void mousePressed(MouseEvent arg0) {
}
public void mouseExited(MouseEvent arg0) {
}

@Override
public void mouseEntered(MouseEvent arg0) {
}

@Override
public void mouseClicked(MouseEvent arg0) {
}
});
this.addMouseMotionListener(new MouseMotionListener() {
@Override
public void mouseMoved(MouseEvent e) {
mousemove(e);
}

@Override
public void mouseDragged(MouseEvent arg0) {

}
});
}
public void press(ActionEvent e){
this.repaint();
boo=true;
paint(null);
boolean iscontinue=true;
if (z.getText().equals(""))
{
z.setBackground(Color.red);
iscontinue=false;
}
else
z.setBackground(Color.WHITE);
if(xx.getText().equals("")){
xx.setBackground(Color.red);
iscontinue=false;
}
else
xx.setBackground(Color.WHITE);
if (!iscontinue)
{
JOptionPane.showMessageDialog(null , "Please Enter Red Fields");
return;
}
}

public static void main(String[] args)
{
JFrame.setDefaultLookAndFeelDecorated(true);
new rasme_nomodar();
}
public void mousemove(MouseEvent e){
int i=e.getX()-400;
int ii=300-e.getY();
zz.setText("Moved to ("+i+","+ii+")");
}
public static double strtodou(String e)
{
int i = 0,x = 1, d = 1;
int a = 0;
if(e.charAt(i)=='-')
{
d = -1;
i++;
}
if(e.charAt(i)=='+')
i++;
double r = 0;
while(i<e.length())
{
r = r*10+(e.charAt(i++)-'0');
if(i==e.length())
break;
if(x>1)
x*=10;
if(e.charAt(i)=='.')
{
i++;
x*=10;
}
if(x>1000000)
{
a ++;
break;
}
}
if(a>0)
x/=10;
return (r/(x*1.0))*d;
}//end of strtodou

public int mt=1;
////////////////////////////////////Math/////////////////////////////////////
public double exp(double x){
double s=1;
for(int i=0;i<=1000;i++){
double k=1;
for(int j=1;j<=i;j++){
k*=(x*1.0/j);
}
s+=k;
}
return s;
}
//***********************************//
public double sin(double x){
int a=-1;
x=Math.toRadians(x);
double s=x;
for(int i=3;i<=1000;i+=2){
double k=1;
for(int j=1;j<=i;j++){
k*=(x*1.0/j);
}
s+=k*a;
a*=-1;
}
return s;
}
//***********************************//
public double cos(double x){
int a=-1;
x=Math.toRadians(x);
double s=1;
for(int i=2;i<=1000;i+=2){
double k=1;
for(int j=1;j<=i;j++){
k*=(x*1.0/j);
}
s+=k*a;
a*=-1;
}
return s;
}
//***********************************//


/////////////////////////////////////////////////////////////////////////////
public double toDouble(String s){
double n=0;

for(int i=0;i<s.length();i++){
if(s.charAt(i)>='0'&&s.charAt(i)<='9'){
int p=1;
boolean as = false;
int t=10;
n=s.charAt(i)-'0';
while(i+p<s.length()){
if((s.charAt(i+p)>='0'&&s.charAt(i+p)<='9')){
if(!as){n=n*10+s.charAt(i+p)-'0';}
if(as){n=n+(s.charAt(i+p)-'0')*1.0/t;t*=10;}
p++;
}
else if(s.charAt(i+p)=='.'){
as=true;p++;
}
else break;

}
i+=p-1;
continue;
}
}
if(s.charAt(0)=='-')n=-n;
return n;
}
public double toarr(String s,double x)
{

double a[]=new double[s.length()];
char b[] = new char [s.length()];
int j=0;
for(int i=0;i<s.length();i++){
if(s.charAt(i)>='0'&&s.charAt(i)<='9'){
int p=1;
boolean as = false;
boolean na = false;
int t=10;
double n=s.charAt(i)-'0';
if(i>0)
if(s.charAt(i-1)=='-'){
if(i-2>0){
if(!(s.charAt(i-2)>='0'&&s.charAt(i-2)<='9')&&!(s.charAt(i-2)=='x')){na=true;}
}
else if(i-2==-1)
na=true;
}
while(i+p<s.length()){
if((s.charAt(i+p)>='0'&&s.charAt(i+p)<='9')){
if(!as)n=n*10+s.charAt(i+p)-'0';
if(as){n=n+(s.charAt(i+p)-'0')*1.0/t;t*=10;}
p++;
}
else if(s.charAt(i+p)=='.'){
as=true;p++;
}
else break;

}
i+=p-1;
a[j]=n;
b[j]='_';
if(na){a[j]*=-1;shifta(a,j-1,1);shiftb(b,j-1,1);j--;}
j++;
continue;
}
if(s.charAt(i)=='+'){
b[j++]='+';
continue;
}
if(s.charAt(i)=='x'){
b[j++]='x';
continue;
}
if(s.charAt(i)=='^'){
b[j++]='^';
continue;
}
if(s.charAt(i)=='-'){

b[j++]='-';
continue;
}
if(s.charAt(i)=='*'){
b[j++]='*';
continue;
}
if(s.charAt(i)=='/'){
b[j++]='/';
continue;
}
if(s.charAt(i)=='s'){
if(i+2<s.length())
if(s.charAt(i+1)=='i'&&s.charAt(i+2)=='n')
{b[j++]='s';i+=2;continue;}
}
if(s.charAt(i)=='c'){
if(i+2<s.length())
if(s.charAt(i+1)=='o'&&s.charAt(i+2)=='s')
{b[j++]='c';i+=2;continue;}
}
if(s.charAt(i)=='t'){
if(i+2<s.length())
if(s.charAt(i+1)=='a'&&s.charAt(i+2)=='n')
{b[j++]='t';i+=2;continue;}
}
if(s.charAt(i)=='c'){
if(i+2<s.length())
if(s.charAt(i+1)=='o'&&s.charAt(i+2)=='t')
{b[j++]='g';i+=2;continue;}
}
if(s.charAt(i)=='l'){
if(i+2<s.length())
if(s.charAt(i+1)=='o'&&s.charAt(i+2)=='g')
{b[j++]='l';i+=2;continue;}
}
if(s.charAt(i)=='s'){
if(i+2<s.length())
if(s.charAt(i+1)=='q'&&s.charAt(i+2)=='r')
{b[j++]='j';i+=2;continue;}
}
if(s.charAt(i)=='e'){
if(i+2<s.length())
if(s.charAt(i+1)=='x'&&s.charAt(i+2)=='p')
{b[j++]='e';i+=2;continue;}
}
}
double r=calc(j,a,b,x);
return r;

}
public void shifta(double a[] ,int p,int l){
for(int i=p;i<a.length-l;i++)
{
if(i+l>=a.length)break;
a[i]=a[i+l];
}
}
public void shiftb(char b[],int p,int l){
for(int i=p;i<b.length-l;i++)
{
if(i+l>=b.length)break;
b[i]=b[i+l];
}
}
public double calc(int j,double a[],char b[],double x){
for(int i=0;i<b.length;i++)
if(b[i]=='x'){
b[i]='_';
a[i]=x;
}

for(int i=0;i<b.length;i++)
if(b[i]=='^'){
if(a[i+1]%2==0&&mt%2==1)
mt=(int)a[i+1];
}
while(j>1){
for(int i=0;i<j-1;i++){
if(b[i]=='^'){
double t=a[i-1];
for(int ii=2;ii<=a[i+1];ii++)a[i-1]*=t;
shifta(a,i,2);shiftb(b,i,2);j-=2;continue;
}

}
for(int i=0;i<j;i++){
if(b[i]=='s'){
a[i]=sin(a[i+1]);shifta(a,i+1,1);shiftb(b,i,1);j--;continue;
}
if(b[i]=='c'){
a[i]=cos(a[i+1]);shifta(a,i+1,1);shiftb(b,i,1);j--;continue;
}
if(b[i]=='t'){
a[i+1]=Math.toRadians(a[i+1]);
a[i]=Math.tan(a[i+1]);shifta(a,i+1,1);shiftb(b,i,1);j--;continue;
}
if(b[i]=='l'){
a[i]=Math.log(a[i+1]);shifta(a,i+1,1);shiftb(b,i,1);j--;continue;
}
if(b[i]=='e'){
a[i]=exp(a[i+1]);shifta(a,i+1,1);shiftb(b,i,1);j--;continue;
}
if(b[i]=='j'){
a[i]=Math.sqrt(a[i+1]);shifta(a,i+1,1);shiftb(b,i,1);j--;continue;
}

}
for(int i=0;i<j-1;i++){
if(b[i]=='*'){
a[i-1]=a[i-1]*a[i+1];shifta(a,i,2);shiftb(b,i,2);j-=2;continue;
}
if(b[i]=='/'){
a[i-1]=a[i-1]/a[i+1];shifta(a,i,2);shiftb(b,i,2);j-=2;continue;
}
}
for(int i=0;i<j-1;i++){
if(b[i]=='+'){
a[i-1]=a[i-1]+a[i+1];shifta(a,i,2);shiftb(b,i,2);j-=2;continue;
}
if(b[i]=='-'){
a[i-1]=a[i-1]-a[i+1];shifta(a,i,2);shiftb(b,i,2);j-=2;continue;
}
}

}
return a[0];

}
public double parant(String s,double x){
for(int i=s.length()-1;i>=0;i--){
if(s.charAt(i)=='('){
int j=1;
String sp ="";
while(s.charAt(i+j)!=')'){
sp=sp+s.charAt(i+j);
j++;
}
double k=toarr(sp,x);
String ss="";
for(int ii=0;ii<i;ii++) ss=ss+s.charAt(ii);
ss=ss+k;
for(int ii=i+j+1;ii<s.length();ii++) ss=ss+s.charAt(ii);
s=ss;
i=s.length()-1;
}
}
double sn=toDouble(s);
return sn;
}
public void Find(String s){
System.out.println("Te'dad Risheha :"+mt);
double a=0,aa=0;
double b=0,bb=0;
double k=1,kk=1;
double i=0,ii=0;
boolean d=false;
int n=0;
while(true){
a=parant(s,i);
aa=parant(s,0);
b=parant(s,ii);
bb=parant(s,0);
if(a==0){System.out.println("Rishe: "+i);d=true;n++;}
if(b==0&&i!=0){System.out.println("Rishe: "+ii);d=true;n++;}
if(mt%2==1&&d)break;
else if(n==mt)break;

if(a*aa<0){System.out.println("Rishe: ["+0+","+i+"]");k=k/10;i-=(k*10);}
if(bb*b<0){System.out.println("Rishe: ["+ii+","+0+"]");kk=kk/10;ii+=(kk*10);}
i+=k;
ii-=kk;
}

}

}

Mr.Mars
جمعه 14 تیر 1392, 01:16 صبح
جمع چند جمله ای
package poroje;
import java.util.Scanner;
public class jam_chand_jomle
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.print("Enter first string:");
String s1=input.nextLine();
System.out.print("Enter second string:");
String s2=input.nextLine();
if(s2.charAt(0)!='-')
s2='+'+s2;
String s="";
int is=0;
s=s1+s2;
if(s.charAt(0)!='-')
s='+'+s;
String ms[]=new String[100];
for(int i=0;i<100;i++)
ms[i]="";
int cms=0;
while(is<s.length())
{
ms[cms]+=s.charAt(is++);
while((s.charAt(is)!='+')&&(s.charAt(is)!='-'))
{
ms[cms]+=s.charAt(is++);
if(is>=s.length())
break;
}//end of second while class
cms++;
}//end of first while class
int ims,z,ca=0,i,sign,t;
int a[]=new int[250];
for(i=0;i<cms;i++)
{
ims=0;
z=0;
t=0;
sign=1;
if(ms[i].charAt(ims)=='-')
sign=-1;
ims++;
if((ms[i].charAt(ims)>='0')&&(ms[i].charAt(ims)<='9'))
{
while((ms[i].charAt(ims)>='0')&&(ms[i].charAt(ims)<='9'))
{
z=z*10+(ms[i].charAt(ims)-'0');
ims++;
if(ims>=ms[i].length())
break;
}//end of while class
if(ims<ms[i].length())
{
ims+=2;
if(ims>=ms[i].length())
t=1;
else
{
ims++;
while((ms[i].charAt(ims)>='0')&&(ms[i].charAt(ims)<='9'))
{
t=t*10+(ms[i].charAt(ims)-'0');
ims++;
if(ims>=ms[i].length())
break;
}//end of while class
}//end of else class
}//end of if class
}//end of if class
else if(ms[i].charAt(ims)=='x')
{
z=1;
ims++;
if(ims>=ms[i].length())
t=1;
else
{
ims++;
while((ms[i].charAt(ims)>='0')&&(ms[i].charAt(ims)<='9'))
{
t=t*10+(ms[i].charAt(ims)-'0');
ims++;
if(ims>=ms[i].length())
break;
}//end of while class
}//end of else class
}//end of else if class
z=z*sign;
a[t]+=z;
if(t>ca)
ca=t;
}//end of for class
for(i=99;i>=2;i--)
{
if(a[i]!=0)
{
if(a[i]<0)
System.out.print(a[i]+"x^"+i);
else
System.out.print("+"+a[i]+"x^"+i);
}//end of if class
}//end of for class
if(a[1]!=0)
{
if(a[1]<0)
System.out.print(a[1]+"x");
else
System.out.print("+"+a[1]+"x");
}//end of if class
if(a[0]!=0)
{
if(a[0]<0)
System.out.print(a[0]);
else
System.out.print("+"+a[0]);
}//end of for class
}//End of main class
}//end of class

Mr.Mars
جمعه 14 تیر 1392, 01:18 صبح
تفریق چند جمله ای
package poroje;
import java.util.Scanner;
public class tafrige_chand_jomle
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.print("Enter first string:");
String s1=input.nextLine();
System.out.print("enter second string:");
String s2=input.nextLine();
if(s2.charAt(0)!='-')
s2='+'+s2;
String s3="";
for(int i=0;i<s2.length();i++)
{
if((s2.charAt(i)!='+')&&(s2.charAt(i)!='-'))
s3+=s2.charAt(i);
if(s2.charAt(i)=='+')
s3+='-';
if(s2.charAt(i)=='-')
s3+='+';
}//end of for class
String s="";
int is=0;
s=s1+s3;
if(s.charAt(0)!='-')
s='+'+s;
String ms[]=new String[100];
for(int i=0;i<100;i++)
ms[i]="";//55*x^6+23//54*x^6+x-x^2-2
int cms=0;
while(is<s.length() )
{
ms[cms]+=s.charAt(is++);
while((s.charAt(is)!='+')&&(s.charAt(is)!='-'))
{
ms[cms]+=s.charAt(is++);
if(is>=s.length())
break;
}//end of second while class
cms++;
}//end of first while class
int ims,z,ca=0,i,sign,t;
int a[]=new int[250];
for(i=0;i<cms;i++)
{
ims=0;
z=0;
t=0;
sign=1;
if(ms[i].charAt(ims)=='-')
sign=-1;
ims++;
if((ms[i].charAt(ims)>='0')&&(ms[i].charAt(ims)<='9'))
{
while((ms[i].charAt(ims)>='0')&&(ms[i].charAt(ims)<='9'))
{
z=z*10+(ms[i].charAt(ims)-'0');
ims++;
if(ims>=ms[i].length())
break;
}//end of while class
if(ims<ms[i].length())
{
ims+=2;
if(ims>=ms[i].length())
t=1;
else
{
ims++;
while((ms[i].charAt(ims)>='0')&&(ms[i].charAt(ims)<='9'))
{
t=t*10+(ms[i].charAt(ims)-'0');
ims++;
if(ims>=ms[i].length())
break;
}//end of while class
}//end of else class
}//end of if class
}//end of if class
else if(ms[i].charAt(ims)=='x')
{
z=1;
ims++;
if(ims>=ms[i].length())
t=1;
else
{
ims++;
while((ms[i].charAt(ims)>='0')&&(ms[i].charAt(ims)<='9'))
{
t=t*10+(ms[i].charAt(ims)-'0');
ims++;
if(ims>=ms[i].length())
break;
}//end of while class
}//end of else class
}//end of else if class
z=z*sign;
a[t]+=z;
if(t>ca)
ca=t;
}//end of for class
for(i=99;i>=2;i--)
{
if(a[i]!=0)
{
if(a[i]<0)
System.out.print(a[i]+"x^"+i);
else
System.out.print("+"+a[i]+"x^"+i);
}//end of if class
}//end of for class
if(a[1]!=0)
{
if(a[1]<0)
System.out.print(a[1]+"x");
else
System.out.print("+"+a[1]+"x");
}//end of if class
if(a[0]!=0)
{
if(a[0]<0)
System.out.print(a[0]);
else
System.out.print("+"+a[0]);
}//end of for class
}//End of main class
}//end of class class

AfshinHonari
یک شنبه 16 تیر 1392, 02:04 صبح
سلام
یه مثال که وا3 کپیه فایل از کلاسای خود جاوا و کلاس File آپاچی استفاده میکنه
106755
بقیه کلاسا از این آدرس قابل دریافتن:
commons.apache.org

skiddie
چهارشنبه 09 بهمن 1392, 23:49 عصر
سلام
برنامه ای با استفاده از شی گرایی برای چاپ 5تا 10 خط رندوم (گرافیکی)


package randomdraw;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class RandomDraw {

public static void main(String[] args) {
line p = new line();
JFrame win = new JFrame();

win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ;

win.add(p);
win.setSize(300,300);
win.setVisible(true);


}
}




package randomdraw;

import java.util.Random;
import java.awt.Graphics;
import java.awt.Color;
import javax.swing.JPanel;

public class line extends JPanel {

private int x1 , x2 , y1 , y2;
private Color c;
private int r;
private int[][] soal = new int[10][4];
private Color[] clr = new Color[10];
Random l = new Random();

public line (){

r = 5 + l.nextInt(6);

for(int i=0 ; i<r ; i++)
{

x1 = l.nextInt(300);
x2 = l.nextInt(300);
y1 = l.nextInt(300);
y2 = l.nextInt(300);

c = new Color(l.nextInt(256), l.nextInt(256) , l.nextInt(256));

soal[i][0] = x1;
soal[i][1] = x2;
soal[i][2] = y1;
soal[i][3] = y2;
clr[i]=c;
}


}


public void paintComponent(Graphics g){

super.paintComponent(g);

setBackground(Color.WHITE);

for(int i=0 ; i<r ; i++)
{ g.setColor(clr[i]);
g.drawLine(soal[i][0],soal[i][1],soal[i][2],soal[i][3]);

}

}
}

mr.dp+
شنبه 23 فروردین 1393, 23:28 عصر
سلام
من یک برنامه خیلی ساده ساختم که میتونه برای کسانی که دارن انگلیسی یاد میگیرن مفید باشه. و همچنین یه بازی خیلی کوچیک هم محسوب میشه
چه کاری میکنه ؟ طبق تصویر چند تا سوال ازتون میپرسه و بعدش یه داستان براتون میسازه (کاملا انگلیسی)
بصورت کامل پروژه رو گذاشتم برای دانلود که روی NetBeans هم ساخته شده !

http://up.ashiyane.org/images/uh7g4ctu8ququ7mq6rj_thumb.jpg (http://up.ashiyane.org/viewer.php?file=uh7g4ctu8ququ7mq6rj.jpg)

لینک دانلود پروژه : Download (http://up.ashiyane.org/images/1c9py8k99g9ry37u9uo.rar)

ftmh02
چهارشنبه 27 فروردین 1393, 00:49 صبح
با سلام وتشکر
نمیشد همین برنامه رو یکم ساده ترو کوتاه ترتر بنویسیم؟ینی به جای اینکه کلاس searchرو بنویسیم با استفاده از تابع بازگشتی عدد اولو پیدا کنیم؟بازم ممنون

ftmh02
پنج شنبه 28 فروردین 1393, 12:00 عصر
salam man taze java ro shoru kardam ye soal kheili sade daram ye kod neveshtam ke kheily kutahe vali nemidunam chera ejra nemishe lotfan komakam konid batashakor:
package javaapplication3;

/**
*
* @author my pc
*/
import java.util.Scanner;
public class JavaApplication3 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

System.out.println("enter 3 number");
double num1;
double num2;
double num3;
Scanner input = new Scanner(System.in);
num1 = input.nextDouble();
num2 = input.nextDouble();
num3 = input.nextDouble();
System.out.println(Math.max(num1,(num2, num3));


}


}

mr.dp+
دوشنبه 08 اردیبهشت 1393, 20:38 عصر
salam man taze java ro shoru kardam ye soal kheili sade daram ye kod neveshtam ke kheily kutahe vali nemidunam chera ejra nemishe lotfan komakam konid batashakor:
package javaapplication3;

/**
*
* @author my pc
*/
import java.util.Scanner;
public class JavaApplication3 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

System.out.println("enter 3 number");
double num1;
double num2;
double num3;
Scanner input = new Scanner(System.in);
num1 = input.nextDouble();
num2 = input.nextDouble();
num3 = input.nextDouble();
System.out.println(Math.max(num1,(num2, num3));


}


}





متد max فقط 2 تا آرگومان میگیره !!!!
اگه شما بخواید بیش از 2 آرگمان استفاده بکنید باید کدتون رو اینطوری بنویسید:
System.out.println(Math.max(num1, Math.max(num2,num3)));

و اینکه پست های اضافه ای که گذاشتید رو لطفا حذف کنید که شلوغ نشه !!!! :لبخندساده:

vahid-p
یک شنبه 14 اردیبهشت 1393, 16:32 عصر
تاپیک خیلی خوبیه و یکی دو ماه هست از وجودش باخبرم اما فعالیتی نداشتم و از نظر من یه اشکالی که وجود داره، ناخواسته باید محدوده ای برای برنامه هامون بذاریم. مثلا من یه بازی که با جاوا نوشته بودم رو میتونم کامل آپلود کنم، ولی مطمئنم به راحتی ازش برای پروژه درسی سوء استفاده میشه و این خط قرمزه برای من. متاسفانه برای همین مجبوریم همیشه یه تیکه خاص از برنامه ها رو بنویسیم که به تنهایی کسی نتونه ازش استفاده کنه و ارزش نمره نداشته باشه.

حالا این انتقادم بود که البته انتقاد از شما نیست، از همه از جمله خودم است که این مشکل راه حلی براش پیدا نکردیم!
اما برای اینکه دست خالی نیومده باشم، یه کد ساده در عین حال کاربردی ( حداقل برای پروژه من نیاز بود، گفتم این تیکش رو بذارم ).
فکر میکنم بتونم با این پیشفرض هایی که گفتم، از این به بعد هر از گاهی یه کد بذارم، و تو این حرکت قشنگتون سهیم باشم.

یک آدرس دایرکتوری ( یا همون پوشه یا فولدر ) رو میگیره، تا هر عمقی اسامی فایل ها و پوشه ها رو به صورت بازگشتی مینویسه. (یه نظمی هم بهش میده )
یه وقت آدرس ندید درایو \:C که اونوقت تا همشو ننویسه ولکن ماجرا نمیشه مگر اینکه برنامه رو کرش کنید.
public static void main(String[] args) throws IOException {
File file=new File("C:\\Program Files\\Java\\jre8"); //Directory address
System.out.println(file.getAbsolutePath());
if(file.isDirectory()){
listFile(file,0);
}
}
public static void listFile(File file,int depth){
for(File f:file.listFiles()){
if(f.isDirectory()){
for(int i=0;i<depth;i++) System.out.print("|"+"\t");
System.out.println("|_"+f.getName());
listFile(f,depth+1);
}else{
for(int i=0;i<depth;i++) System.out.print("|"+"\t");
System.out.println("|_"+f.getName());
}
}
}

A.iman
شنبه 27 اردیبهشت 1393, 15:07 عصر
یه مبحثی توی فیزیک قبل از اختراع کامپیوتر مطرح بود که میگه چه زمانی ماده از بالای یه جسم میتونه به پائین تراوش کنه ؟ مثلا تو عکس زیر ما هر خونه ای که داریم یا بازه(سفید) یا بسته است(سیاه) یا بازه و مایع توشه(ابی) . زمانی که از سطح بالا با استفاده از خونه های باز همجوار راهی به سطح پائین وجود داشته باشه ، میگیم که توارش انجام شده .
119131
ازمایشها نشون دادن که pی استانه ای وجود دارد به گونه ای که اگر احتمال باز بودن خانه ها از ان p بیشتر باشد ، به احتمال بسیار قوی تراوش انجام خواهد شد و اگر کمتر باشد تراوشی انجام نخواهد شد . در شکل زیر این نمودار را مشاهده میکنید :
119132
هدف این برنامه ای که نوشتیم محاسبه این p هست . به طوری که ما ابتدا یه جدول n*n انتخاب میکنیم و تابع ایجاد اعداد شانسی رو بر روی اون لحاظ مکنیم . تا بهصورت شانسی به تعداد 1000 بار ویا بیشتر(وردی کاربر) این کار را انجام دهد و مقدار p را محاسبه کند .
برای اینکار داد ه ساختاری را معرفی کرده ایم که بتونه این عمل رو پیاده سازیکنه . این داده ساختار مثل همبندی پویاست و عکسشو اینجا قرار میدم :کدهاشو بخونید متوجه میشید نیازی ب توضیح نیست :
119133
کلاس WeightedQuickUnionFind همون ساختار داده هست
کلاس PercolationStats و Percolation عمل و شرط تراوش رو بررسی میکنند
کلاس PercolationVisualizerهم برای گرافیکی بودن برنامه هست :
public class WeightedQuickUnionUF { private int[] id; // id[i] = parent of i
private int[] sz; // sz[i] = number of objects in subtree rooted at i
private int count; // number of components


// Create an empty union find data structure with N isolated sets.
public WeightedQuickUnionUF(int N) {
count = N;
id = new int[N];
sz = new int[N];
for (int i = 0; i < N; i++) {
id[i] = i;
sz[i] = 1;
}
}


// Return the number of disjoint sets.
public int count() {
return count;
}


// Return component identifier for component containing p
public int find(int p) {
while (p != id[p])
p = id[p];
return p;
}


// Are objects p and q in the same set?
public boolean connected(int p, int q) {
return find(p) == find(q);
}



// Replace sets containing p and q with their union.
public void union(int p, int q) {
int i = find(p);
int j = find(q);
if (i == j) return;


// make smaller root point to larger one
if (sz[i] < sz[j]) { id[i] = j; sz[j] += sz[i]; }
else { id[j] = i; sz[i] += sz[j]; }
count--;
}




public static void main(String[] args) {
int N = StdIn.readInt();
WeightedQuickUnionUF uf = new WeightedQuickUnionUF(N);


// read in a sequence of pairs of integers (each in the range 0 to N-1),
// calling find() for each pair: If the members of the pair are not already
// call union() and print the pair.
while (!StdIn.isEmpty()) {
int p = StdIn.readInt();
int q = StdIn.readInt();
if (uf.connected(p, q)) continue;
uf.union(p, q);
StdOut.println(p + " " + q);
}
StdOut.println(uf.count() + " components");
}


}
..


public class Percolation {
private int N;
private int topVS;
private int bottomVS;
private boolean[][] grid;
private WeightedQuickUnionUF union;
private WeightedQuickUnionUF PRBL;




public Percolation(int n) {


N = n;



union = new WeightedQuickUnionUF((n + 1) * (n + 1) + 2);
PRBL = new WeightedQuickUnionUF((n + 1) * (n + 1) + 2);
topVS = (n + 1) * (n + 1);
bottomVS = (n + 1) * (n + 1) + 1;




for (int j = 1; j <= N; j++) {
union.union(topVS, xyTo1D(1, j));
PRBL.union(topVS, xyTo1D(1, j));
}



for (int j = 1; j <= N; j++) {
union.union(bottomVS, xyTo1D(N, j));
}


grid = new boolean[N + 1][N + 1];
}
/**
* Opens the site located at row i and column j.
*/
public void open(int i, int j) {
checkIndices(i, j);
grid[i][j] = true;
int site1D = xyTo1D(i, j);


if (i < N) {
if (grid[i + 1][j]) {
union.union(site1D, xyTo1D(i + 1, j));
PRBL.union(site1D, xyTo1D(i + 1, j));
}
} if (i > 1) {
if (grid[i - 1][j]) {
union.union(site1D, xyTo1D(i - 1, j));
PRBL.union(site1D, xyTo1D(i - 1, j));
}
} if (j < N) {
if (grid[i][j + 1] && j < N) {
union.union(site1D, xyTo1D(i, j + 1));
PRBL.union(site1D, xyTo1D(i, j + 1));
}
} if (j > 1) {
if (grid[i][j - 1] && j > 0) {
union.union(site1D, xyTo1D(i, j - 1));
PRBL.union(site1D, xyTo1D(i, j - 1));
}
}
}
/**
* Returns true if site (i, j) is open,
* otherwise returns false.
*/
public boolean isOpen(int i, int j) {
checkIndices(i, j);
return grid[i][j];
}
/**
* Returns true if site (i, j) is full,
* otherwise returns false.
*/
public boolean isFull(int i, int j) {
checkIndices(i, j);
if (!PRBL.connected(xyTo1D(i, j), topVS)) {
return false;
}
if (grid[i][j] && union.connected(xyTo1D(i, j), topVS)) {
return true;
}
return false;
}
/**
* Returns true if the system percolates,
* otherwise returns false.
*/
public boolean percolates() {
return union.connected(topVS, bottomVS);
}
/**
* Converts the position (row and column) of
* a site to its corresponding object number.
*/
private int xyTo1D(int i, int j) {
return N * i + j;
}
/**
* Checks if the site (i, j) exists in the grid.
* If it does not exist, throws an exception.
*/


private void checkIndices(int i, int j) {
if (i > N || i < 1) {
new IndexOutOfBoundsException("Row index i out of bounds");
} if (j > N || j < 1) {
new IndexOutOfBoundsException("Column index j out of bounds");
}


}
// test client
public static void main(String[] args) {
int N = Integer.parseInt(args[0]);
Percolation percolation = new Percolation(N);

percolation.open(1, 1);
percolation.open(2, 1);
percolation.open(3, 1);
percolation.open(4, 1);
percolation.open(5, 1);
StdOut.println(percolation.percolates());

}
}



..
public class PercolationStats {
private int T;
private double[] result;

public PercolationStats(int N, int T)
{
if (N <= 0 || T <= 0)
throw new IllegalArgumentException("N and T must be greater than 0");


this.T = T;

Percolation percolation;
result = new double[T];

for (int t = 0; t < T; t++)
{
percolation = new Percolation(N);
int openSites = 0;

while (!percolation.percolates())
{
int i = StdRandom.uniform(N) + 1;
int j = StdRandom.uniform(N) + 1;

if (!percolation.isOpen(i, j))
{
percolation.open(i, j);
openSites++;
}
}

result[t] = (double) openSites / (N * N);
}
}

public double mean()
{
return StdStats.mean(result);
}

public double stddev()
{
if (T > 1) return StdStats.stddev(result);
else return Double.NaN;
}

public double confidenceLo()
{
return mean() - 1.96 * Math.sqrt(StdStats.var(result)) / Math.sqrt(T);
}

public double confidenceHi()
{
return mean() + 1.96 * Math.sqrt(StdStats.var(result)) / Math.sqrt(T);
}

public static void main(String[] args)
{
int N = Integer.parseInt(args[0]);
int T = Integer.parseInt(args[1]);

PercolationStats percolationStats = new PercolationStats(N, T);

StdOut.printf("%-23s = %f\n", "mean", percolationStats.mean());
StdOut.printf("%-23s = %f\n", "stddev", percolationStats.stddev());
StdOut.printf("%-23s = %f, %f\n", "95% confidence interval",
percolationStats.confidenceLo(),
percolationStats.confidenceHi());
}

}
..


import java.awt.Font;

public class PercolationVisualizer {


// draw N-by-N percolation system
public static void draw(Percolation perc, int N) {
StdDraw.clear();
StdDraw.setPenColor(StdDraw.BLACK);
StdDraw.setXscale(0, N);
StdDraw.setYscale(0, N);
StdDraw.filledSquare(N/2.0, N/2.0, N/2.0);


// draw N-by-N grid
int opened = 0;
for (int row = 1; row <= N; row++) {
for (int col = 1; col <= N; col++) {
if (perc.isFull(row, col)) {
StdDraw.setPenColor(StdDraw.BOOK_LIGHT_BLUE);
opened++;
}
else if (perc.isOpen(row, col)) {
StdDraw.setPenColor(StdDraw.WHITE);
opened++;
}
else
StdDraw.setPenColor(StdDraw.BLACK);
StdDraw.filledSquare(col - 0.5, N - row + 0.5, 0.45);
}
}


// write status text
StdDraw.setFont(new Font("SansSerif", Font.PLAIN, 12));
StdDraw.setPenColor(StdDraw.BLACK);
StdDraw.text(.25*N, -N*.025, opened + " open sites");
if (perc.percolates()) StdDraw.text(.75*N, -N*.025, "percolates");
else StdDraw.text(.75*N, -N*.025, "does not percolate");


}


public static void main(String[] args) {
In in = new In(args[0]); // input file
int N = in.readInt(); // N-by-N percolation system


// repeatedly read in sites to open and draw resulting system
Percolation perc = new Percolation(N);
draw(perc, N);
while (!in.isEmpty()) {
StdDraw.show(0); // turn on animation mode
int i = in.readInt();
int j = in.readInt();
perc.open(i, j);
draw(perc, N);
StdDraw.show(50); // pause for 100 miliseconds
}
}
}



البته برای اجرای این برنامه به کتابخانه StdLib نیاز خواهید داشت که به همراه فایلهای ورودی براتون میزارم :
http://uplod.ir/7m2sgvb3p4jg/percolation.rar.htm

mohadese20
شنبه 21 تیر 1393, 10:41 صبح
سلام
همین برنامه رو اگه بخوایم تعداد فایل های هر فولدر رو برگردونه و ماکزیمم تعداد فایل های تمامی فولدر ها رو برگردونه چطور باید تغییر بدیم

vahid-p
شنبه 21 تیر 1393, 11:55 صبح
سلام
همین برنامه رو اگه بخوایم تعداد فایل های هر فولدر رو برگردونه و ماکزیمم تعداد فایل های تمامی فولدر ها رو برگردونه چطور باید تغییر بدیم
در همان تاپیک جواب داده شد : http://barnamenevis.org/showthread.php?460002-%D8%A8%D8%B1%D9%86%D8%A7%D9%85%D9%87-%DA%A9%D8%A7%D8%B1-%D8%A8%D8%A7-%D9%81%D9%88%D9%84%D8%AF%D8%B1-%D9%88-%D9%81%D8%A7%DB%8C%D9%84&p=2059782&viewfull=1#post2059782
تا جای ممکن اینجا سوال پرسیده نشه و فقط کد صحیح و کاربردی قرار بگیره.

donyamrg
یک شنبه 05 مرداد 1393, 13:40 عصر
خیلی سادس اولین کدی که نوشتم معذرت :مفهوم ارث بری


package inheritance;
import inheritance.b;
import inheritance.inherittest;
public class inherittestusing {
public static void main(String[] args) {
// TODO Auto-generated method stub
inherittest superob= new inherittest();
b subob=new b();
superob.i=10;
superob.j=20;
superob.showij();
System.out.println();
subob.i = 7;
subob.j = 8;
subob.k = 9;
System.out.println("Contents of subOb :");
subob.showij();
subob.showk();
System.out.println();
System.out.print("sum:");
subob.sum();
}
}









package
inheritance;

public
class inherittest {

inti,j;

void
showij(){

System.
out.println("inherittest.showij"+i+" "+j);

}

}

class
b extends inherittest{

intk;

void showk(){


System.
out.println("b.showk()"+k);

}

void sum (){

System.
out.println("sum:"+(i+j+k));

}

}

dasssnj
پنج شنبه 30 مرداد 1393, 08:57 صبح
سلام دوستان این تاپیک به اعلان ها اضافه شد .
از دوستان تقاضای همکاری دارم .


برای تشکر کافی است دکمه ی تشکر را بفشارید . از نوشتن کامنت زیر پست های مفید خودداری کنید .

dasssnj
شنبه 29 شهریور 1393, 13:02 عصر
اینم یه color chooser ساده.

123696

123697

dasssnj
شنبه 29 شهریور 1393, 13:08 عصر
پیدا کردن عدد رندم بین دو عدد :

public static int rand(int a, int b) {
if (a == b)
return -1;
else if (a > b)
return -1;
else if (b - a == 1)
return -1;
Random r = new Random();
int y = r.nextInt(b);
if (y < a)
y += (a - y) + r.nextInt(b - a);
if (y != a)
return y;
else
return y + 1 + r.nextInt((b - a) - 1);
}

البته اعداد پارامتر نباید مساوی باشند. دومی نباید کوچکتر از اولی باشه و تفاضلشون باید بیشتر از 1 باشه وگر نه 1- برمی گردونه.

dasssnj
شنبه 29 شهریور 1393, 13:10 عصر
پیدا کردن بزرگترین عدد بین هر چندتا عدد که دلتون بخواد !!!!!


public static int max(int... i){
int max;
int c = i[0];
max=c;
for (int k = 1; k < i.length; k++){
if(i[k]>max)
max=i[k];
}
return max;
}


مثال :
int i = max(2,-5,1000,50,60,600);
int j = max(1,8,4,54,87,468,354,156,357,68,354,68,34,69);

dasssnj
شنبه 29 شهریور 1393, 13:13 عصر
تبدیل string به int با الگوریتم خودم.

public static int strToint(String e) throws NumberFormatException {
if (e == null || e.length() < 1 || e.equals("")) //string moshkel dare
throw new NumberFormatException("String : " + e + " is corrupt !");

char[] ch = e.toCharArray();
boolean negative = false; //manfi
int len = ch.length; // toole adad
int[] i = new int[len]; //araye adad
short j, k; // adad halghe ha
int result = 0; //javab
if (ch[0] == '-') { //manfi
if (e.length() == 1)
throw new NumberFormatException("String : " + e + " is corrupt !");

negative = true; // manfi mishe
ch = e.substring(1).toCharArray();
len = ch.length;
} else if (ch[0] == '+') { //mosbat
if (e.length() == 1)
throw new NumberFormatException("String : " + e + " is corrupt !");
ch = e.substring(1).toCharArray();
len = ch.length;
}

for (j = 0; j < len; j++) {
if (ch[j] < '0' || ch[j] > '9') // bayad beine 0 ta 9 bashe
throw new NumberFormatException("String : " + e + " Not a Number !");
i[j] = ch[j] - 48; // az char ke adad bashe 48 ta kam koni mishe int
for (k = 0; k < len - (j + 1); k++)
i[j] *= 10; //sefr ha ra mizaram ba zarb dar 10

result += i[j]; // hala jam mikonam
if (result < 0) //aslan nabayad manfi bashe
{
if (result == -2147483648 && negative) {//No problem (-|0)
// irad az man nist . system manfi bar migardoone . baray hamin in shart lazeme
} else //adad bozorg tar az int
{
throw new NumberFormatException("Number : " + e + " is out of range for int! ");
}
}
}
return negative ? -result : result; // manfi bashe ya mosbat
}

ahmad.mo74
پنج شنبه 11 دی 1393, 01:30 صبح
سلام،

توی این تاپیک کمتر دیدم دوستان از مباحث multi threading و ... مطلب قرار بدن.

یکی از موضوعاتی که به تازگی اهمیت پیدا کرده و به شدت تو افزایش سرعت اجرای تسک ها تاثیر گذاره، تقسیم کردن تسک های بزرگ به چندین تسک کوچیک و اجرای همزمان اون هاست.
پیکیج java.util.concurrent یک API کاملیه که مخصوصا برای مدیریت بهتر concurrency ، بهره گیری کامل از توان سیستم برای انجام تسک ها و افزایش نظم و سرعت در اجرای برنامه های multi thread فراهم شده.
واقعا حیفه که یه نگاهی به این پکیج و کلاس هاش انداخته نشه...

برای مثال محاسبه فاکتوریل یک عدد نسبتا بزرگ میتونه کاملا اهمیت تجزیه تسک ها رو نشون بده هر چند مثال کاربردی نیست اما میتونید با دیدن این مثال برای موارد دیگه هم ایده بگیرید.

فرض کنید میخوایم فاکتوریل عدد 100 رو حساب کنیم.

یعنی :


1 * 2 * 3 * ... * 100


اگر بخوایم محاسبه این فاکتوریل رو به محاسبات کوچیک تر تقسیم کنیم :


1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14 * 15 * 16 * 17 * 18 * 19 * 20 * 21 * 22 * 23 * 24 * 25



26 * 27 * 28 * 29 * 30 * 31 * 32 * 33 * 34 * 35 * 36 * 37 * 38 * 39 * 40 * 41 * 42 * 43 * 44 * 45 * 46 * 47 * 48 * 49 * 50



51 * 52 * 53 * 54 * 55 * 56 * 57 * 58 * 59 * 60 * 61 * 62 * 63 * 64 * 65 * 66 * 67 * 68 * 69 * 70 * 71 * 72 * 73 * 74 * 75



76 * 77 * 78 * 79 * 80 * 81 * 82 * 83 * 84 * 85 * 86 * 87 * 88 * 89 * 90 * 91 * 92 * 93 * 94 * 95 * 96 * 97 * 98 * 99 * 100


حالا با محاسبه همه دنباله ها به صورت موازی داریم :


15511210043330985984000000



1960781468160819415703172080467968000000



815712000579973729423615859451974909952000000



3761767332187389431968739190317715670695936000000


در آخر با ضرب همه نتیجه ها فاکتوریل عدد 100 رو حساب میکنیم :


93326215443944152681699238856266700490715968264381 62146859296389521759999322991560894146397615651828 62536979208272237582511852109168640000000000000000 00000000



FactorialCalculator :


package com.sample.factorial;


import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ForkJoinPool;


/**
* @author avb
*/
public class FactorialCalculator {


private static final int AVAILABLE_PROCESSORS = Runtime.getRuntime().availableProcessors();
private static final int OUTER_CHUNK_SIZE = AVAILABLE_PROCESSORS * AVAILABLE_PROCESSORS * 2;
private static final int INNER_CHUNK_SIZE = AVAILABLE_PROCESSORS;


private boolean parallel;


public FactorialCalculator parallel() {
parallel = true;
return this;
}


public FactorialCalculator nonParallel() {
parallel = false;
return this;
}


public boolean isParallel() {
return parallel;
}


public BigInteger calculate(int n) {
if (n < 0) {
throw new IllegalArgumentException();
}
if (n == 0) {
return BigInteger.ONE;
}
Sequence sequence = new Sequence(1, n);
if (!parallel) {
return sequence.multiplySequence();
}
List<BigInteger> elements = parallelCalculate(splitSequence(sequence.getElemen ts(), OUTER_CHUNK_SIZE));
while (elements.size() > INNER_CHUNK_SIZE) {
elements = parallelCalculate(splitSequence(elements, INNER_CHUNK_SIZE));
}
return new Sequence(elements).multiplySequence();
}


private List<Sequence> splitSequence(List<BigInteger> elements, int chunkSize) {
int index = 0, targetIndex, elementsSize = elements.size();
List<Sequence> subSequences = new ArrayList<>();
while (index < elementsSize) {
targetIndex = Math.min(index + chunkSize, elementsSize);
subSequences.add(new Sequence(elements.subList(index, targetIndex)));
index = targetIndex;
}
return subSequences;
}


private List<BigInteger> parallelCalculate(List<Sequence> sequences) {
CountDownLatch latch = new CountDownLatch(sequences.size());
List<BigInteger> results = Collections.synchronizedList(new ArrayList<>());
ForkJoinPool pool = new ForkJoinPool(AVAILABLE_PROCESSORS);
sequences.parallelStream().forEach(sequence -> pool.submit(() -> {
results.add(sequence.multiplySequence());
latch.countDown();
}));
pool.shutdown();
try {
latch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
return results;
}


public static class Sequence {


private final List<BigInteger> elements;


public Sequence(List<BigInteger> elements) {
this.elements = elements;
}


public Sequence(int from, int to) {
if (to < from) {
throw new IllegalArgumentException();
}
elements = new ArrayList<>();
for (; from <= to; from++) {
elements.add(BigInteger.valueOf(from));
}
}


public List<BigInteger> getElements() {
return elements;
}


public BigInteger multiplySequence() {
BigInteger result = BigInteger.ONE;
for (BigInteger element : elements) {
result = result.multiply(element);
}
return result;
}


}


}


Test :


package com.sample.factorial;


/**
* @author avb
*/
public class Test {


public static void main(String[] args) throws InterruptedException {
final FactorialCalculator factorialCalculator = new FactorialCalculator();
for (int i = 0; i < 10; i++) {
System.out.println("test " + (i + 1) + " : ");
long l = System.currentTimeMillis();
factorialCalculator.parallel().calculate(1000000);
System.out.println("Execution time : " + (System.currentTimeMillis() - l) + " ms");
System.out.println("----------------------------");
}
}


}


برای مقایسه محاسبه فاکتوریل عدد 1000000 به صورت معمولی حدودا 5-3 دقیقه طول میکشه اما به صورت parallel حدودا 7 ثانیه روی یه پردازنده 8 هسته طول میکشه !!! به شدت که میگم برای اینه :))

دانلود src (https://www.dropbox.com/s/o3n7m5etg35jyzh/factorial_parallel_src.zip?dl=0)

Raminab
چهارشنبه 24 دی 1393, 22:30 عصر
یه notepad ساده با عملیات open,save,copy,cut,past :لبخندساده:

http://s5.picofile.com/file/8163858584/MYNOtePad.rar.html (http://s5.picofile.com/file/8163858584/MYNOtePad.rar.html)

kingtak
چهارشنبه 01 بهمن 1393, 21:23 عصر
این هم حل مساله ۸ وزیر با الگوریتم ژنتیکه که برای پروژه هوش مصنوعی در دانشگاه نوشته بودم.برنامه درست کار میکنه.ولی اگه کسی خواست مینونه بهترش بکنه.
https://github.com/kingtak66/N-Queen

Raminab
دوشنبه 20 بهمن 1393, 16:31 عصر
یک فرم که توش فونت و سایزشو انتخاب میکنیم ( ورودی سازنده ی کلاس یک JtextArea است و خروجی بعد کلیلک روی ok تغییر فونت JtextArea است )

import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GraphicsEnvironment;


import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.border.EmptyBorder;
import javax.swing.JComboBox;


import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


import javax.swing.JLabel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.SwingConstants;




public class FontChooser extends JDialog
{
private JComboBox comboBox;
private final JPanel contentPanel = new JPanel();
private JLabel lblNewLabel;
private JPanel buttonPane;
public FontChooser(JTextArea a)
{
JComboBox comboBox_1 = new JComboBox();

int[] s = {8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72};
for(int i =0;i<s.length;i++)
{
comboBox_1.addItem(s[i]);
}
JLabel lblPreview = new JLabel("Preview");
lblPreview.setHorizontalAlignment(SwingConstants.C ENTER);
comboBox_1.setSelectedItem(a.getFont().getSize());
setBounds(100, 100, 485, 287);
contentPanel.setLayout(new FlowLayout());
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
{

buttonPane = new JPanel();
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
{
JButton okButton = new JButton("OK");
okButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
a.setFont(new Font(comboBox.getSelectedItem().toString(),Font.IT ALIC,Integer.parseInt(comboBox_1.getSelectedItem() .toString())));
dispose();
}
});

JButton btnNewButton = new JButton("Preview");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
////////////////////////
lblPreview.setFont(new Font(comboBox.getSelectedItem().toString(),Font.PL AIN,Integer.parseInt(comboBox_1.getSelectedItem(). toString())));


}
});
buttonPane.add(btnNewButton);
okButton.setActionCommand("OK");
buttonPane.add(okButton);
getRootPane().setDefaultButton(okButton);
}
{
JButton cancelButton = new JButton("Cancel");
cancelButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
dispose();
}
});
cancelButton.setActionCommand("Cancel");
buttonPane.add(cancelButton);
}
}
{
lblNewLabel = new JLabel("Font : ");
}


JLabel lblSize = new JLabel("Size :");


{
GroupLayout groupLayout = new GroupLayout(getContentPane());
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.TRAILING )
.addGroup(groupLayout.createSequentialGroup()
.addGap(23)
.addGroup(groupLayout.createParallelGroup(Alignmen t.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(contentPanel, GroupLayout.PREFERRED_SIZE, 175, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED, 161, Short.MAX_VALUE)
.addComponent(comboBox_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addGap(82))
.addGroup(groupLayout.createSequentialGroup()
.addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 237, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(lblSize)
.addContainerGap(177, Short.MAX_VALUE))))
.addGroup(groupLayout.createSequentialGroup()
.addContainerGap(29, Short.MAX_VALUE)
.addComponent(buttonPane, GroupLayout.PREFERRED_SIZE, 413, GroupLayout.PREFERRED_SIZE)
.addGap(27))
.addGroup(groupLayout.createSequentialGroup()
.addContainerGap(156, Short.MAX_VALUE)
.addComponent(lblPreview, GroupLayout.PREFERRED_SIZE, 173, GroupLayout.PREFERRED_SIZE)
.addGap(140))
);
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGroup(groupLayout.createParallelGroup(Alignmen t.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addContainerGap()
.addGroup(groupLayout.createParallelGroup(Alignmen t.BASELINE)
.addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)
.addComponent(lblSize))
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(contentPanel, GroupLayout.PREFERRED_SIZE, 61, GroupLayout.PREFERRED_SIZE))
.addGroup(groupLayout.createSequentialGroup()
.addGap(54)
.addComponent(comboBox_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(lblPreview, GroupLayout.PREFERRED_SIZE, 60, GroupLayout.PREFERRED_SIZE)
.addGap(35)
.addComponent(buttonPane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addGap(23))
);
comboBox = new JComboBox();
contentPanel.add(comboBox);
getContentPane().setLayout(groupLayout);
String[] fontList = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getAvailableFontFamilyNames();
for(int i = 0 ;i<fontList.length;i++)
{
comboBox.addItem(fontList[i]);
}
comboBox.setSelectedItem(a.getFont().getName());

}
}
}

morteza1207
سه شنبه 11 فروردین 1394, 17:25 عصر
سلام به همه دوستان اینم یک ماشین حساب که خودم نوشتم میزارم شاید به دردتون بخوره. ضمیمه کردم

morteza1207
سه شنبه 11 فروردین 1394, 17:52 عصر
با سلام.اینم یکی دیگه از پروژه هام که به دلایلی کاملشو نذاشتم .یه پینت هست paint

sepita
یک شنبه 08 شهریور 1394, 14:20 عصر
کاش بشه اسم برنامه های نوشته شده یه جاذخیره بشه که اگه خواستیم برنامه بذاریم مطمئن شیم تکراری نیست،ممنون ،خسته نباشید

kfaghih
جمعه 10 مهر 1394, 15:11 عصر
من کاربر مبتدی جاوا هستم و برنامه ای برای محاسبه وزن نرمال نوشتم135639

foory2015
جمعه 16 بهمن 1394, 15:06 عصر
یه برنامه برای رسم این شکل:
*
***
*****
*****
***
*

package javaclass;

public class UpDownTriangle {

static int n = 6;
static int FILL = 1;
static int FIRST = 0;

public static void main(String args[]) {

if (n % 2 == 0) {
FIRST = n / 2;
} else {
FIRST = (int) (n / 2) + 1;
}
int SPASE = FIRST - 1;
int i = 0;
for (i = 0; i < FIRST; i++) {
fillRow(new char[n], SPASE, FILL);
if (n % 2 == 0 && i == FIRST - 1) {
fillRow(new char[n], SPASE, FILL);
} else if (i < FIRST - 1) {
SPASE--;
FILL += 2;
}
}

for (i = FIRST; i < n; i++) {
SPASE++;
FILL -= 2;
fillRow(new char[n], SPASE, FILL);
}
}

public static void fillRow(char[] row, int SPASE, int FILL) {
for (int i = SPASE; i < FILL + SPASE; i++) {
row[i] = '*';
}
System.out.println(row);
}
}

سلام و ممنون از برنامه هاي خوبتون . من هم تازه كار هستم و سعي كردم برنامه شما رو بازنويسي كنيم كه باعث رونق بيشتر اين تاپيك بشه . تشكر

public class Star1 {

public static void main(String[] args) {

int[] number = { 1, 3, 5, 5, 3, 1 } ;

for ( int x : number ){

for ( int i=0 ; i<((5-x)/2) ; i++){
System.out.print(" ");
}

for ( int i=0 ; i<x ; i++){
System.out.print("*");
}

System.out.println();
}

}

}

foory2015
جمعه 16 بهمن 1394, 15:17 عصر
سلام . از دوستاني كه برنامه هاشون رو گذاشتن تشكر ميكنم و اميدوارم كه باز هم مشاركت داشته باشن .

foory2015
جمعه 16 بهمن 1394, 15:20 عصر
اين تاپيك براي برنامه نويسهاي مبتدي خيلي مفيده . لطفا ادامه بديد .

glassheart
یک شنبه 02 اسفند 1394, 12:21 عصر
میشه توی این تاپیک سوالاتمون رو هم بپرسیم؟

pegah73
چهارشنبه 30 تیر 1395, 12:57 عصر
سلام خسته نباشید میشه توضیح بدین چرا از import java.util.* استفاده کردین؟
ممنون از برنامه کاربردیتون

vahid-p
چهارشنبه 30 تیر 1395, 15:07 عصر
سلام خسته نباشید میشه توضیح بدین چرا از import java.util.* استفاده کردین؟
اینجا محل سوال پرسیدن نیست. فقط سورس آماده.
این سوال را در تاپیک مجموعه سوال های مبتدیان (http://barnamenevis.org/showthread.php?459679-%D9%85%D8%AC%D9%85%D9%88%D8%B9%D9%87-%D8%B3%D9%88%D8%A7%D9%84-%D9%87%D8%A7%DB%8C-%D9%85%D8%A8%D8%AA%D8%AF%DB%8C%D8%A7%D9%86) مطرح کنید.

vahid-p
پنج شنبه 07 مرداد 1395, 16:38 عصر
برنامه PhotoMarker

نسخه فعلی: v0.1 (تیر 95)
- با توجه به نسخه نوشته شده، هنوز به نسخه 1 هم نرسیده، پس بسیاری از توضیحات زیر عملی نشده و مشکلاتی موجود است، اما برای یادگیری بد نیست! نمیخواستم الان این رو بذارم چون مشکلات زیاد داره، ولی گفتم ممکنه فراموش کنم و شاید تا همینجاش هم برای یکی مفید باشه.

این برنامه به زبان جاوا و با استفاده از کامپوننت های JavaFX 8 نوشته شده و از اونجایی که مثالها برای JavaFX کم بوده، فکر میکنم مفید باشه.

لینک: گیت لب - PhotoMarker (https://gitlab.com/VahidPY/PhotoMarker)

توضیحات:
هدف این برنامه ساده: انجام عملیات مارک زنی بر روی تصاویر، کار با چندین لایه عکس و متن و... به صورت آسان

کاربرد این برنامه بیشتر برای وبسایت ها یا عکاس هاییست که میخواهند بر روی عکس های خود لوگو، توضیحات و... رو به همراه تغییر اندازه عکس آن هم به صورت سریع و راحت انجام بدن.
از برنامه های معروفی که برای اینکار وجود داره uMark هست که دقیقا اون چیزی نبود که من میخواستم.
مثلا در uMark v3 که من ازش استفاده میکنم:
امکان ابتدا تغییر سایز و بعد مارک زنی رو نداره، و در نتیجه لوگوی سایت ممکنه برای یک عکس بزرگتر و برای یک عکس دیگه کوچکتر باشه.
یا مثلا ترتیب عکس ها رو نمیشه عوض کرد تا در خروجی که به صورت اتوماتیک شماره میزنه، به اون ترتیبی که میخوای شماره بزنه و...


* قابل ذکر است قرار نیست این برنامه حرفه ای باشه و چنین هدفی هم نداشتم، همین که بتونه کار من رو راه بندازه و نمونه آموزشی برای بقیه دوستان باشه کافیه.

از اونجایی که ممکنه به مرور زمان کدهای این برنامه تغییر کنه، کدهاشو اینجا نمیذارم، اما میتونید از gitlab آخرین کدها رو ببینید و در صورتی که علاقه مند بودید میتونید برنامه رو بهبود بدید.

[younes]
پنج شنبه 07 مرداد 1395, 20:00 عصر
bitMapFontCreator این یک ابزار رایگان و متن باز برای تبدیل و نمایش فونت های فارسی و برای استفاده در موتور بازی سازی JmonkeyEngine است.

مجوز نشر :
unlicense (http://unlicense.org)
توضیحات :
با توجه به اینکه پلاگین فونت ساز موجود در sdk موتور بازی سازی jmonkey Engine از فونت پارسی پشتیبانی نمی کرد پس لازم بود یکی بنویسم.
و البته نواقصی وجود داره که در آینده اصلاح خواهد شد (مثلا:نویسه های اینگلیسی قابل استفاده نیست و به جاش کاراکتر # چاپ خواهد شد)

لینک گیت هاب برای بهود و دریافت برنامه. (https://github.com/younes-noori/bitMapFontCreator)
نحوه استفاده از برنامه. (http://younes-noori.blog.ir/page/bitMapFontCreator)

amindelavar
جمعه 15 مرداد 1395, 22:20 عصر
من یک برنامه جستجو گر در کل کامپیوتر نوشتم. امیدوارم به درد بخوره...
راستش چون کد هاش زیادی زیاد بود ، همین طوری نگذاشتم.
این عکسش:

141881

اینم لینک دانلود کل فایل با سورس :
http://s2.picofile.com/file/8262601384/explorer_engine.rar.html

anaide
پنج شنبه 29 تیر 1396, 02:16 صبح
سلام
تو این کانال سورس کدهای رایگان گذاشته شده
بنظرم عالیه
Http://t.me/an_aide

sooren_66
سه شنبه 18 مهر 1396, 19:07 عصر
پروژه ی بازی به زبان جاوا146675

sooren_66
شنبه 06 آبان 1396, 01:35 صبح
باسلام
پروژه ی حمل و نقل به زبان جاوا

sooren_66
دوشنبه 08 آبان 1396, 03:08 صبح
باسلام
در این پروژه به حل مسئله 8 پازل با استفاده از الگوریتم A* با زبان برنامه نویسی Java در محیط Netbeans و زبان C#‎‎‎ در محیط Wpf پرداخته شده . مبحث جست و جوی آگاهانه و نا آگاهانه درهوش مصنوعی برای حل مسائل مطرح است. در جست و جوی ناآگاهانه هیچ گونه اطلاعاتی درباره حالت های مسئله نداریم و به همین دلیل ناآگاهانه نامیده شده اند. در جست و جوی آگاهانه یا هیورستیک از دانش خاص مسئله برا حل آن استفاده می شود: جست وجوی اول بهترین یا حریصانه: در آن نود ها برای گسترش براساس یک تابع ارزیابی مثل(f(n انتخاب می شوند و در هر مرحله نودی که کمترین مقدار fرا دارد گسترش می یابد.
معروف ترین فرم جست وجوی اول بهترین ،الگوریتم A* است که نودها را با ترکیب تابع(g(nو(h(nارزیابی می کند یعنی (g(n) + h(n) = f(nکه (g(n،هزینه مسیر از نود شروعتانود n و (h(n، هزینه تخمینی ارزان ترین مسیر ازنود n تا هدف میباشد.و نود با کمترین مقدارf انتخاب شده و گسترش می یابد.با کاربرد این الگوریتم مسئله 8 پازل حل شده است.

146927

146926

S.M.Mousavi
جمعه 29 دی 1396, 23:41 عصر
پروژه ی بازی به زبان جاوا146675


فایل zip پسوورد داره

grn.developer
سه شنبه 17 بهمن 1396, 10:16 صبح
با سلام سورس پروژه خواندن باسکول با استفاده از java applet
147585

somayeh7813
دوشنبه 22 اردیبهشت 1399, 15:14 عصر
سلام برنامه ای به زبان جاوا که به کمک متد getinfo اطلاعات دانشجویان مثل id و name و avg را گرفته سبب با یکی از اطلاعات لیست ها در اطلاعات جستجو انجام دهد

Farzad_Ahmand_1383
شنبه 28 تیر 1399, 01:56 صبح
سلام
پیادسازی "بازی زندگی"کانوی با جاوا :
import java.util.*;

public class GameOfLife​ { static Scanner input=new Scanner(System.in);
public static void main(String[] args) {
int n=input.nextInt();
boolean[][]world=new boolean[n][n];
for (int i=0;i < world.length;i++) {
for (int j=0;j < world[i].length;j++) {
world[i][j] = new Random().nextInt(100) <= 80 ?false: true;
}
}
while (true) {
evaluation(world);
draw(world);
try {
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void evaluation(boolean[][]world) {
boolean[][]temp=new boolean[world.length][world[0].length];
for (int i=0;i < world.length;i++) {
for (int j=0;j < world[i].length;j++) {
int lifes=0;
for (int x=i - 1;x < i + 2;x++) {
for (int y=j - 1;y < j + 2;y++) {
if (x < world.length && x >= 0 && y < world[x].length && y >= 0 && world[x][y]) {
lifes++;
}
}
}
if (world[i][j]) {
lifes--;
}
if (world[i][j] && (lifes < 2 || lifes > 3)) {
temp[i][j] = false;
} else if (!world[i][j] && lifes == 3) {
temp[i][j] = true;
} else if (world[i][j] && (lifes == 2 || lifes == 3)) {
temp[i][j] = true;
}
}
}
for (int i=0;i < world.length;i++) {
for (int j=0;j < world[i].length;j++) {
world[i][j] = temp[i][j];
}
}
}
public static void draw(boolean[][]world) {
for (int i=0;i < world.length;i++) {
for (int j=0;j < world[i].length;j++) {
System.out.print(world[i][j] ?"*": " ");
}
System.out.println();
}
}
}

Farzad_Ahmand_1383
شنبه 28 تیر 1399, 02:16 صبح
سلام
پیاده سازی برنامه "هشت وزیر" با جاوا :
import java.util.*;


public class KnightQueens {
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
System.out.print("Enter N :");
int n=input.nextInt();
boolean[][]page=new boolean[n][n];
boolean beadCondition;
int numberQueens=0,numberCases=0;
for (int i=0;i < page.length;i++) {
beadCondition = false;
for (int j=0;j < page[i].length;j++) {
page[i][j] = true;
if (!checkPage(page)) {
page[i][j] = false;
} else {
beadCondition = true;
numberQueens++;
if (numberQueens == n) {
showPages(page);
System.out.println("-------------------------------");
beadCondition = false;
numberCases++;
page[i][j] = false;
numberQueens--;
} else {
break;
}
}
if (!beadCondition && j == page.length - 1) {
for (int y=0;y < page.length;y++) {
if (page[i - 1][y]) {
page[i - 1][y] = false;
i--;
j = y;
beadCondition = false;
numberQueens--;
if (y + 1 >= page.length && i != 0) {
y = -1;
} else {
break;
}
}
}
}
}
}
System.out.println("Number Of Cases : "+numberCases);
}
public static boolean checkPage(boolean[][]page) {
for (int i=0;i < page.length;i++) {
for (int j=0;j < page[i].length;j++) {
if (page[i][j]) {
for (int m=0;m < page.length;m++) {
if ((page[i][m] && m != j) || (page[m][j] && i != m) || (i + m < page.length && j + m < page[i + m].length && page[i + m][j + m] && m != 0) || (i - m >= 0 && j - m >= 0 && m != 0 && page[i - m][j - m]) || (i + m < page.length && j - m >= 0 && m != 0 && page[i + m][j - m]) || (j + m < page.length && i - m >= 0 && m != 0 && page[i - m][j + m])) {
return false;
}
}
}
}
}
return true;
}
public static void showPages(boolean[][]page) {
for (int i=0;i < page.length;i++) {
for (int j=0;j < page[i].length;j++) {
System.out.print(page[i][j] ?" Q ": " . ");
}
System.out.println();
}
}
}

Farzad_Ahmand_1383
شنبه 28 تیر 1399, 02:22 صبح
سلام
پیاده سازی برنامه "حل کننده سودوکو" با جاوا :
import java.util.*;
public class SudokuSolver {
public static void main(String[] args) {
int[][] array={
{ 8, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 3, 6, 0, 0, 0, 0, 0 },
{ 0, 7, 0, 0, 9, 0, 2, 0, 0 },
{ 0, 5, 0, 0, 0, 7, 0, 0, 0 },
{ 0, 0, 0, 0, 4, 5, 7, 0, 0 },
{ 0, 0, 0, 1, 0, 0, 0, 3, 0 },
{ 0, 0, 1, 0, 0, 0, 0, 6, 8 },
{ 0, 0, 8, 5, 0, 0, 0, 1, 0 },
{ 0, 9, 0, 0, 0, 0, 4, 0, 0 }};
solve(array,0,0);
showSudoku(array);
}
public static boolean solve(int[][]array, int i, int j) {
for (i = 0;i < array.length;i++) {
for (j = 0;j < array[i].length;j++) {
if (array[i][j] == 0) {
for (int z=1;z <= 9;z++) {
array[i][j] = z;
if (paste(array, i, j, z) && solve(array, i, j + 1)) {
return true;
} else {
array[i][j] = 0;
}
}
return false;
}
}
}
return true;
}
public static boolean paste(int[][]array, int i, int j, int val) {
for (int x = 0; x < 9; x++) {
if (x != j) {
if (array[i][x] == val) {
return false;
}
}
}
for (int x = 0; x < 9; x++) {
if (x != i) {
if (array[x][j] == val) {
return false;
}
}
}
for (int x = (i / 3) * 3; x < (i / 3) * 3 + 3; x++) {
for (int y = (j / 3) * 3; y < (j / 3) * 3 + 3; y++) {
if ((x != i) || (y != j)) {
if (array[x][y] == val) {
return false;
}
}
}
}
return true;
}
public static void showSudoku(int[][]array) {
for (int i=0;i < array.length;i++) {
for (int j=0;j < array[i].length;j++) {
System.out.print(array[i][j] + " ");
}
System.out.println();
}
}
}