Basically Create the above images, thats what the code should output student.jav
ID: 3667695 • Letter: B
Question
Basically Create the above images, thats what the code should output
student.java
public class Student extends Person{
String status;
String Major;
Student(String informedFirstName, String informedLastName, int informedAge) {
super(informedFirstName, informedLastName, informedAge);
if (informedAge <= 25) {
status = "Traditional";
} else {
status = "Non-Traditional";
}
}
public String getMajor() {
return Major;
}
public void setMajor(String Major) {
this.Major = Major;
}
String whatIsUp() {
int n = 0;
String b = "...";
n = (int) (Math.random() * 3);
if (n == 0) {
b = "Attending class";
}
if (n == 1) {
b = "Doing homework";
}
if (n == 2) {
b = "Surfing the web";
}
return b;
}
String getStatus() {
return status;
}
String getInfo() {
return ("Name = " + getName() + ", age =" + getAge() + ", Status = "+getStatus()+ ", Major= "+getMajor());
}
}
class Person{
String informedFirstNam;
String informedLastName;
int informedAge;
public Person(String informedFirstName, String informedLastName, int informedAge)
{
this.informedFirstNam=informedFirstName;
this.informedLastName=informedLastName;
this.informedAge=informedAge;
}
String getName()
{
return(this.informedFirstNam+" "+this.informedLastName);
}
int getAge()
{
return(this.informedAge);
}
}
app.java
public class app
{
public static void main(String args[])
{
myJFrame mjf = new myJFrame();
}
}
myJFrame.java
import java.awt.*;
import javax.swing.*;
public class myJFrame extends JFrame
{
public myJFrame ()
{
super ("My First Frame");
myJPanel mjp = new myJPanel();
getContentPane().add(mjp,"Center");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize (800, 480);
setVisible(true);
}
}
myJPanel.java
import java.awt.*;
import javax.swing.*;
public class myJPanel extends JPanel
{
public myJPanel ()
{
super ();
GridLayout grid = new GridLayout(1,1);
setLayout(grid);
//try commenting the two lines above to run the lab without a layout
setBackground(Color.green);
PanelLeft left = new PanelLeft();
PanelRight right = new PanelRight();
add(left);
add(right);
}
}
Panelleft.java
import java.awt.*;
import javax.swing.*;
public class PanelLeft extends JPanel
{
public PanelLeft ()
{
super ();
GridLayout grid = new GridLayout(1,1);
setLayout(grid);
//try commenting the two lines above to run the lab without a layout
setBackground(Color.pink);
JButton jb1 = new JButton("I belong to panel left");
add(jb1);
}
}
Panelright.java
import java.awt.*;
import javax.swing.*;
public class PanelRight extends JPanel
{
public PanelRight ()
{
super ();
GridLayout grid = new GridLayout(3,1);
setLayout(grid);
//try commenting the two lines above to run the lab without a layout
setBackground(Color.red);
JButton jb1 = new JButton("I belong to panel right");
JButton jb2 = new JButton("Hi");
jb2.setBackground(Color.red);
JButton jb3 = new JButton("I am a JButton)");
add(jb1);
add(jb2);
add(jb3);
}
}
If you can complete the assignment with out the provided code that will do fine. Thanks
Explanation / Answer
app.java
public class HelloWorld
{
public static void main(String args[])
{
myJFrame mjf = new myJFrame();
}
}
myJFrame.java
import java.awt.*;
import javax.swing.*;
public class myJFrame extends JFrame
{
public myJFrame ()
{
super ("My First Frame");
myJPanel mjp = new myJPanel();
getContentPane().add(mjp,"Center");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize (640, 480);
setVisible(true);
}
}
myJPanel.java
import java.awt.*;
import javax.swing.*;
public class myJPanel extends JPanel
{
public myJPanel()
{
super();
setBackground(Color.gray);
setLayout(new BorderLayout());
myJPanel1 p1 = new myJPanel1();
myJPanel2 p2 = new myJPanel2();
add(p1,"North");
add(p2,"Center");
}
}
myJPanel1.java
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class myJPanel1 extends JPanel
{
JButton b1;
public myJPanel1()
{
super();
setBackground(Color.yellow);
b1 = new JButton("student info will be here later ...");
add(b1);
}
}
myJPanel2.java
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class myJPanel2 extends JPanel
{
JButton b2;
student st1;
public myJPanel2()
{
super();
st1 = new student("Fred","Fonseca",44);
setBackground(Color.pink);
b2 = new JButton("whats Up will be shown here" );
add(b2);
}
}
student.java
import java.awt.*;
import javax.swing.*;
public class student
{
String firstName;
String lastName;
int age;
public student(String a, String b, int x)
{
super();
firstName = a;
lastName = b;
age = x;
}
String getInfo()
{
return "NAME = "+firstName+ " "+lastName+" "+"Age = "+age;
}
String whatsUp()
{
double r = Math.random();
int myNumber = (int) (r * 3f); //comment: a random number between 0 and 2
String answer = "I don't know";
if(myNumber == 0) answer = "searching the web";
if(myNumber == 1) answer = "doing Java";
if(myNumber == 2) answer = "Listening to endless lecture";
return answer;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.