Object-Oriented Design and Network Programming Java Project Report
VerifiedAdded on  2023/05/30
|52
|5341
|240
Project
AI Summary
This Java project demonstrates object-oriented design and network programming concepts through several tasks. The first task involves creating a counter that calculates combinations of numbers summing to a given total, implemented in two parts with different combination sizes. The second task simulates traffic lights using Java Swing, allowing users to switch between red, yellow, and green lights via radio buttons. The third task draws Hilbert curves of varying orders using recursion and graphical components. The final task implements a client-server Morse code communication system, where the client sends text messages to the server, which then translates them into Morse code and displays the output. The client application also handles connection management and graceful termination. This assignment solution, available on Desklib, serves as a valuable resource for students seeking assistance with similar projects, providing a comprehensive understanding of Java programming, GUI development, and network communication.

Running head: Java Assignment Codes 1
Java Assignment Codes
Student Name
Institution
Location of Institution
Professor’s Name
Date
Java Assignment Codes
Student Name
Institution
Location of Institution
Professor’s Name
Date
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

Java Assignment Codes 2
Table of Contents
1.1 Question One Part One..............................................................................................................3
1.2 Question One Part Two.............................................................................................................7
1.3 Question Two...........................................................................................................................11
1.4 Question Three.........................................................................................................................19
1.4.1 Main Class........................................................................................................................19
1.4.2 Applet...............................................................................................................................27
1.5 Question Four..........................................................................................................................28
1.5.1 Morse Code Client............................................................................................................28
1.5.2 Morse Code Server...........................................................................................................44
Table of Contents
1.1 Question One Part One..............................................................................................................3
1.2 Question One Part Two.............................................................................................................7
1.3 Question Two...........................................................................................................................11
1.4 Question Three.........................................................................................................................19
1.4.1 Main Class........................................................................................................................19
1.4.2 Applet...............................................................................................................................27
1.5 Question Four..........................................................................................................................28
1.5.1 Morse Code Client............................................................................................................28
1.5.2 Morse Code Server...........................................................................................................44

Java Assignment Codes 3
1.1 Question One Part One
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package counter;
import java.util.ArrayList;
import java.util.Scanner;
/**
*
* @author Keeprawteach
*/
public class Counter {
/**
* @param args the command line arguments
*/
int k, m, counter, sum_counter;
1.1 Question One Part One
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package counter;
import java.util.ArrayList;
import java.util.Scanner;
/**
*
* @author Keeprawteach
*/
public class Counter {
/**
* @param args the command line arguments
*/
int k, m, counter, sum_counter;
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

Java Assignment Codes 4
public Counter() {
Scanner in = new Scanner(System.in);
System.out.println("Enter number: ");
int x = in.nextInt();
DoCalculations(x);
}
void DoCalculations(int n) {
System.out.println("Counter Sum Counter| n | m");
ArrayList<String> combs = new ArrayList<>();
counter = 0;
sum_counter = 0;
for (k = 1; k < n; k++) {
for (m = k + 1; m <= n; m++) {
counter++;
if ((k + m) == n) {
combs.add(k + " + " + m + " = " + n);
}
public Counter() {
Scanner in = new Scanner(System.in);
System.out.println("Enter number: ");
int x = in.nextInt();
DoCalculations(x);
}
void DoCalculations(int n) {
System.out.println("Counter Sum Counter| n | m");
ArrayList<String> combs = new ArrayList<>();
counter = 0;
sum_counter = 0;
for (k = 1; k < n; k++) {
for (m = k + 1; m <= n; m++) {
counter++;
if ((k + m) == n) {
combs.add(k + " + " + m + " = " + n);
}
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

Java Assignment Codes 5
if ((k + m) == n) {
sum_counter++;
System.out.println(" " + counter + " " + sum_counter + " " + k + "
" + m);
}else{
System.out.println(" " + counter + " " + k + " " + m);
}
}
}
System.out.println (
"\n\n");
System.out.println (
"Total Combinations: " + String.valueOf(combs.size()));
System.out.println (
"\n\nCombinations:\n");
if (!combs.isEmpty ()
if ((k + m) == n) {
sum_counter++;
System.out.println(" " + counter + " " + sum_counter + " " + k + "
" + m);
}else{
System.out.println(" " + counter + " " + k + " " + m);
}
}
}
System.out.println (
"\n\n");
System.out.println (
"Total Combinations: " + String.valueOf(combs.size()));
System.out.println (
"\n\nCombinations:\n");
if (!combs.isEmpty ()

Java Assignment Codes 6
) {
for (String comb : combs) {
System.out.println(comb);
}
}
}
public static void main(String[] args) {
// TODO code application logic here
new Counter();
}
}
) {
for (String comb : combs) {
System.out.println(comb);
}
}
}
public static void main(String[] args) {
// TODO code application logic here
new Counter();
}
}
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

Java Assignment Codes 7
1.2 Question One Part Two
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package counter.part.two;
import java.util.ArrayList;
import java.util.Scanner;
/**
*
* @author Keeprawteach
*/
public class CounterPartTwo {
/**
* @param args the command line arguments
*/
int a, b, c, d, e, f, counter, sum_counter;
1.2 Question One Part Two
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package counter.part.two;
import java.util.ArrayList;
import java.util.Scanner;
/**
*
* @author Keeprawteach
*/
public class CounterPartTwo {
/**
* @param args the command line arguments
*/
int a, b, c, d, e, f, counter, sum_counter;
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

Java Assignment Codes 8
public CounterPartTwo() {
Scanner in = new Scanner(System.in);
System.out.println("Enter number: ");
int x = in.nextInt();
DoCalculations(x);
}
public static void main(String[] args) {
// TODO code application logic here
new CounterPartTwo();
}
private void DoCalculations(int n) {
System.out.println("Counter | Sum Counter | a | b | c | d | e | f ");
ArrayList<String> combs = new ArrayList<>();
counter = 0;
sum_counter = 0;
for (a = 1; a < n; a++) {
for (b = a + 1; b <= n; b++) {
public CounterPartTwo() {
Scanner in = new Scanner(System.in);
System.out.println("Enter number: ");
int x = in.nextInt();
DoCalculations(x);
}
public static void main(String[] args) {
// TODO code application logic here
new CounterPartTwo();
}
private void DoCalculations(int n) {
System.out.println("Counter | Sum Counter | a | b | c | d | e | f ");
ArrayList<String> combs = new ArrayList<>();
counter = 0;
sum_counter = 0;
for (a = 1; a < n; a++) {
for (b = a + 1; b <= n; b++) {

Java Assignment Codes 9
for (c = b + 1; b <= n; b++) {
for (d = c + 1; b <= n; b++) {
for (e = d + 1; b <= n; b++) {
for (f = e + 1; b <= n; b++) {
counter++;
if ((a + b + c + d + e + f) == n) {
combs.add(a + " + " + b + " + " + c + " + " + d + " + " + e + " + " + f + " =
" + n);
}
if ((a + b + c + d + e + f) == n) {
sum_counter++;
System.out.println(counter +" "+sum_counter+" "+a+" "+b+"
"+c+" "+d+" "+e+" "+f );
} else {
System.out.println(counter +" "+a+" "+b+" "+c+" "+d+"
"+e+" "+f );
}
}
}
for (c = b + 1; b <= n; b++) {
for (d = c + 1; b <= n; b++) {
for (e = d + 1; b <= n; b++) {
for (f = e + 1; b <= n; b++) {
counter++;
if ((a + b + c + d + e + f) == n) {
combs.add(a + " + " + b + " + " + c + " + " + d + " + " + e + " + " + f + " =
" + n);
}
if ((a + b + c + d + e + f) == n) {
sum_counter++;
System.out.println(counter +" "+sum_counter+" "+a+" "+b+"
"+c+" "+d+" "+e+" "+f );
} else {
System.out.println(counter +" "+a+" "+b+" "+c+" "+d+"
"+e+" "+f );
}
}
}
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

Java Assignment Codes 10
}
}
}
}
System.out.println("\n\n");
System.out.println("Total Combinations: " + String.valueOf(combs.size()));
System.out.println("\n\nCombinations:\n");
if (!combs.isEmpty()) {
for (String comb : combs) {
System.out.println(comb);
}
}
}
}
}
}
}
}
System.out.println("\n\n");
System.out.println("Total Combinations: " + String.valueOf(combs.size()));
System.out.println("\n\nCombinations:\n");
if (!combs.isEmpty()) {
for (String comb : combs) {
System.out.println(comb);
}
}
}
}
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

Java Assignment Codes 11
1.3 Question Two
package traffic.lights;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
public class TrafficLights extends JFrame implements ItemListener{
/**
*
*/
private static final long serial_number_version = 1L;
1.3 Question Two
package traffic.lights;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
public class TrafficLights extends JFrame implements ItemListener{
/**
*
*/
private static final long serial_number_version = 1L;

Java Assignment Codes 12
//Create buttons for traffic Lights_of_Traffics
private JRadioButton Red_Radio_Button;
private JRadioButton Yellow_Radio_Button;
private JRadioButton Green_Radio_Button;
private ButtonGroup Overal_Radio_Button = new ButtonGroup();
//create class Lights_of_Traffics
private TrafficLights.Light Lights_of_Traffics = new TrafficLights.Light();
public static void main(String[] args)
{
//Create frame
TrafficLights frame = new TrafficLights();
frame.setDefaultCloseOperation(3);
frame.setSize(400, 170);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public TrafficLights()
{
//Create buttons for traffic Lights_of_Traffics
private JRadioButton Red_Radio_Button;
private JRadioButton Yellow_Radio_Button;
private JRadioButton Green_Radio_Button;
private ButtonGroup Overal_Radio_Button = new ButtonGroup();
//create class Lights_of_Traffics
private TrafficLights.Light Lights_of_Traffics = new TrafficLights.Light();
public static void main(String[] args)
{
//Create frame
TrafficLights frame = new TrafficLights();
frame.setDefaultCloseOperation(3);
frame.setSize(400, 170);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public TrafficLights()
{
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide
1 out of 52
Related Documents
Your All-in-One AI-Powered Toolkit for Academic Success.
 +13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
Copyright © 2020–2025 A2Z Services. All Rights Reserved. Developed and managed by ZUCOL.




