Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Don't use a scanner class or any other input which requests user. Application should run on self contained and without any user input. A04A Starter

Don't use a scanner class or any other input which requests user. Application should run on self contained and without any user input.

image text in transcribed

image text in transcribedimage text in transcribedimage text in transcribed

A04A Starter project below:

Controller: (no changes needed)

package Controller;

import Model.Model; import Model.Student; import View.View; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Scanner; import javax.swing.JButton;

public class Controller {

Model model; View view; int k = 0; int n1, n2, n3;

public Controller(Model model, View view) { this.n2 = 1; this.n3 = 2; this.n1 = 0; this.model = model; this.view = view; view.displayData((Student) model.findStudent(n1)); view.displayData((Student) model.findStudent(n2)); view.displayData((Student) model.findStudent(n3)); }

}

MailAddress:

package Model;

public class MailAddress {

String streetAddress; String city; String state; int zipcode;

public MailAddress(String inf_streetAddress, String inf_city, String inf_state, int inf_zipcode) { streetAddress = inf_streetAddress; city = inf_city; state = inf_state; zipcode = inf_zipcode; }

@Override public String toString() { return streetAddress + "," + city + "," + state + "," + zipcode; }

}

Model:(no changes needed)

package Model;

import java.util.ArrayList;

public class Model {

ArrayList sts = new ArrayList();

public Model() { //creates 3 students MailAddress addr1 = new MailAddress("107 W College Avenue", "State College", "PA", 16801); Student st1 = new Student("Emily", "Smith", 20, addr1); MailAddress addr2 = new MailAddress("200 W College Avenue", "State College", "PA", 16801); Student st2 = new Student("Mary", "Doe", 20, addr2); MailAddress addr3 = new MailAddress("300 W College Avenue", "State College", "PA", 16801); Student st3 = new Student("John", "Doe", 20, addr3); //add them to the array of students sts.add(st1); sts.add(st2); sts.add(st3); }

public Object findStudent(int index) { return sts.get(index); } }

Student:

package Model;

public class Student { //---------Declaring attributes----

String firstName; String lastName; int age; MailAddress address; int credits; //------------------------------ //----------Constructor------------

public Student(String a, String b, int c, MailAddress d) { firstName = a; lastName = b; age = c; address = d; credits = creditsThisSemester(); }

//---------- METHODS -------- public String getInfo() { return "NAME = " + firstName + " " + lastName + " " + "Age = " + age + ", address=" + address.toString() + " credits=" + credits; }

//------------------------------------------------ public int creditsThisSemester() { //calculate randomly a new value for credits in the semester //and updates the attribute credits double dn = Math.random(); credits = (int) (15.0 * dn); return credits; } }

InitialPanel:

package View;

import java.awt.*; import java.util.ArrayList; import javax.swing.*;

public class InitialPanel extends JPanel {

public InitialPanel() { super(); setBackground(Color.darkGray); JButton b1 = new JButton("number 01"); add(b1); } }

MainFrame:

package View;

import java.awt.*; import javax.swing.*;

public class MainFrame extends JFrame {

private InitialPanel ip;

public MainFrame() { super("A04A - Basic Graphics"); setupLayoutForMacs(); ip = new InitialPanel(); add(ip, "Center"); //------------------------------------------------------ setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(720, 280); setVisible(true); }

private void setupLayoutForMacs() { // On some MACs it might be necessary to have the statement below //for the background color of the button to appear try { UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch (Exception e) { e.printStackTrace(); } //------------------------------------------------------ }

/** * @return the ip */ public InitialPanel getIp() { return ip; }

/** * @param ip the ip to set */ public void setIp(InitialPanel ip) { this.ip = ip; } }

View:

package View;

public class View {

private MainFrame mf;

public View() { mf = new MainFrame(); }

/** * @return the mf */ public MainFrame getMf() { return mf; }

/** * @param mf the mf to set */ public void setMf(MainFrame mf) { this.mf = mf; } }

App:

import Controller.Controller; import Model.Model; import View.View;

class App {

public static void main(String[] args) { Model model = new Model(); View view = new View(); Controller controller = new Controller(model, view); } }

Assignment Objectives Practice on implementing a MVC project Start working with Java Graphics Deliverables A zipped Java project according to the How to submit Labs and Assignments guide. 0.0. Requirements (these items will be part of your grade) One class, one file. Don't create multiple classes in the same.java file Don't use static variables and methods Encapsulation: make sure you protect your class variables and provide access to them through get and set methods all the classes are required to have a constructor that receives all the attributes as parameters and update the attributes accordingly Follow Horstmann's Java Language Coding Guidelines Organized in packages (MVC - Model - View Controller) Contents This is a variation on the last assignment. Only View will have a new functionality, Controller and Model should stay the same. Model #1 - Controller asks Model for student data as text Controller and Model are exactly the same as in the last assignment. No changes needed. student Controller View #3 - View receives the data and displays it as graphics MO #2 - Controller passes student data as text to to View and asks View to displays it as text ity Singe - 20 1 7 College Co . PAS 11 MANE - My Dee Age - adress:200 W ege Gallego P161019 WAME W C CGL The Netbeans Project Regarding the starter Netbeans project you have to options: 1. Keep using your project from the last assignment and 1. add View.java, MainFrame.Java and InitialPanel.java from this A04A starter project or 1. Use the A04A starter project and 1. add the updates from your previous project (mostly from Model.java) The starter NetBeans project that you will use looks like this: o App.java Controller o Controller.java Model o Model.java o MailAddress.java o Student.java View o InitialPanel.java o MainFrame.java o View.java Projects Files Services A04A_Starter Source Packages EB App.java 3 Controller Controller.java Model MailAddress.java Model.java Student.java View InitialPanel.java Mainframe.java View.java Functionality The main objective is to make View display the information about 3 students, but this time in buttons. The students are created in Model. Controller will retrieve the data from Model and pass it to View.View will use buttons organized in a layout to display the following result: A04A - Basic Graphics NAME - Emily Smith Age = 20, address=107 W College Avenue, State College, PA,16801 13 NAME - Mary Doe Age = 20, address=200 W College Avenue,State College, PA, 16801 9 NAME = John Doe Age = 20, address=300 W College Avenue,State College, PA,16801 10 The number of credits are calculated on the fly in Model and might vary in the output of your assignment. You will need to work on View adding single statements and methods to achieve the lab objectives. Model and Controller might need few updates to adjust on how View wants to receive the Strings with the information to be displayed. App o it has the main method which is the method that Java looks for and runs to start any application o it creates 3 objects, one of the Model class, one of the View class and one of the Controller class. o When it creates Controller, it passes the two other objects as input parameters so that Controller has access to Model and View. Model model = new Model(); View view = new View(); Controller controller = new Controller (model, view); Controller o will retrieve from Model (using the model object) data about each student to be displayed o will pass the data to View, which will display it o the two operations above will work best if Model and View have methods that help with that. You are writing these methods or reusing them from the previous assignment Model o it is already given in the starter project although you will need to add some functionality o it needs a method that returns data about a specific student in the array (you will write this method or a similar one) o it might need a method that returns all the students' information but packaged as individual elements public class Model ArrayList sts = new ArrayList(); public Model() //creates 3 students MailAddress addr1 = new mailAddress("107 W College Avenue", "State College", "PA", 16801); Student st1 = new student("Emily", "Smith", 20, addr1); MailAddress addr2 = new mailAddress("200 W College Avenue", "State College", "PA", 16801); Student st2 = new student("Mary", "Doe", 20, addr2); MailAddress addr3 = new mailAddress("300 W College Avenue", "State College", "PA", 16801); Student st3 = new student("John", "Doe", 20, addr3); //add them to the array of students sts.add(sti); sts.add(st2); sts.add(st); Mail Address o it is used by the Student class and doesn't need any updates Student o it is used in Model and doesn't need any updates. View o In this assignment, is much more complex than in the previous assignment o it has a Frame It has a Panel The panel has buttons it needs a method to receive information to be displayed in its buttons the method needs to receive as an input parameter the text information and the number (or index) of the button to be used Main Frame o it is a JFrame used as a container for a JPanel InitialPanel o it needs a layout o it has 3 buttons (the best place to create them might be the constructor) o a method to display information on its buttons the input parameters should be the string to be displayed a number telling in which button it should be displayed Assignment Objectives Practice on implementing a MVC project Start working with Java Graphics Deliverables A zipped Java project according to the How to submit Labs and Assignments guide. 0.0. Requirements (these items will be part of your grade) One class, one file. Don't create multiple classes in the same.java file Don't use static variables and methods Encapsulation: make sure you protect your class variables and provide access to them through get and set methods all the classes are required to have a constructor that receives all the attributes as parameters and update the attributes accordingly Follow Horstmann's Java Language Coding Guidelines Organized in packages (MVC - Model - View Controller) Contents This is a variation on the last assignment. Only View will have a new functionality, Controller and Model should stay the same. Model #1 - Controller asks Model for student data as text Controller and Model are exactly the same as in the last assignment. No changes needed. student Controller View #3 - View receives the data and displays it as graphics MO #2 - Controller passes student data as text to to View and asks View to displays it as text ity Singe - 20 1 7 College Co . PAS 11 MANE - My Dee Age - adress:200 W ege Gallego P161019 WAME W C CGL The Netbeans Project Regarding the starter Netbeans project you have to options: 1. Keep using your project from the last assignment and 1. add View.java, MainFrame.Java and InitialPanel.java from this A04A starter project or 1. Use the A04A starter project and 1. add the updates from your previous project (mostly from Model.java) The starter NetBeans project that you will use looks like this: o App.java Controller o Controller.java Model o Model.java o MailAddress.java o Student.java View o InitialPanel.java o MainFrame.java o View.java Projects Files Services A04A_Starter Source Packages EB App.java 3 Controller Controller.java Model MailAddress.java Model.java Student.java View InitialPanel.java Mainframe.java View.java Functionality The main objective is to make View display the information about 3 students, but this time in buttons. The students are created in Model. Controller will retrieve the data from Model and pass it to View.View will use buttons organized in a layout to display the following result: A04A - Basic Graphics NAME - Emily Smith Age = 20, address=107 W College Avenue, State College, PA,16801 13 NAME - Mary Doe Age = 20, address=200 W College Avenue,State College, PA, 16801 9 NAME = John Doe Age = 20, address=300 W College Avenue,State College, PA,16801 10 The number of credits are calculated on the fly in Model and might vary in the output of your assignment. You will need to work on View adding single statements and methods to achieve the lab objectives. Model and Controller might need few updates to adjust on how View wants to receive the Strings with the information to be displayed. App o it has the main method which is the method that Java looks for and runs to start any application o it creates 3 objects, one of the Model class, one of the View class and one of the Controller class. o When it creates Controller, it passes the two other objects as input parameters so that Controller has access to Model and View. Model model = new Model(); View view = new View(); Controller controller = new Controller (model, view); Controller o will retrieve from Model (using the model object) data about each student to be displayed o will pass the data to View, which will display it o the two operations above will work best if Model and View have methods that help with that. You are writing these methods or reusing them from the previous assignment Model o it is already given in the starter project although you will need to add some functionality o it needs a method that returns data about a specific student in the array (you will write this method or a similar one) o it might need a method that returns all the students' information but packaged as individual elements public class Model ArrayList sts = new ArrayList(); public Model() //creates 3 students MailAddress addr1 = new mailAddress("107 W College Avenue", "State College", "PA", 16801); Student st1 = new student("Emily", "Smith", 20, addr1); MailAddress addr2 = new mailAddress("200 W College Avenue", "State College", "PA", 16801); Student st2 = new student("Mary", "Doe", 20, addr2); MailAddress addr3 = new mailAddress("300 W College Avenue", "State College", "PA", 16801); Student st3 = new student("John", "Doe", 20, addr3); //add them to the array of students sts.add(sti); sts.add(st2); sts.add(st); Mail Address o it is used by the Student class and doesn't need any updates Student o it is used in Model and doesn't need any updates. View o In this assignment, is much more complex than in the previous assignment o it has a Frame It has a Panel The panel has buttons it needs a method to receive information to be displayed in its buttons the method needs to receive as an input parameter the text information and the number (or index) of the button to be used Main Frame o it is a JFrame used as a container for a JPanel InitialPanel o it needs a layout o it has 3 buttons (the best place to create them might be the constructor) o a method to display information on its buttons the input parameters should be the string to be displayed a number telling in which button it should be displayed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 11g SQL

Authors: Jason Price

1st Edition

0071498508, 978-0071498500

More Books

Students also viewed these Databases questions