What's new

Java Programming - Can anyone help me?

Scheiss, man. I cannot thank you enough for your help. Again, i owe this entire semester to you. Just know that.
Even though you didnt have the correct answer, you still pointed out mine was wrong. I dont know if what i changed since then is right, but i just want to thank you for all your support. You've been very helpful

Code:
// FixDebugFive4.java
// Jason Sodano
// October 30th, 2010
import javax.swing.*;
public class FixDebugFive4
{
   public static void main (String args[]) 
   {
    	int one, two, three, four;
    	String str, output;
	 	// Inputs the numbers in order to determine the highest number.
    	str = JOptionPane.showInputDialog(null,"Enter an integer");
    	one = Integer.parseInt(str);
    	str = JOptionPane.showInputDialog(null,"Enter an integer");
    	two = Integer.parseInt(str);
    	str = JOptionPane.showInputDialog(null,"Enter an integer");
    	three = Integer.parseInt(str);
    	str = JOptionPane.showInputDialog(null,"Enter an integer");
    	four = Integer.parseInt(str);
	 
	 	// Determines which is the highest number.
    	if(one > two && one > three && one > four)
       output = "Highest is " + one;
    	else 
		if(two > one && two > three && two > four)
       output = "Highest is " + two;
    	else
		if(three > one && three > two && three > four)
       output = "Highest is " + three;
    	else
       output = "Highest is  " + four;
				
	 // Outputs highest of four numbers			
    JOptionPane.showMessageDialog(null, output);
    System.exit(0);
  }
}
I wont hand this in till i hear from you. I have till midnight to hand it in.

Take a look and tell me what you think.
 
dude, its the same shit to me. like we've said before. if i didnt spend all that time testing MK then i wouldnt have the "sick" passion for this shit either. its like a game to me. i like the challenge.

i'll test out your code now. I thought i had something like that, then wound up changing it because it needed the other 2>1 2>4 etc
 
Alright, Scheisse, its time to learn loops. I gotta say, you were right last night when you said they arent hard (although i say that now without even looking at the debugs).

I'm going to start on them now, but i will post them for you so you can take a look early at them whenever you want:

Debug1

Code:
// DebugSix1.java
// Start with a penny
// double it every day
// how much do you have in a 30-day month?
public class DebugSix1
{
   public static void main(String args[])
   {
     final int DAYS = 30;
     double money = .01;
     while(day < DAY)
     {
      money = 2 * previousAmount;
      ++day;
      Systm.out.println("After day ", day,
         " you have ", money);

    }
   }
}

Debug2

Code:
// DebugSix2.java
// Print every character between Unicode 65 and 122
// Start new line after 20 characters
public class DebugSix2
{
   public static void main(String args[])
   {
     char letter;
     
     for(a = 65; a++; a <= 122)
       {
         letter = (char)a;
         System.out.print("  " + letter);
         if((a==85)&&(a == 105))
         System.out.println();
     }

     System.out.println("\nEnd of application;

    }

}

Debug3

Code:
// DebugSix3.java
// Prompt user for value to start
// Value must be between 1 and 20 inclusive
// At command line, count down to blastoff
// With a brief pause between each displayed value
public class DebugSix3
{
  public static void main(String[] args)
  {
    String userNumString;
    int userNum;
    userNumString = JOptionPane.showInputDialog(null,
        "Enter a number between 1 and 20 inclusive");
    userNum = Integer.parseInt(userNumString);
    while(userNum < 1 || userNum < 20)
    {
       userNumString = JOptionPane.showInoutDialog(null,
        "Number out of range" +
        "\nEnter a number between 1 and 20 inclusive");
       userNum = Integer.parseInt(userString);
    }
    for(val = userNum; val < 0; --val)
    {
      System.out.print val + "  ";
      for(int x = 0; x < 100000; ++x)
       for(int y = 0; y < 10000; ++y);
       // Adjust these numbers for faster or slower performance
      System.out.println("Blastoff!");
    }
  }
}

Debug4

Code:
// DebugSix4.java
// Displays 5 random numbers between 
// (and including) user-specified values
import javax.swing.*;
import java.util.*;
public class DebugSix4
{
  public static void main(String[] args)
  {
    int high, low, count;
    String highS, lowS;
    // Prompt user to enter high and low values
    lowS = JOptionPane.showInputDialog(null,
      "This application displays five random numbers" +
      "\nbetween the low and high values you enter" +
       "\nEnter low value now");
    highS = JOptionPane.showInputDialog(null,
       "Enter high value");
    low = Integer.parseInt(low);
    high = Integer.parseInt(high);
    while (count < 5)
      double result = Math.random();
        // random() returns value between 0 and 1
      int answer = (int) (result * 10 + low);
        // multiply by 10 and add low is random is at least that much
      if(answer <= high)
      {
         System.out.print(answer + "  ");
        // only use answer if it is low enough
      }
      ++count;
    }
    System.out.println;
    System.exit(0);
  }
}

Thanks in advance, dude.
 
Heres what i did for Debug1. No idea why its giving me a error message for the Print Stream :(

Code:
// DebugSix1.java
// Start with a penny
// double it every day
// how much do you have in a 30-day month?

public class DebugSix1
{
   public static void main(String[] args)
   {
     int day;
     int previousAmount;
     final int DAYS = 30;
     double money = .01;
     while(day < DAYS)
	  money = previousAmount + 1;
	  ++day;
     System.out.printIn("After day " + day + " you have " + money);
   }
}
 
My debug2: (I know i need to skip a line after 20 characters. We did this before in the previous chapter, but i may need you to refresh my memory again how you did it)

Code:
// DebugSix2.java
// Print every character between Unicode 65 and 122
// Start new line after 20 characters
public class DebugSix2
{
   public static void main(String[] args)
   {
     char letter;
     char a;
     for(a = 65; a <= 122; ++a)
     {
         letter = (char)a;
         System.out.print("  " + letter);
         if((a==85)&&(a == 105))
         System.out.println();
     }

     System.out.println("\n " + "End of application");

    }

}
 
My debug3: (i havent ran it yet, but it compiled)

Code:
// DebugSix3.java
// Prompt user for value to start
// Value must be between 1 and 20 inclusive
// At command line, count down to blastoff
// With a brief pause between each displayed value

import javax.swing.JOptionPane;

public class DebugSix3
{
  public static void main(String[] args)
  {
    String userNumString;
    int val;
    int userNum;
    userNumString = JOptionPane.showInputDialog(null,
    "Enter a number between 1 and 20 inclusive");
    userNum = Integer.parseInt(userNumString);
    while(userNum > 1 || userNum > 20)
    {
       userNumString = JOptionPane.showInputDialog(null,
        "Number out of range" +
        "\nEnter a number between 1 and 20 inclusive");
       userNum = Integer.parseInt(userNumString);
    }
    for(val = userNum; val > 20; --val)
    {
      System.out.print (val + "  ");
      for(int x = 0; x < 100000; ++x)
       for(int y = 0; y < 10000; ++y);
       // Adjust these numbers for faster or slower performance
      System.out.println("Blastoff!");
    }
  }
}
 
My guess is you enter a number, it validates if the number is between 1-20, then counts down from that number.

Did you take a look at the other 2 debugs i posted as well?
 
Actually that one is wrong^
You don't even really need the "previousAmount" you just add money to itself every time. That's how I would do it at least.
Thats what i thought too, but i havent spent enough time with it yet to know for sure. I knew you would help me out on this. Greatly appreciated. Top notch work.

Im going to look at your code now for Debug2 until i get a grasp for it, then move on to Debug4.

Thanks again, Scheisse.
 
Code:
if(count == 20)
{
System.out.println();
count = 0;
}
}
Ok, i get Debug2 now, but can you just tell what the point of count = 0 is? Thats the only part i don't get.
 
wtf at Debug4. shit is too hard and makes no sense, here it is again:

Code:
// DebugSix4.java
// Displays 5 random numbers between 
// (and including) user-specified values
import javax.swing.*;
import java.util.*;
public class DebugSix4
{
  public static void main(String[] args)
  {
    int high, low, count;
    String highS, lowS;
    // Prompt user to enter high and low values
    lowS = JOptionPane.showInputDialog(null,
      "This application displays five random numbers" +
      "\nbetween the low and high values you enter" +
       "\nEnter low value now");
    highS = JOptionPane.showInputDialog(null,
       "Enter high value");
    low = Integer.parseInt(low);
    high = Integer.parseInt(high);
    while (count < 5)
      double result = Math.random();
        // random() returns value between 0 and 1
      int answer = (int) (result * 10 + low);
        // multiply by 10 and add low is random is at least that much
      if(answer <= high)
      {
         System.out.print(answer + "  ");
        // only use answer if it is low enough
      }
      ++count;
    }
    System.out.println;
    System.exit(0);
  }
}
 
This is all i did to Debug4 so far:

Code:
// DebugSix4.java
// Displays 5 random numbers between 
// (and including) user-specified values
import javax.swing.JOptionPane;
public class DebugSix4
{
  public static void main(String[] args)
  {
    int high, low, count;
    String highs, lows;
    // Prompt user to enter high and low values
    lowString = JOptionPane.showInputDialog(null,
      "This application displays five random numbers" +
      "\nbetween the low and high values you enter" +
       "\nEnter low value now");
    highString = JOptionPane.showInputDialog(null,
       "Enter high value");
    low = Integer.parseInt(low);
    high = Integer.parseInt(high);
    while (count < 5)
      double result = Math.random();
        // random() returns value between 0 and 1
      int answer = (int) (result * 10 + low);
        // multiply by 10 and add low is random is at least that much
      if(answer <= high)
      {
         System.out.print(answer + "  ");
        // only use answer if it is low enough
      }
      ++count;
    }
    System.out.println;
    System.exit(0);
  }
}
i get up double result and end up with errors. here are all the errors i get:




DebugSix4.java:21: '.class' expected
double result = Math.random();
^
DebugSix4.java:21: not a statement
double result = Math.random();
^
DebugSix4.java:21: illegal start of expression
double result = Math.random();
^
DebugSix4.java:21: ';' expected
double result = Math.random();
^
DebugSix4.java:32: <identifier> expected
System.out.println;
^
DebugSix4.java:33: <identifier> expected
System.exit(0);
^
DebugSix4.java:33: illegal start of type
System.exit(0);
^
DebugSix4.java:35: class, interface, or enum expected
}
^
8 errors
 
Thanks dude, but what you had was correct. It creates five random numbers between the high and low. It was spread out perfectly.

Im not sure if this is done yet though. So i went ahead and sent it to my professor and she emailed me back today with her edits. This is what she put (its still doing the same exact thing as before, just without a lot of those lines):

Code:
// Jason Sodano
// November 11th, 2010
// DebugSix4.java
import javax.swing.*;
import java.util.*;
public class DebugSix4
{
  public static void main(String[] args)
  {
    int high, low;
	 int count = 0;
    String highS, lowS;
	 int result;
	 
    // Prompt user to enter high and low values
    lowS = JOptionPane.showInputDialog(null,
      "This application displays five random numbers" +
      "\nbetween the low and high values you enter" +
       "\nEnter low value now");
    highS = JOptionPane.showInputDialog(null,
       "Enter high value");
    low = Integer.parseInt(lowS);
    high = Integer.parseInt(highS);

	while (count++ < 5)
		{
				result = (int)(Math.random() * 100) % (high-low+1) + low;
				System.out.println(result);
		}
	}
}
so is this done? because my question to her is what is the point of of this line:
Code:
 result = (int)(Math.random() * 100) % (high-low+1) + low;
the applications purpose is to ask for a high and low number then generate 5 random numbers between it. so really what else is there to do? any tips? because i dont even know how to respond to her now.
 
Ok, she had mentioned to me there was a section on random numbers in the chapter and to go over it. Thats what ima do. I did not see anything in the chapter in regards to it.

I'm going to look this over, but now i have a better idea on what to do. Thanks SN.
 
I found it in the book. It was actually in the appendix of the book, not the chapter.

You have to import java.util.*; or java.util.Random..... the other method being used in that program is to calculate within a given amount of numbers like you mentioned.

Thats as far as i got, but i figured i'd share what i found so far. Hopefully you can add your knowledge to this.
 
I'll take it, as i have no energy left to try and figure this out. Its displaying integers, so its not going to display every number. Thats all i can think.

And lol at her finally giving me my grade for the last debugs. She gave me 2 out of 4. Her comments were:

Missed an error:
debug 5-2 -- display in table format (-1)
debug 5-4 -- does not display the highest integer entered (-1)


first off, i have no idea what shes talking about with display in table format. no idea at all.

secondly, i checked the code and test out each placement of the highest integer and it always came out right, here was the code that i submitted for both.


debug4

Code:
// FixDebugFive4.java
// Jason Sodano
// October 30th, 2010
import javax.swing.*;
public class FixDebugFive4
{
   public static void main (String args[]) 
   {
    	int one, two, three, four;
    	String str, output;
	 	// Inputs the numbers in order to determine the highest number.
    	str = JOptionPane.showInputDialog(null,"Enter an integer");
    	one = Integer.parseInt(str);
    	str = JOptionPane.showInputDialog(null,"Enter an integer");
    	two = Integer.parseInt(str);
    	str = JOptionPane.showInputDialog(null,"Enter an integer");
    	three = Integer.parseInt(str);
    	str = JOptionPane.showInputDialog(null,"Enter an integer");
    	four = Integer.parseInt(str);
	 
	 // Determines which is the highest number.
    	if(one > two && one > three && one > four)
       output = "Highest is " + one;
    	else if(two > three && two > four)
       output = "Highest is " + two;
    	else if(three > four)
       output = "Highest is " + three;
    	else
       output = "Highest is " + four;
				
	 // Outputs highest of four numbers			
    JOptionPane.showMessageDialog(null, output);
    System.exit(0);
  }
}

and im not even going to post the debug2 because im so fed up with this class its not even funny. its fucking bullshit. she told me it was right to begin with. maybe she needs to lay off the back medicine a bit.

anyway, thank you for all your help, Scheiss. you did nothing wrong. just wanted to show you that.

im going to post the final assignment for this week in my next post. im not even going to attempt to try and fix that random bullshit anymore. ive had enough.
 
Here is the final assignment (Im typing it out word for word from the book)

1. a. Write an application that creates a quiz. This quiz contains at least five questions about a hobby, popular music, astronomy, or any other personal interest. Each question should be a multiple-choice question with at least four options. When the user answers the question correctly, display a congratulatory message. If the user responds to a question incorrectly, display an appropriate message as well as the correct answer. At the end of the quiz, display the number of correct and incorrect answers, and the percentage of correct answers. Save as Quiz.java

b Modify the Quiz application so that the user is presented with each question continually until it is answered all correctly. Remove the calculation for percentage of correct answers--all user will have 100% correct by the time they complete the application. Save as Quiz2.java
 
Heres what i did for the Quiz so far... I have no idea how to display the number of correct and incorrect answers and the percentage of correct answers.

Quiz

Code:
// Quiz

import java.lang.String;
import javax.swing.*;
public class Quiz
{
  public static void main(String args[])
  {
   String QuestionString;
   int one, two, three, four, five;
	
    QuestionString = JOptionPane.showInputDialog(null,
   "Who is known as The King of Rock and Roll?" + "\n1 - BB King \n2 - Elvis" +
   "\n3 - Jimi Hendrix \n4 - Miles Davis");
    one = Integer.parseInt(QuestionString);
     
     if(one == 2) 
     QuestionString = JOptionPane.showInputDialog(null, "Correct Answer!");
     else
     QuestionString = JOptionPane.showInputDialog(null, "The Correct Answer was Elvis");
     //end Question 1		
			 
     QuestionString = JOptionPane.showInputDialog(null,
     "Which artist had the hit song entitled: Insane in the Membrane?" + 
     "\n1 - Blink182 \n2 - Cypress Hill" +
     "\n3 - The Beatles \n4 - Lady Gaga");
     two = Integer.parseInt(QuestionString);
	
     if(two == 2)
     QuestionString = JOptionPane.showInputDialog(null, "Correct Answer!");
     else
     QuestionString = JOptionPane.showInputDialog(null, "The Correct Answer was Cypress Hill");
     //end Question 2
			 
     QuestionString = JOptionPane.showInputDialog(null,
    "This rapper is known for interupting Taylor Swift at the MTV Music Awards" 
    + "\n1 - Kanye West \n2 - Snoop Dogg" +
    "\n3 - Eminem \n4 - Vanilla Ice");
    three = Integer.parseInt(QuestionString);
	
    if(three == 1)
    QuestionString = JOptionPane.showInputDialog(null, "Correct Answer!");
    else
    QuestionString = JOptionPane.showInputDialog(null, "The Correct Answer was Kanye West");
    //end Question 3
	
    QuestionString = JOptionPane.showInputDialog(null,
   "This guitarist was featured on the premiere episode of Conan" + "\n1 - Joe Satriani \n2 - Bob Dylan" +
   "\n3 - Jack White \n4 - Carlos Santana");
   four = Integer.parseInt(QuestionString);
	
   if(four == 3)
   QuestionString = JOptionPane.showInputDialog(null, "Correct Answer!");
   else
   QuestionString = JOptionPane.showInputDialog(null, "The Correct Answer was Jack White");
   //end Question 4
	
   QuestionString = JOptionPane.showInputDialog(null,
   "Pink Floyd is best known for the movie produced after their hit record called: "
   + "\n1 - Dark Side of the Moon \n2 - Echoes" +
   "\n3 - Wish You Were Here \n4 - The Wall");
   five = Integer.parseInt(QuestionString);
	
   if(five == 4)
   QuestionString = JOptionPane.showInputDialog(null, "Correct Answer!");
   else
   QuestionString = JOptionPane.showInputDialog(null, "The Correct Answer was The Wall");	
   //end Question 5
  }
}
I have tried everything, but i cant figure out.
 
Well, you just keep owning her, dude. Thats why i come to you instead of her and why i came to you in the first place. The help i was getting from her was just as much bullshit, but whatever, i'll take her falling on her ass as a sign of bad karma.

Through trial and error, i was able to figure out to just take out "QuestionString = " before the begining of the JOptionPane, then just change "ShowInputDialog" to "ShowMessageDialog." Here is the code

Code:
// Quiz 2

import java.lang.String;
import javax.swing.*;
public class Quiz2
{
  public static void main(String args[])
  {
   String QuestionString;
   int one = 0, two = 0, three = 0, four = 0, five = 0;
	int correct = 0, incorrect = 0;
	
	while(one != 2)
	{
    QuestionString = JOptionPane.showInputDialog(null,
   "Who is known as The King of Rock and Roll?" + "\n1 - BB King \n2 - Elvis" +
   "\n3 - Jimi Hendrix \n4 - Miles Davis");
    one = Integer.parseInt(QuestionString);
     
     if(one == 2) 
	  {
	  JOptionPane.showMessageDialog(null, "Correct Answer!");
		  correct++;
	  }
     else
	  {
   	  JOptionPane.showMessageDialog(null, "Try Again");
	  	  incorrect++;
	  }
     //end Question 1		
	}
	while(two != 2)
	{	 
     QuestionString = JOptionPane.showInputDialog(null,
     "Which artist had the hit song entitled: Insane in the Membrane?" + 
     "\n1 - Blink182 \n2 - Cypress Hill" +
     "\n3 - The Beatles \n4 - Lady Gaga");
     two = Integer.parseInt(QuestionString);
	
     if(two == 2)
	  {
     JOptionPane.showMessageDialog(null, "Correct Answer!");
	  correct++;
     }
	  else
	  {
     JOptionPane.showMessageDialog(null, "Try Again");
     incorrect++; 
	  }
	  //end Question 2
	}
	
	while(three != 1)
	{	 
     QuestionString = JOptionPane.showInputDialog(null,
    "This rapper is known for interupting Taylor Swift at the MTV Music Awards" 
    + "\n1 - Kanye West \n2 - Snoop Dogg" +
    "\n3 - Eminem \n4 - Vanilla Ice");
    three = Integer.parseInt(QuestionString);
	
    if(three == 1)
	 {
    JOptionPane.showMessageDialog(null, "Correct Answer!");
	 correct++;
    }  
	 else
	 {
    JOptionPane.showMessageDialog(null, "Try Again");
	 incorrect++;
	 }
    //end Question 3
	}
	
	while(four != 3)
	{
    QuestionString = JOptionPane.showInputDialog(null,
   "This guitarist was featured on the premiere episode of Conan" + "\n1 - Joe Satriani \n2 - Bob Dylan" +
   "\n3 - Jack White \n4 - Carlos Santana");
   four = Integer.parseInt(QuestionString);
	
   if(four == 3)
	{
   JOptionPane.showMessageDialog(null, "Correct Answer!");
	correct++;
	}
   else
	{
   JOptionPane.showMessageDialog(null, "Try Again");
	incorrect++;
	}
   //end Question 4
	}
	
	while(five != 4)
	{ 
   QuestionString = JOptionPane.showInputDialog(null,
   "Pink Floyd is best known for the movie produced after their hit record called: "
   + "\n1 - Dark Side of the Moon \n2 - Echoes" +
   "\n3 - Wish You Were Here \n4 - The Wall");
   five = Integer.parseInt(QuestionString);
	
   if(five == 4)
	{
   JOptionPane.showMessageDialog(null, "Correct Answer!");
	correct++;
	}
   else
	{
   JOptionPane.showMessageDialog(null, "Try Again");	
	incorrect++;
	}
   //end Question 5
	}
	
	System.out.print("Correct Answers: " + correct + "\n");
	System.out.print("Incorrect Answers: " + incorrect);
  }
}

Good shit, Scheiss.

BTW man, do you have any idea how to add the calculate percentage of the number of answers you got right for Quiz1? Thats the only other thing i need.
 
Awesome. I'll take care of that later on tonight. Im sick in bed at the moment.

Thank you so much, dude.
 
Scheiss, just a quick heads up, that Quiz2 application states to get rid of the calculate percentage since you are given an infinite number of tries to get it right. With that said, i dont see the point of even adding those correct/incorrect display lines since its always going to say 5 for the correct, and it doesnt say anything to leave the number of incorrect tries. I can probably handle this on my own, but i just wanted to tell you anyway.

The calculate percentage was for the Quiz1 application, and since there is 5 questions, you never have to worry about the additional decimal points. I will look it over anyway, but i dont think theres anything that needs to be put. All it says in the book is to multiply by 100 to get rid of the decimal points, which you already did. However, if there is anything youd like to add, feel free to do so.

I will post the remaining codes tomorrow most likely. Thanks for your time, as always.
 
Some justice has been served....

"High priority

Hi Jason.

I checked Debug 4. You are correct. It is reporting the highest value. I also checked Debug 2. You were to report the numbers in a table format and move to a new line for every 10. Your numbers are reported in a linear fashion (used println rather than print). I am adjusting your grade by 1 point.

Prof. Verno"

Still though, she never said anything to me about the table format when i showed it to her. She has a funny way of doing things.
 
Indeed, nor is she even mentioning these problems when i show it to her. She'll mention EVERY other thing thats wrong with it, except for one thing just so she could mark it wrong. She knows i have a 4.00 GPA since shes my advisor... Yea she screwed me out of that my first year of college anyway. I could of taken these classes a year ago. Some advisor huh?

Anyway, I'm sorry to hear what you're going through as well, Scheiss. Trust me if there was anything i could do to help you, i would. You know im here if you need anything dude.

The tests are bullshit too for game classes. They always make em where the majority of people are gonna get a b on it, then use the extra credit to boost up their grade to an A at the end of the semester. Such bullshit.

I'm running through the debugs right now while i have energy. Im still sick. I'll post my final results in my next post.