Trying to help a student fix an assignment for his computer math class. The text is overlapping when he runs his applet. How do we change this?
The assignment is meant to teach basic if-then loops.
Here's the code:
import java.awt.*;
import java.lang.*;
import java.applet.*;
public class HibbertJ_if extends Applet {//more points lost
public void init() { }
public void paint(Graphics g) {
int Rigby=(int)(Math.random()*123)+123;
int Mario=(int)(Math.random()*321)+2;
int SJF = (int)(Math.random()*2)+3;
int Drake = (int)(Math.random()*9)+7;
int Luigi = (int)(Math.random()*6)+8;
int Benson = (int)(Math.random()*3)+4;
boolean DoYouLikeToLose=getRandomBoolean();
boolean DoYouLikeMario=getRandomBoolean();
boolean DoYouSlackOff=getRandomBoolean();
boolean IAmLolzingAtYou=getRandomBoolean();
boolean IAmBeatingYou=getRandomBoolean();
boolean DoYouLikeRegularShow=getRandomBoolean();
String Go="Mr. Win";
String Bball="Wii U";
String Hib="PS4";
String Son="3DS";
String Marshall="Compaq";
String Jordan="Beats";
String student="sweeeeet";//need 3 string variables
//type code here
//start first word
g.drawString("x = "+Rigby,100,15);
g.drawString("y= "+SJF,200,15);
g.drawString("Headaches= "+DoYouLikeMario,300,15);
if(DoYouLikeMario)//equals NOT =, = assigns values, == says if same
{
if(SJF>=Rigby)//greater than or equal to
{
g.drawString("Mordo has a "+Rigby,10,15);
}
else
g.drawString("SMB has a ",10,15);;
}
else
g.drawString("SMG4 has a ",10,15);
if(DoYouLikeMario)//equals NOT =, = assigns values, == says if same
{
g.drawString(Go,10,30);
if(SJF>=Rigby)//greater than or equal to
g.drawString(Bball,10,30);
}
if(Rigby<=SJF)//less than or equal to
g.drawString(Hib,10,45);
else if(SJF>Rigby)//greater than
g.drawString(Son,10,60);
else
{
g.drawString(student,10,75);
if(Mario<SJF)//less than
{
g.drawString(Marshall,10,90);
if(Rigby!=Rigby)//Not equal to
g.drawString(student,10,105);
}
}
if(Mario==SJF&&SJF>Rigby)//(equal to) AND (greater than)
g.drawString(Jordan,10,120);
if(Luigi==Drake&&Benson>Rigby)//(equal to) AND (greater than)
g.drawString(Bball,10,120);
if(Rigby==SJF||SJF==Mario)//(equal to) OR (equal to)
g.drawString(student,10,135);
if(Mario==Drake||Rigby==SJF)//(equal to) OR (equal to)
g.drawString(Go,10,135);
else
g.drawString(Go,10,135);
if(DoYouLikeMario)
g.drawString(Bball,10,135);
if(DoYouSlackOff)
g.drawString(Hib,10,135);
if(IAmLolzingAtYou)
g.drawString(Son,10,135);
if(true)
g.drawString("This always happens",1,100);
//if(false); also works, ; means some line of code could be there
}
public boolean getRandomBoolean() {
return Math.random() < 0.5;
}
}