Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-05-2008, 08:44 PM
Member
 
Join Date: Oct 2008
Posts: 4
Rep Power: 0
CheDesign is on a distinguished road
Default Peaople please HELP ME!
Hi all!

Can you please help me to do homework 4 Java programs this is very important. I was in hospital and therefore missed many lessons, that's why i need your help because i can't do them alone.

1.
Make a class Box with int variables height, width, length. Box class must have a constructor Box (), which allows the height, width and length = 0, and another constructor Box (int h, int w, int l), which makes height = h, w = width and length = l. Add get and set methods for height, width and length. Additionally, create a method getSize () to return the volume (height * width * length).
Create a program that creates an object (box1) of the class Box (without calling the parameters so that the first constructor used) and an object (box2) of the class Box with height = 3 width = 4, length = 6 ( so that the second constructor used).
Put height = 2 width = 3, length = 11 on box1 using set-methods.
Print what box, which is highest and how much it is larger than the second box. (The program will decide which box, whichever is greater (or whether they are equal) using the method calls on box1 and box2.)
Put height = 3 on box1. Print what box, which is highest and how much it is larger than the second box.
Sets length = 8 on box1. Print what box, which is highest and how much it is larger than the second box.

2.
Make a class DiceGame with a private variable (diceArray) of type array of int. DiceGame must have a constructor, which instantiated diceArray with 5 seats, each seat will include a random number (int) between 1 and 6 Make a method rollDie (int index), which puts the figure at the space index in diceArray to a new random number between 1 and 6 Make a method getSum () which returns the sum of the 5 int in the array.
Make a method toString () which returns all figures in diceArray with space between as a String.
Create a program that creates an object (game) of the class DiceGame. Print the game through toString method, using getSum () to print the sum.
Call rollDie method with 1, 2 and 3 Print the game again and use getSum () to print the sum.

3.
Make a JApplet with a JTextField, a JTextArea and a JButton. Add code so that the text of JTextField added to JTextArea (append) and JTextField'et erased when you click on the button, so you are ready for the next text.
Create an HTML page that contains JApplet'en. (Remember to compile class, otherwise it can not run in the browser.)

4.
Make a JFrame with a JPanel and a JLabel. Add code so that each time you click the mouse on JPanel signed x and y coordinates of the mouse clicked in JLabel. (Note to Event Mouse has some methods you can use.)
Be sure to set up an object of your JFrame when the program is run. (If you have a main class, with an empty main method, nothing happens when I run the program.)

p.s. sorry for my bad english
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 10-05-2008, 10:09 PM
ojn ojn is offline
Member
 
Join Date: Aug 2008
Location: Stockholm, Sweden
Posts: 54
Rep Power: 0
ojn is on a distinguished road
Send a message via MSN to ojn
Default
No one is going go do your homework for you. That's cheating and won't help you at all. Just tell your teacher about your hospital stay and you'll hopefully get an extension.

When you're back on track with your studies and have read up on the material you've missed, feel free to come back here and if you have more specific questions about your code.

What you have described is pretty basic Java, so it won't take you long to catch up.

Good luck.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 10-05-2008, 11:05 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 3,195
Rep Power: 5
Fubarable is on a distinguished road
Default
I need to second what ojn is saying. If your excuse is valid, your teacher should give you an extension and then you can do your own work. You also may consider dropping the class. What won't happen though is for anyone here to help you cheat. Best of luck.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 10-06-2008, 07:39 AM
Senior Member
 
Join Date: Jun 2008
Posts: 902
Rep Power: 2
masijade is on a distinguished road
Default
Originally Posted by CheDesign View Post
Hi all!

Can you please help me to do homework 4 Java programs this is very important.
Oh yeah, so important you didn't bother to do them.

Quote:
I was in hospital and therefore missed many lessons, that's why i need your help because i can't do them alone.
I don't buy this, you were out partying, weren't you? If you were really in the hospital, all you need do is tell your instructor and you will get extra time to do them, as well as help (even if only in the form of information as to where you can find a good tutor) to get the instruction you missed.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 10-06-2008, 08:10 AM
Senior Member
 
Join Date: Aug 2008
Posts: 302
Rep Power: 1
Supamagier is on a distinguished road
Default
google it with problems, or ask here, we'll HELP you, NOT DO your homework.
__________________
check out
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
, 100% made by me.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 10-06-2008, 08:32 AM
Member
 
Join Date: Oct 2008
Posts: 4
Rep Power: 0
CheDesign is on a distinguished road
Default
Thank you all for help!
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 10-06-2008, 09:52 AM
serjant's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Ukraine,Zaporozhye
Posts: 451
Rep Power: 2
serjant is on a distinguished road
Send a message via ICQ to serjant Send a message via Skype™ to serjant
Default
I made for my friend some time ago this stuff,the same homework as you have so here is your class dice,but the other stuff do by yourselves buddy


Code:
import java.util.Scanner; //scanner class
import java.util.Random; //Random class

/**
	This Program will input numbers between 1 and 6 from the user, and compare them to the output of 
	the dice being rolled within 3 rolls. 
*/

public class dice
{
	
	
	public void dieImage(int dice1)
	{
		switch (dice1)
		{
		case 1:
			System.out.print("     \n");
			System.out.print("  *  \n");
			System.out.println("     ");
			break;
		case 2:
			System.out.println("*    ");
			System.out.println("     ");
			System.out.println("    *");
			break;
		case 3:
			this.printThree();
			break;
		case 4:
			System.out.print("*   *\n");
			System.out.print("     \n");
			System.out.println("*   *");
			break;
		case 5:
			System.out.print("*   *\n");
			System.out.print("  *   \n");
			System.out.println("*   *");
			break;
		case 6:
			this.printSix();
			break;			
		}
					
	
	}
	public void printSix(){
		int i=0,j;
		for(;i<3;i++){
			for(j=0;j<2;j++){
				System.out.print("*   ");
			}
			System.out.println("");
		}
	}
	
	
	
	public void printThree(){
		for(int i=0;i<3;i++){
			for(int j=0;j<1;j++){
				for(int k=0;k<i;k++){
					System.out.print("  ");
				}
				System.out.print("*");
			}
			System.out.println();	
		}
	}
	
	
	
	public void play(int userGuess){
		int times=1,sum=0;
		int dice1,dice2;
		do{	
			//create a Random class object. 
			Random randomNumbers = new Random();
	
			//Get two random numbers.
			dice1 = randomNumbers.nextInt(6)+1;
			dice2 = randomNumbers.nextInt(6)+1;
			System.out.println(dice1);
			System.out.println(dice2);
			//output the number of each die with asteriks by calling the method
			System.out.println("Die 1      ");
			
			this.dieImage(dice1);
			System.out.println("Die 2       ");
			this.dieImage(dice2);
			
			System.out.println("-----------------");
	  		//Sum the two die numbers
			sum = (dice1 + dice2);
		
			
			times++;
		} while (userGuess != sum&&times<4);
		if (userGuess == sum)
		{
		System.out.println("YOU WIN!!!");
		}
		else 
		{
		System.out.println("SORRY YOU LOSE!");
		}
	}
	
	public static void main(String[] args)
	{
		
		boolean exit=false;
		int userGuess;
		String answer;
		dice d=new dice();
		//Create a scanner object for keyboard input.
		Scanner keyboard = new Scanner(System.in);
		
		//get number from user
		System.out.println("Please enter a number between " +
								"2 and 12.");
	
		userGuess = keyboard.nextInt();
		d.play(userGuess);
		
			
		
		
		
		do{
			System.out.println("Wanna continue laying?Press Y/N");
			answer=keyboard.next();
			if(answer.matches("Y".toLowerCase())||answer.matches("Y")){
				//get number from user
				System.out.println("Please enter a number between " +
										"2 and 12.");
			
				userGuess = keyboard.nextInt();
				d.play(userGuess);
			}
			else{
				exit=true;
			}
		}while(!exit);
		System.exit(0);
	}
		
	
}
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 10-06-2008, 08:31 PM
Member
 
Join Date: Oct 2008
Posts: 4
Rep Power: 0
CheDesign is on a distinguished road
Default
Serjant, thank you very much!

I have done with first 2..But this one with Applet i can't figure it out...

"Make a JApplet with a JTextField, a JTextArea and a JButton. Add code so that the text of JTextField added to JTextArea (append) and JTextField'et erased when you click on the button, so you are ready for the next text."
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 10-06-2008, 08:56 PM
ojn ojn is offline
Member
 
Join Date: Aug 2008
Location: Stockholm, Sweden
Posts: 54
Rep Power: 0
ojn is on a distinguished road
Send a message via MSN to ojn
Default
Applets: java.sun.com/applets

Also read up on Swing and in particular the JTextField, JTextArea and JButton classes and you'll have no problem.
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 10-06-2008, 11:08 PM
serjant's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Ukraine,Zaporozhye
Posts: 451
Rep Power: 2
serjant is on a distinguished road
Send a message via ICQ to serjant Send a message via Skype™ to serjant
Default
here is you program 3,but it is JFrame,you should read about how to make Applets and change some code

Code:
import javax.swing.*;
import java.awt.event.*;
public class Frame extends JFrame{

	private JButton addText=new JButton("Add text");
	private JTextArea textArea=new JTextArea();
	private JTextField textField=new JTextField("");
	
	public Frame(String name){
		super(name);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.pack();
		this.getContentPane().add(this.addComponents());
		this.setSize(200,300);
		this.setVisible(true);
	}
	
	private JPanel addComponents(){
		JPanel p=new JPanel();
		p.setLayout(new BoxLayout(p,BoxLayout.Y_AXIS));
		p.add(textField);
		p.add(addText);
		p.add(textArea);
		addText.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				textArea.append(textField.getText()+"\n");
				textField.setText("");
			}
		});
		return p;
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Frame("My prog");
	}

}
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 10-07-2008, 08:15 AM
Member
 
Join Date: Oct 2008
Posts: 4
Rep Power: 0
CheDesign is on a distinguished road
Default
Serjant, спасибо тебе! Гадам буду не забуду!
Теперь буду смотреть что в этом коде надо поменять.
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 10-07-2008, 08:17 AM
Senior Member
 
Join Date: Sep 2008
Posts: 607
Rep Power: 1
Darryl.Burke is on a distinguished road
Default
serjant

You may think you're being helpful, but it appears to me that all you're doing is making it possible for someone to earn a grade they don't deserve.

I hope you one day have to work alongside someone whose education was hampered by being "helped" in this way.

db

edit And that doesn't look so far fetched, seeing the OP's last response.

Last edited by Darryl.Burke; 10-07-2008 at 08:21 AM. Reason: after reading the post just before this.
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 10-07-2008, 01:29 PM
serjant's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Ukraine,Zaporozhye
Posts: 451
Rep Power: 2
serjant is on a distinguished road
Send a message via ICQ to serjant Send a message via Skype™ to serjant
Default
Originally Posted by Darryl.Burke View Post
serjant

You may think you're being helpful, but it appears to me that all you're doing is making it possible for someone to earn a grade they don't deserve.

I hope you one day have to work alongside someone whose education was hampered by being "helped" in this way.

db

edit And that doesn't look so far fetched, seeing the OP's last response.
I didn't give him the whole answer,i gave him an example,also he can google,he should think alone now,how to make it fetched.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +2. The time now is 03:20 AM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org