Sign In
Sign-Up
Welcome!
Close
Would you like to make this site your homepage? It's fast and easy...
Yes, Please make this my home page!
No Thanks
Don't show this to me again.
Close
import javax.swing.*;
public class course
{
int total;
public String title;
public int credits;
public course()
{
credits = 0;
title = "";
}
public void setTitle(String ttl)
{
title = ttl;
}
public void setCredits(int crd)
{
credits = crd;
}
public String getTitle()
{
return title;
}
public int getCredits()
{
return credits;
}
public void inputTitle()
{
title = JOptionPane.showInputDialog("Enter Course Title");
}
public void inputCredits()
{
String tempCredits = JOptionPane.showInputDialog("Enter Course Credits");
credits = Integer.parseInt(tempCredits);
}
}
---------------------------------------------------------------------------------------------
import javax.swing.JOptionPane;
public class main
{
public static void main(String args[])
{
int total;
course first = new course();
first.inputTitle();
first.inputCredits();
course second = new course();
second.setTitle("MAT105");
second.setCredits(3);
course third = new course();
third.setTitle("ESL095");
third.setCredits(6);
total = first.getCredits()+second.getCredits()+third.getCredits();
JOptionPane.showMessageDialog(null, total, "result", JOptionPane.WARNING_MESSAGE);
JOptionPane.showMessageDialog(null, first.getTitle()+": "+first.getCredits()+"\n"+second.getTitle()+": "
+second.getCredits()+"\n"+third.getTitle()+": "+third.getCredits(), "result", JOptionPane.WARNING_MESSAGE);
}
}