Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello there, I am trying to complete the design of three ship classes. I think I

ID: 3648584 • Letter: H

Question

Hello there,

I am trying to complete the design of three ship classes. I think I have the classes (and their inheritance) set up properly. But now I need to create a test program that has a graphical user interface which allows the user to enter the information for a ship and includes a set of radio buttons to select the type of ship to create.

I've set up a GUI shell but after that I'm a little lost in the woods. Any input would be appreciated!

* Here is the GUI shell:
----------------------------------------------------------------
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuBar;

/* This will be the UI shell */
public class ShipGUI
{

public static void main(String[] args)
{
//Creates and set up the window
JFrame frame = new JFrame("ShipGUI");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Creates the menu bar
JMenuBar greenMenuBar = new JMenuBar();
greenMenuBar.setOpaque(true);
greenMenuBar.setBackground(new Color(154, 165, 127));
greenMenuBar.setPreferredSize(new Dimension(200, 20));

//Creates a yellow label
JLabel yellowLabel = new JLabel();
yellowLabel.setOpaque(true);
yellowLabel.setBackground(new Color(248, 213, 131));
yellowLabel.setPreferredSize(new Dimension(200, 180));

//Set the menu bar and add the label to the content pane.
frame.setJMenuBar(greenMenuBar);
frame.getContentPane().add(yellowLabel, BorderLayout.CENTER);

//Display the window.
frame.pack();
frame.setVisible(true);

}

}


And here are the three ship classes:

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

public class Ship
{
private String ShipName;
private String Year;

//blank constructor
public Ship()
{

}

//add year and name to construtor
public Ship(String ShipName,String Year)
{
SetShipName(ShipName);
SetYear(Year);
}

//sets and gets for the data feilds
public void SetShipName(String ShipName)
{
this.ShipName = ShipName;
}

public String GetShipName()
{
return this.ShipName;
}

public void SetYear(String Year)
{
this.Year = Year;
}
public String GetYear()
{
return this.Year;
}

//toString returns a string for the data in the class
public String toString()
{
String strOut;
strOut = "Ship Name: " + this.ShipName + " Year: " + this.Year;
return strOut;
}
}


* CRUISE
----------------------------------------------------------------
public class CruiseShip extends Ship
{
//holds passenger capacity
private int MaxPassengers;

//blank constructor
public CruiseShip()
{

}

//a construtor with all data for this class
public CruiseShip(String ShipName, String Year, int MaxPassengers)
{
super(ShipName, Year);//class the super class constructor for this data
this.MaxPassengers=MaxPassengers;
}

//set and get for the Passeneger feild
public void SetMaxPassengers(int MaxPassengers)
{
this.MaxPassengers = MaxPassengers;
}

public int GetMaxPassengers()
{
return this.MaxPassengers;
}

//tostring will override the toString in the Ship class
public String toString()
{
String strOut;
strOut = "Ship Name: " + GetShipName() + " Max Passenegers: " + GetMaxPassengers();
return strOut;
}
}

* CARGO
----------------------------------------------------------------
public class CargoShip extends Ship
{
//hold the tonnage the ship can hold
private int CargoCapcity;

//a blank constructor
public CargoShip()
{

}

//a constructor with all data needed for this class
public CargoShip(String ShipName, String Year, int CargoCapcity)
{
super(ShipName, Year);//send this data to the super class Ship
this.CargoCapcity = CargoCapcity;
}

//set and get for the tonnage
public void SetCargoCapcity(int CargoCapcity)
{
this.CargoCapcity = CargoCapcity;
}

public int GetCargoCapcity()
{
return this.CargoCapcity;
}

//toString overrides the superclass 'Ship' toString Method
public String toString()
{
String strOut;
strOut = "Ship Name: " + GetShipName() + " Cargo Capcity " + GetCargoCapcity()+" tons";
return strOut;
}
}


Again, thanks in advance for your time. Getting this all set would be a huge help!

Explanation / Answer

I added a label/text field and a couple radio buttons to your original GUI just so you can see how you can make them. You'll probably need to change the BorderLayout and/or make nested FlowLayouts in your code depending on what options you need your GUI to have. I just set it so you could actually see what the text field and radio buttons look like. Let me know if you need more help with any of your project or any explanations (preferably through messages because I'm not sure how to revise answers or anything here... you can also message me and make another question if you want) Hope this helps though :) import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout; import javax.swing.ButtonGroup; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenuBar; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JTextField; /* This will be the UI shell */ public class ShipGUI { public static void main(String[] args) { //Creates and set up the window JFrame frame = new JFrame("ShipGUI"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Creates the menu bar JMenuBar greenMenuBar = new JMenuBar(); greenMenuBar.setOpaque(true); greenMenuBar.setBackground(new Color(154, 165, 127)); greenMenuBar.setPreferredSize(new Dimension(200, 20)); //Creates a yellow label JLabel yellowLabel = new JLabel(); yellowLabel.setOpaque(true); yellowLabel.setBackground(new Color(248, 213, 131)); yellowLabel.setPreferredSize(new Dimension(200, 180)); //Set the menu bar and add the label to the content pane. frame.setJMenuBar(greenMenuBar); frame.getContentPane().add(yellowLabel, BorderLayout.CENTER); //make "Ship Name:" text label and corresponding text field JLabel nameLabel = new JLabel("Ship Name:"); JTextField name = new JTextField("", 4); //add label and field to window and use BorderLayout to assign location frame.add(nameLabel); frame.add(name, BorderLayout.EAST); //make a radio button JRadioButton shipType1 = new JRadioButton("Type 1"); JRadioButton shipType2 = new JRadioButton("Type 2"); ButtonGroup buttonGroup = new ButtonGroup(); buttonGroup.add(shipType1); buttonGroup.add(shipType2); JPanel panel = new JPanel(); panel.add(shipType1); panel.add(shipType2); //add the panel to the window frame.add(panel, BorderLayout.SOUTH); //Display the window. frame.pack(); frame.setVisible(true); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote