A university that you attend requires an application that will print out a Course Report. You are required to create an application with this course data:
COURSE CODE
DISD DIWD DIDM
COURSE NAME
Diploma in Software Development Diploma in Web Development Diploma in Data Metrics
STUDENT NUMBERS
35 28 39
LECTURER
Mr Jones Mrs Smith Mr Ntsinga
In your main class must include a static method to handle the printing of the course report:
COURSE REPORT
Course Diploma in data metrics
Lecturer Mr Ntsinga
venue : venue 1
Would you like to exit the application?Enter (y) to use the exit or any other key to continue(JOptionPane input-must be a while loop)
// some changes
import java.util.HashMap;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
@SuppressWarnings("serial")
public class CourceReport extends JFrame{
HashMap<String, Cource> cources;
public void addCource(String code, String name, String lc, int number, int v)
{cources.put(code, new Cource(code, name, lc, number, v));}
CourceReport()
{setSize(800, 400);
setVisible(true);
cources = new HashMap<>();}
class Cource{
String courceCode, courceName, lecturer;
int studentNumber, venue;
public Cource(String code, String name, String lc, int number, int v)
{courceCode = code;
courceName = name;
lecturer = lc;
studentNumber = number;
venue = v;}
public String toString()
{return "COURSE REPORT\n"+
"Course "+courceName+"\n"+
"Lecturer "+lecturer+"\n"+
"venue : venue "+venue; }
}
public static void main(String args[]) {
CourceReport cr = new CourceReport ();
cr.addCource("DISD", "Diploma in Software Development", "Mr Jones", 35 , 1);
cr.addCource("DIWD", "Diploma in Web Development", "Mrs Smith", 28 , 2);
cr.addCource("DIDM", "Diploma in Data Metrics", "Mr Ntsinga", 39 , 3);
showReports(cr);
}
public static void showReports(CourceReport cr)
{boolean isStarted = false;
String input = "";
while(!input.equals("s"))
{input = JOptionPane.showInputDialog(cr,
"Please enter the code of the course"+(isStarted?
"Would you like to exit the application? \n Enter (y) to use the exit or any other key to continue":""));
if (cr.cources.containsKey(input))
JOptionPane.showMessageDialog(cr, cr.cources.get(input));
else if (!input.equals("s"))
JOptionPane.showMessageDialog(cr,
"Please enter the right code of the course.");
}}
}
Comments
Leave a comment