Answer For PART1:
import java.io.*;
import javax.print.DocFlavor.STRING;
class Route {
Airport departure;
Airport destination;
public void setDeparture(Airport departure)
{
this.departure =
departure;
}
public void setDestination(Airport
destination) {
this.destination =
destination;
}
public Airport getDeparture() {
return departure;
}
public Airport getDestination() {
return
destination;
}
public Route(Airport departure, Airport
destination) {
setDeparture(departure);
setDestination(destination);
}
}
class Date {
int day;
int month;
int year;
public void setDay(int day) {
if (day <= 31
&& day > 0) {
this.day = day;
} else {
System.out.println("Invalid Day");
}
}
public void setMonth(int month) {
if (month <= 12
&& month > 0) {
this.month = month;
} else {
System.out.println("Invalid Month");
}
}
public void setYear(int year) {
if (year > 2020
&& year < 2025) {
this.year = year;
} else {
System.out.println("Invalid Year");
}
}
public int getDay() {
return day;
}
public int getMonth() {
return month;
}
public int getYear() {
return year;
}
public Date(int day, int month, int year)
{
setDay(day);
setMonth(month);
setYear(year);
}
}
class ClockTime {
int hour;
int minute;
public void setHour(int hour) {
if (hour <= 23
&& hour >= 0) {
this.hour = hour;
} else {
System.out.println("Invalid Hour");
}
}
public void setMinute(int minute) {
if (minute <= 59
&& minute >= 0) {
this.minute = minute;
} else {
System.out.println("Invalid Minute");
}
}
public ClockTime(int hour, int minute)
{
setHour(hour);
setMinute(minute);
}
}
class Time {
Date date;
ClockTime clocktime;
public void setClocktime(ClockTime clocktime)
{
this.clocktime =
clocktime;
}
public void setDate(Date date) {
this.date = date;
}
public ClockTime getClocktime() {
return clocktime;
}
public Date getDate() {
return date;
}
public Time(Date date, ClockTime clocktime)
{
setClocktime(clocktime);
setDate(date);
}
}
class Ticket {
Route route;
Time departureTime;
Time arrivalTime;
public void setRoute(Route route) {
this.route =
route;
}
public void setDepartureTime(Time
departureTime) {
this.departureTime =
departureTime;
}
public void setArrivalTime(Time arrivalTime)
{
this.arrivalTime =
arrivalTime;
}
public Route getRoute() {
return route;
}
public Time getDepartureTime() {
return
departureTime;
}
public Time getArrivalTime() {
return
arrivalTime;
}
public Ticket(Route route,Time
departureTime,Time arrivalTime){
setRoute(route);
setDepartureTime(departureTime);
setDepartureTime(departureTime);
}
}
public class Airport {
String name;
String city;
String country;
public void setName(String name) {
this.name = name;
}
public void setCity(String city) {
this.city = city;
}
public void setCountry(String country)
{
this.country =
country;
}
public String getCity() {
return city;
}
public String getCountry() {
return country;
}
public String getName() {
return name;
}
public Airport(String name, String city,
String country) {
setName(name);
setCity(city);
setCountry(country);
}
public static void main(String[] args)
{
Airport port1=new
Airport("ABC Airport", "ABC", "CountryABC");
Airport port2=new
Airport("DEF Airport", "DEF", "CountryDEF");
Airport port3=new
Airport("GHI Airport", "GHI", "CountryGHI");
Date day1=new Date(4, 6,
2021);
Date day2=new Date(5, 6,
2021);
Date day3=new Date(5, 6,
2021);
ClockTime ti1=new
ClockTime(5, 20);
ClockTime ti2=new
ClockTime(9, 40);
ClockTime ti3=new
ClockTime(23, 59);
Time time1= new
Time(day1, ti1);
Time time2= new
Time(day2, ti2);
Time time3= new
Time(day3, ti3);
Route rt1= new
Route(port1, port2);
Route rt2= new
Route(port2, port3);
Route rt3= new
Route(port3, port1);
Ticket t1=new
Ticket(rt1, time1, time2);//instance 1
Ticket t2=new
Ticket(rt2, time2, time3);//instance 2
Ticket t3=new
Ticket(rt3, time3, time1);//instance 3
}
}
PART2:
public class transpose2dmatrix {
public static int[][] transpose(int[][]
matrix) {
int transp[][] = new
int[3][3];
for (int i = 0; i <
3; i++) {
for (int j = 0; j < 3; j++) {
transp[i][j] = matrix[j][i];
}
}
return transp;
}
public static void main(String[] args)
{
int matrix[][] = { { 1,
2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
int transposed[][] =
transpose(matrix);
System.out.println("Matrix before Transpose:");
for (int i = 0; i <
3; i++) {
for (int j = 0; j < 3; j++) {
System.out.print(matrix[i][j] + " ");
}
System.out.println();
}
System.out.println("Matrix After Transpose:");
for (int i = 0; i <
3; i++) {
for (int j = 0; j < 3; j++) {
System.out.print(transposed[i][j] + " ");
}
System.out.println();
}
}
}
OUTPUT:
Matrix before Transpose:
1 2 3
4 5 6
7 8 9
Matrix After Transpose:
1 4 7
2 5 8
3 6 9
java with Part 1 Write the Java classes given with their fields. Implement their constructors, toString...
Design and implement a C++ class called Date that has the following private member variables month (int) day (nt) . year (int Add the following public member functions to the class. Default Constructor with all default parameters: The constructors should use the values of the month, day, and year arguments passed by the client program to set the month, day, and year member variables. The constructor should check if the values of the parameters are valid (that is day is...
JAVA. Create an application that uses a "PriorityQueue" to perform the following Uses the constructor that receives a "Comparator" object as an argument Stores 5 "Time1" objects using the "Time1" class shown in Fig. 8.1 on page 331. The class must be modified to implement the "Comparator" interface Displays the "Universal Time" in priority order Note: To determine the ordering when implementing the "Comparator" interface, convert the time into seconds (i.e., hours * 3600 + minutes * 60 + seconds),...
Use Java and creat proper classes to finish this problem Write a class called Date that represents a date consisting of a year, month, and day. A Date object should have the following methods: public Date(int year, int month, int day) Constructs a new Date object to represent the given date. public void addDays(int days) Moves this Date object forward in time by the given number of days. public void addWeeks(int weeks) Moves this Date object forward in time by...
This is assignment and code from this site but it will not compile....can you help? home / study / engineering / computer science / computer science questions and answers / c++ this assignment requires several classes which interact with each other. two class aggregations ... Question: C++ This assignment requires several classes which interact with each other. Two class aggregatio... (1 bookmark) C++ This assignment requires several classes which interact with each other. Two class aggregations are formed. The program...
Need help with a few questions! Using the JAVA language please. 1) exercises - branching Write a method whatToWear(int temp) that takes a temperature and then outputs a string for what to wear in different weather conditions. There must be at least 3 categories. For example, whatToWear(90) might return “shorts” and whatToWear(30) might return “down coat” 2) Enum exercise • Define an enum Seasons, and rewrite the whatToWear method to use enums and switch statement 8) 2D array exercise 1....
This is for my c++ class and im stuck. Complete the Multiplex.cpp file with definitions for a function and three overloaded operators. You don't need to change anything in the Multiplex.h file or the main.cpp, though if you want to change the names of the movies or concession stands set up in main, that's fine. Project Description: A Multiplex is a complex with multiple movie theater screens and a variety of concession stands. It includes two vectors: screenings holds pointers...
java questions: 1. Explain the difference between a deep and a shallow copy. 2. Given the below classes: public class Date { private String month; private String day; private String year; public Date(String month, String day, String year) { this.month = month; this.day = day; this.year = year; } public String getMonth() { return month; } public String getDay() { return day; } public String...
PART 1: GETTING STARTED 1. Create a new Java Project. 2. Create a new Tree class and enter this code. You do not have to type in the comments public class Tree { private String name; private int age; private bogJsAn evergreen; // true if evergreen // false if deciduous //CONSTRUCTORS public Tree( { name 0; evergreen = true; age } // you fill this one public Tree (String n, jnt a, bgalean e) //PUT YOUR CODE HERE } //...
The following is for java programming. the classes money date and array list are so I are are pre made to help with the coding so you can resuse them where applicable Question 3. (10 marks) Here are three incomplete Java classes that model students, staff, and faculty members at a university class Student [ private String lastName; private String firstName; private Address address; private String degreeProgram; private IDNumber studentNumber; // Constructors and methods omitted. class Staff private String lastName;...
Please help with Java programming! This code is to implement a Clock class. Use my beginning code below to test your implementation. public class Clock { // Declare your fields here /** * The constructor builds a Clock object and sets time to 00:00 * and the alarm to 00:00, also. * */ public Clock() { setHr(0); setMin(0); setAlarmHr(0); setAlarmMin(0); } /** * setHr() will validate and set the value of the hr field * for the clock. * *...