VU CS506 Assignment 1 Solution File free
Virtual University Pakistan CS506 Assignment 1 solution file spring 2023 free download. To get 100% marks follow our guide.
Instructions From VU
Write a program in java which will have two classes i.e., Vehicle and Asssignment1 class. Vehicle class will have three data members (name, price, model), a default constructor, a parameterized constructor, setter and getter functions and a display () function. Assignment1 class will contains main method.
In main method you are required to create two objects of vehicle class by giving parameters for name, price and model. Create first object using parameterized constructor and second object by using default constructor & setter functions. After creating these objects store both objects in the ArrayList then print your student id and ArrayList objects data on console using for loop and display() function of Vehicle class.
Details: (Assignment1.java file contains)
- Vehicle class
Data Members: name, price, model
Default Constructor: Vehicle
Parametrized Constructor: Vehicle (name, price, model)
Setter Functions: setName(…), setPrice(…), setModel(…)
Getter Functions: getName(), getPrice(), getModel()
Display Function: display()
- Assignment1 class
Main Method: public String void main(String args[])
Output of the Program: (Data is just a demo you will input your own data for creating objects)
Code for CS506 Assignment 1 Solution
Code Version 2 for CS506 Assignment 1 Solution
To get 100% marks in CS506 Assignment 1 2023, make a file named “Assignment1.java” edit with any text editor and copy the above code or below and paste into the file save the file. To verify this code whether it’s working or not just copy the code and paste into this website Jdoodle
CS506 Assignment 1 Solution Spring 2023
It’s the modified code no.2 for CS506 Assignment 1 Spring 2023.
import java.util.ArrayList;
class Vehicle {
String name;
double price;
int model;
// Default constructor
public Vehicle() {
}
// Parameterized constructor
public Vehicle(String cy, double rs, int ml) {
this.name = cy;
this.price = rs;
this.model = ml;
}
// Setter functions
public void setName(String c) {
this.name = c;
}
public void setPrice(double rs) {
this.price = rs;
}
public void setModel(int ml) {
this.model = ml;
}
// Getter functions
public String getName() {
return name;
}
public double getPrice() {
return price;
}
public int getModel() {
return model;
}
// Display function
public void display() {
System.out.println("Name: " + name);
System.out.println("Price: " + price);
System.out.println("Model: " + model);
}
}
public class Assignment1 {
public static void main(String[] args) {
ArrayList<Vehicle> vehicleList = new ArrayList<>();
// Create first object using parameterized constructor
Vehicle vehicle1 = new Vehicle("GLI 2D", 3350000.0, 2020);
vehicleList.add(vehicle1);
// Create second object using default constructor and setter functions
Vehicle vehicle2 = new Vehicle();
vehicle2.setName("Mehran 2018");
vehicle2.setPrice(900000.0);
vehicle2.setModel(2018);
vehicleList.add(vehicle2);
// Print student ID
System.out.println("Student ID: yourid");
// Print data of ArrayList objects using for loop and display() function
for (Vehicle vehicle : vehicleList) {
vehicle.display();
System.out.println();
}
}
}
Modification and Submission Guide
Remember to put your own student id in “yourid” . Don’t Just copy paste made some changes in Parameterized constructor and Setter functions. For example i have change price to c , model to ml you can change also. Bookmark our website Gadget Gazette by pressing CTRL+D to get more solutions for free or comment below to get free soultion files. Only upload Assignment1.java file, don’t upload txt, zip, pdf or .docx file. File name should be exact “Assignment1.java” otherwise you will get zero marks. Remember these below guidelines from VU also.
Instructions:
Please read the following instructions carefully before submitting assignment. It should be clear that your assignment will not get any credit if:
- The assignment is submitted after due date.
- The submitted assignment does not open or file is corrupt.
- Assignment is copied (partial or full) from any source (websites, forums, students, etc.) Strict action will be taken in this regard.
- The assignment submission format is other than .java file.
- Use Notepad or Notepad++ for coding and JDK package for java source code compilation and running.
- Submit a single Assignment1.java file including both classes(Vehicle and Assignment1) in one file (No multiple or zip files allowed).
Code Example 3
It’s the modified code no.3 for CS506 Assignment 1 Spring 2023.
Code Example 4
Download Solution files for CS506 Assigment 1 spring 2023
Click Here to download the solution files for CS506 Assigment 1 2023 spring. Solution file are in a zip file so check the file format before going to other website. We don’t upload files on other websites except Google Drive. You can download all files directly from this website.
Download the solution files from here.