Results 1 to 13 of 13
  1. #1
    CheDesign is offline Member
    Join Date
    Oct 2008
    Posts
    4
    Rep Power
    0

    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 :)

  2. #2
    ojn
    ojn is offline Senior Member
    Join Date
    Aug 2008
    Location
    Stockholm, Sweden
    Posts
    119
    Rep Power
    0

    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.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    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.

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote 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.

    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.

  5. #5
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    google it with problems, or ask here, we'll HELP you, NOT DO your homework.
    I die a little on the inside...
    Every time I get shot.

  6. #6
    CheDesign is offline Member
    Join Date
    Oct 2008
    Posts
    4
    Rep Power
    0

    Default

    Thank you all for help!

  7. #7
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    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


    Java 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);
    	}
    		
    	
    }

  8. #8
    CheDesign is offline Member
    Join Date
    Oct 2008
    Posts
    4
    Rep Power
    0

    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."

  9. #9
    ojn
    ojn is offline Senior Member
    Join Date
    Aug 2008
    Location
    Stockholm, Sweden
    Posts
    119
    Rep Power
    0

    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.

  10. #10
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    here is you program 3,but it is JFrame,you should read about how to make Applets and change some code

    Java 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");
    	}
    
    }

  11. #11
    CheDesign is offline Member
    Join Date
    Oct 2008
    Posts
    4
    Rep Power
    0

    Default

    Serjant, спасибо тебе! Гадам буду не забуду!
    Теперь буду смотреть что в этом коде надо поменять.

  12. #12
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,229
    Rep Power
    19

    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 DarrylBurke; 10-07-2008 at 08:21 AM. Reason: after reading the post just before this.

  13. #13
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    Quote 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •