Course,java
import java.util.ArrayList;
import java.util.Arrays;
/*
* 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.
*/
/**
*
* @author fenghui
*/
public class Course {
private String cName;
private ArrayList<Subject> cores;
private ArrayList<Major> majors;
private ArrayList<Subject> electives;
private int cCredit;
public Course(String n, int cc){
cName = n;
cCredit = cc;
cores = new ArrayList<Subject>(0);
majors = new ArrayList<Major>(0);
electives = new ArrayList<Subject>(0);
}
public void addCores(Subject[] co){
cores.addAll(Arrays.asList(co));
}
public void addMajors(Major[] ma){
majors.addAll(Arrays.asList(ma));
}
public void addElectives(Subject[] el){
electives.addAll(Arrays.asList(el));
}
public ArrayList<Subject> getCores(){
return cores;
}
public ArrayList<Subject> getElectives(){
return electives;
}
public String toString(){
String s="Course: ";
s+=cName+"\n\n";
s+="Cores: \n";
for(Subject su:cores)
s+=su;
s+="\n";
for(Major m:majors)
s+=m;
s+="Electives: \n";
for(Subject su:electives)
s+=su;
return s;
}
public String getCName(){
return cName;
}
public ArrayList<Major> getMajors(){
return majors;
}
public int getCCredit(){
return cCredit;
}
}
Subject,java
/*
* 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.
*/
/**
*
* @author fenghui
*/
public class Subject implements Cloneable{
private String sName, code;
private int credit;
public Subject(String co, String name, int cr){
sName = name;
code = co;
credit = cr;
}
public int getCredit(){
return credit;
}
@Override
public String toString(){
return code+" ("+sName+", "+credit+"pt)\n";
}
public String getCode(){
return code;
}
public boolean isSame(Subject s){
if(s.getCode().equals(code))
return true;
else
return false;
}
@Override
public Subject clone() throws CloneNotSupportedException {
return (Subject) super.clone();
}
}
Major.java
import java.util.ArrayList;
import java.util.Arrays;
public class Major implements Cloneable{
private String mName;
private ArrayList<Subject> mCores;
public Major(){
this("No Major");
}
public Major(String n){
mName = n;
mCores = new ArrayList<Subject>(0);
}
public void addMCores(Subject[] cores){
mCores.addAll(Arrays.asList(cores));
}
public ArrayList<Subject> getMCores(){
return mCores;
}
@Override
public String toString(){
String s="";
s+=mName+" Major\n";
for(Subject sub:mCores)
s+= sub;
s+="\n";
return s;
}
public String getMName(){
return mName;
}
public boolean isIncluded(Subject s){
boolean b = false;
for(Subject mc: mCores)
b=b||mc.isSame(s);
//System.out.println(mName+" includes "+ s.getCode()+": "+b);
return b;
}
@Override
public Major clone() throws CloneNotSupportedException {
Major major = (Major) super.clone();
major.mCores = (ArrayList<Subject>) mCores.clone();
return major; //To change body of generated methods, choose Tools | Templates.
}
}
Java code and screen short of output shown below
Course.java
import java.util.ArrayList;
import java.util.Arrays;
/*
* 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.
*/
/**
*
* @author fenghui
*/
import java.io.*;
public class Course implements Serializable{
private String cName;
private ArrayList<Subject> cores;
private ArrayList<Major> majors;
private ArrayList<Subject> electives;
private int cCredit;
public Course(String n, int cc){
cName = n;
cCredit = cc;
cores = new ArrayList<Subject>(0);
majors = new ArrayList<Major>(0);
electives = new ArrayList<Subject>(0);
}
public void addCores(Subject[] co){
cores.addAll(Arrays.asList(co));
}
public void addMajors(Major[] ma){
majors.addAll(Arrays.asList(ma));
}
public void addElectives(Subject[] el){
electives.addAll(Arrays.asList(el));
}
public ArrayList<Subject> getCores(){
return cores;
}
public ArrayList<Subject> getElectives(){
return electives;
}
public String toString(){
String s="Course: ";
s+=cName+"\n\n";
s+="Cores: \n";
for(Subject su:cores)
s+=su;
s+="\n Major:\n";
for(Major m:majors)
s+=m;
s+="\nElectives: \n";
for(Subject su:electives)
s+=su;
return s;
}
public String getCName(){
return cName;
}
public ArrayList<Major> getMajors(){
return majors;
}
public int getCCredit(){
return cCredit;
}
}
Subect.java
/*
* 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.
*/
/**
*
* @author fenghui
*/
import java.io.*;
public class Subject implements
Cloneable,Serializable{
private String sName, code;
private int credit;
public Subject(String co, String name, int cr){
sName = name;
code = co;
credit = cr;
}
public int getCredit(){
return credit;
}
@Override
public String toString(){
return code+" ("+sName+", "+credit+"pt)\n";
}
public String getCode(){
return code;
}
public boolean isSame(Subject s){
if(s.getCode().equals(code))
return true;
else
return false;
}
@Override
public Subject clone() throws CloneNotSupportedException {
return (Subject) super.clone();
}
}
Major.java
import java.util.ArrayList;
import java.util.Arrays;
import java.io.*;
public class Major implements Cloneable,Serializable{
private String mName;
private ArrayList<Subject> mCores;
public Major(){
this("No Major");
}
public Major(String n){
mName = n;
mCores = new ArrayList<Subject>(0);
}
public void addMCores(Subject[] cores){
mCores.addAll(Arrays.asList(cores));
}
public ArrayList<Subject> getMCores(){
return mCores;
}
@Override
public String toString(){
String s="";
s+=mName+" \n";
for(Subject sub:mCores)
s+= sub;
s+="\n";
return s;
}
public String getMName(){
return mName;
}
public boolean isIncluded(Subject s){
boolean b = false;
for(Subject mc: mCores)
b=b||mc.isSame(s);
//System.out.println(mName+" includes "+ s.getCode()+": "+b);
return b;
}
@Override
public Major clone() throws CloneNotSupportedException {
Major major = (Major) super.clone();
major.mCores = (ArrayList<Subject>) mCores.clone();
return major; //To change body of generated methods, choose Tools | Templates.
}
}
Student.java
public class Student {
private String stName, gender, DOB;
private int stNum;
public Student(String name, int num, String g, String dob){
stName=name;
stNum=num;
gender=g;
DOB=dob;}
public String toString(){
return "Student: "+stName+" ("+stNum+", "+gender+", "+DOB+") \n";}}
CreateCourse.java
import java.io.*;
import java.util.ArrayList;
public class CreateCourse
{
public static void main(String[] args)
{
//same subject,major and elective in both courses
Subject[] obj1 = new Subject[2] ;
obj1[0] = new Subject("001","Artificial Intelligence",10); //for
core subject
obj1[1] = new Subject("001","Data Structure",10); //for elective
Major[] obj2 = new Major[2] ;
obj2[0]=new Major("Robotics");
obj2[1]=new Major("Programming");
Course object1 = new Course("Bachelor of Computer Science",
5);
object1.addCores(obj1);
object1.addMajors(obj2);
object1.addElectives(obj1);
Course object2 = new Course("Master of Computer Science", 5);
object2.addCores(obj1);
object2.addMajors(obj2);
object2.addElectives(obj1);
String filename1 = "bcs.ser";
String filename2 = "mcs.ser";
// Serialization
try {
// Saving of object in a file
FileOutputStream file1 = new FileOutputStream
(filename1);
ObjectOutputStream out1 = new ObjectOutputStream
(file1);
FileOutputStream file2 = new FileOutputStream
(filename2);
ObjectOutputStream out2 = new ObjectOutputStream
(file2);
// Method for serialization of object
out1.writeObject(object1);
out2.writeObject(object2);
out1.close();
file1.close();
out2.close();
file2.close();
System.out.println("Object has been serialized\n"
+ object1);
System.out.println("Object has been serialized\n"
+ object2);
}
catch (IOException ex) {
System.out.println("IOException is caught");
}
}
}
output
Object has been serialized
Course: Bachelor of Computer Science
Cores:
001 (Artificial Intelligence, 10pt)
001 (Data Structure, 10pt)
Major:
Robotics
Programming
Electives:
001 (Artificial Intelligence, 10pt)
001 (Data Structure, 10pt)
Object has been serialized
Course: Master of Computer Science
Cores:
001 (Artificial Intelligence, 10pt)
001 (Data Structure, 10pt)
Major:
Robotics
Programming
Electives:
001 (Artificial Intelligence, 10pt)
001 (Data Structure, 10pt)
Course,java import java.util.ArrayList; import java.util.Arrays; /* * To change this license header, choose License Headers in...
/* * 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 checkingaccounttest; // Chapter 9 Part II Solution public class CheckingAccountTest { public static void main(String[] args) { CheckingAccount c1 = new CheckingAccount(879101,3000); c1.deposit(350); c1.deposit(220); c1.withdraw(100); c1.deposit(1100); c1.deposit(700); c1.withdraw(350); c1.withdraw(220); c1.withdraw(100); c1.deposit(1100); c1.deposit(700); c1.deposit(1000); System.out.println(c1); System.out.println("After calling computeMonthlyFee()"); c1.computeMonthlyFee(); System.out.println(c1); } } class BankAccount { private int...
Java help! Please help complete the min method below in bold. import java.util.Arrays; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; /** * Provides an implementation of a binary search tree * with no balance constraints, implemented with linked nodes. * * * */ public class Bst<T extends Comparable<T>> implements Iterable<T> { ////////////////////////////////////////////////////////////////// // I M P L E M E N T T H E M I N M E T H O D B E L O W...
Language is Java, any help is appreciated. Thank you! WHERE TO START FROM: import java.util.ArrayList; //PartTest.java //package simple; public class PartTest { public static void main(String[] args) { ArrayList<ExpendablePart> system=new ArrayList<ExpendablePart>(); // creating Part Object Part part1 = new ExpendablePart("Last, First"); part1.setNumber("AX-34R"); part1.setNcage("MN34R"); part1.setNiin("ABCD-RF-WDE-KLJM"); // printing information System.out.println(part1.toString()); //Create a part2 object of class Part Part part2=new ConsumablePart("Widget, purple"); part2.setNumber("12345"); part2.setNcage("OU812"); part2.setNiin("1234-12-123-1234"); // printing information System.out.println(part2.toString()); //checking equality of two Part class objects if(part1.equals(part2)) System.out.println("part1 and...
JAVA programming 9.9 Ch 9, Part 2: ArrayList Searching import java.util.ArrayList; public class ArrayListSet { /** * Searches through the ArrayList arr, from the first index to the last, returning an ArrayList * containing all the indexes of Strings in arr that match String s. For this method, two Strings, * p and q, match when p.equals(q) returns true or if both of the compared references are null. * * @param s The string...
Cant figure out how to fix error Code- import java.io.File; import java.io.IOException; import java.util.*; public class Program8 { public static void main(String[] args)throws IOException{ File prg8 = new File("program8.txt"); Scanner reader = new Scanner(prg8); String cName = ""; int cID = 0; double bill = 0.0; String email = ""; double nExempt = 0.0; String tExempt = ""; int x = 0; int j = 1; while(reader.hasNextInt()) { x = reader.nextInt();} Customers c1 [] = new Customers [x]; for (int...
How to solve and code the following requirements (below) using the JAVA program? 1. Modify the FoodProduct Class to implement Edible, add the @Overrride before any methods that were there (get/set methods) that are also in the Edible interface. 2. Modify the CleaningProduct Class to implement Chemical, add the @Overrride before any methods that were there (get/set methods) that are also in the Chemical interface. 3. Create main class to read products from a file, instantiate them, load them into...
PLEASE COMPLETE THE CODES. package javaprogram; import java.io.PrintStream; import java.util.ArrayList; import java.util.Scanner; /** * Movie class definition. * * @author David Brown * @version 2019-01-22 */ public class Movie implements Comparable { // Constants public static final int FIRST_YEAR = 1888; public static final String[] GENRES = { "science fiction", "fantasy", "drama", "romance", "comedy", "zombie", "action", "historical", "horror", "war" }; public static final int MAX_RATING = 10; public static final int MIN_RATING = 0; /** * Converts a string of...
/** * */ package groceries; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class ShoppingList { /** * @param args */ public static void main(String[] args) { List groceryList = new ArrayList<>(); groceryList.add("rice"); groceryList.add("chicken"); groceryList.add("cumin"); groceryList.add("tomato"); groceryList.add("cilantro"); groceryList.add("lime juice"); groceryList.add("peppers"); groceryList.remove("cilantro"); for (int i = 0; i if (groceryList.get(i).equals("peppers")) {...
complete this in java import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class WordDetective { /** * Finds the specified set of words in the specified file and returns them * as an ArrayList. This finds the specified set in the file which is on the * line number of the set. The first line and set in the file is 1. * * This returns an ArrayList with the keyword first, then : and then followed...
public class Scheduler { private List<Course> classes; private List<Student> students; public Scheduler() { classes = new ArrayList<Course>(); students = new ArrayList<Student>(); } public void addCourse(Course course) { this.classes.add(course); } public List<Course> getCourses() { List<Course> newCList=new ArrayList<>(); for(int i=0;i<classes.size();i++){ newCList.add(classes.get(i)); } return newCList; } public void addStudent(Student student) { this.students.add(student); } ...