Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3623954
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:26:50+00:00 2026-05-18T23:26:50+00:00

my dear Friends I am new to this java ..so plz help me thank

  • 0

my dear Friends I am new to this java ..so plz help me thank u in advance.. Now i am workin on an examples to understand the concepts of java’s objects, classes method in detail.
With all the knowledge i have i tried this example. . but i am unable to accomplish the task.. . Can any one plz give me suggestions of corrected coding..

I also wanted to know Which s the best site for learning JAVA (like MSDN for .NET )
Thank u in advance

Question:To Create Vehicle having following attributes: Vehicle No., Model, Manufacturer and Color. Create truck which has the following additional attributes: loading capacity( 100 tons…).Add a behavior to change the color and loading capacity. Display the updated truck details.

Codings:

import java.io.*;

class Vehicle
{
    String VehicleNo;
    String Model;
    String Manufacturer;
    String Color;


    public void setNo(String VehicleNo)
    {
    this.VehicleNo=VehicleNo;
    }

    public String getNo()
    {
    return VehicleNo;
    }


    public void setModel(String Model)
    {
    this.Model=Model;
    }

    public String getModel()
    {
    return Model;
    }

    public void setManufacturer(String Manufacturer)
    {
    this.Manufacturer=Manufacturer;
    }

    public String getManufacturer()
    {
    return Manufacturer;
    }



    public void setColor(String Color)

    {
    this.Color=Color;
    }

    public String getColor(String s)
    {
    return s;
    }

}


class Truck extends Vehicle

{

    double LoadingCapacity;

    public void setLoad(double LoadingCapacity)
    {
    this.LoadingCapacity=LoadingCapacity;
    }


    public double getLoad(double ld)
    {
    return ld;
    }
}

public class VehicleInfo {

    /**
     * @param args
     * @throws IOException 
     */
    public static void mainEntry2() throws IOException
    {   
        //Truck D=new Truck();
        //BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.print("Color: ");
        String col=br.readLine();
        D.setColor(col);

        System.out.print("Enter Loading Capacity: Maximum 100tons");
        int load=Integer.parseInt(br.readLine());
        D.setLoad(load);
    }
    public static void main(String[] args) throws IOException 
        {
            int loop_option=0;
            public Truck D=new Truck();
            public BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            System.out.print("Vehicle No: ");
            String no=br.readLine();
            D.setNo(no);

            System.out.print("Model: ");
            String model=br.readLine();
            D.setModel(model);

            System.out.print("Manufacturer: ");
            String man=br.readLine();
            D.setManufacturer(man);

mainEntry2();
            do
            {
                System.out.println("");

                System.out.println("----Vehicle Information----");
                System.out.println();
                System.out.println("Vehicle No: "+D.getNo());
                System.out.println("Model: "+D.getModel());
                System.out.println("Manufacturer: "+D.getManufacturer());
                System.out.println("Color: "+D.getColor(col));
                System.out.println("Loading Capacity: "+D.getLoad(load));
                System.out.println("");
                System.out.println(" if U want to update color and loading capacity press 1 and to exit press 2 ..");
                loop_option=Integer.parseInt(br.readLine());
                if(loop_option==1)
                {
                    mainEntry2();
                }

            }while(loop_option==1);

        }

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T23:26:51+00:00Added an answer on May 18, 2026 at 11:26 pm

    Here are some general remarks. Hope they help:

    1. getters should only return value, they do not have parameters (otherwise they are not getters).
    2. if you’re encapsulating fields, make them private
    3. use descriptive variable names (eg. truck instead of D)
    4. use descriptive method names (mainEntry2() tells absolutely nothing)
    5. if you’re parsing integer from user input, handle parsing exceptions (like NumberFormatException)

    For instance, your program may be re-written like here:

    import java.io.*;
    
    class Vehicle {
        private String vehicleNo;
        private String model;
        private String manufacturer;
        private String color;
    
        public void setNo(String vehicleNo) {
            this.vehicleNo = vehicleNo;
        }
    
        public String getNo() {
            return vehicleNo;
        }
    
        public void setModel(String model) {
            this.model = model;
        }
    
        public String getModel() {
            return model;
        }
    
        public void setManufacturer(String manufacturer) {
            this.manufacturer = manufacturer;
        }
    
        public String getManufacturer() {
            return manufacturer;
        }
    
        public void setColor(String color)
        {
            this.color = color;
        }
    
        public String getColor() {
            return color;
        }
    
    }
    
    class Truck extends Vehicle
    {
        private double loadingCapacity;
    
        public void setLoad(double loadingCapacity) {
            this.loadingCapacity = loadingCapacity;
        }
    
        public double getLoad() {
            return this.loadingCapacity;
        }
    
    }
    
    public class VehicleInfo {
    
        private static void updateColorAndCapacity(BufferedReader br, Truck truck)
            throws IOException
        {
            System.out.print("Color: ");
            String col = br.readLine();
            truck.setColor(col);
    
            while (true)
            {
                System.out.print("Enter Loading Capacity (maximum 100tons):");
                String value = br.readLine();
                value = value.trim();
                try {
                    int load = Integer.parseInt(value);
                    truck.setLoad(load);
                    return;
                } catch (NumberFormatException e) {
                    /// do it once again
                    continue;
                }
            }
        }
    
        public static void main(String[] args) 
            throws IOException {
    
            Truck truck = new Truck();
    
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
            System.out.print("Vehicle No: ");
            String no = br.readLine();
            truck.setNo(no);
    
            System.out.print("Model: ");
            String model = br.readLine();
            truck.setModel(model);
    
            System.out.print("Manufacturer: ");
            String man = br.readLine();
            truck.setManufacturer(man);
    
            updateColorAndCapacity(br, truck);
    
            int loop_option = 0;        
            do {
                System.out.println();
                System.out.println("----Vehicle Information----");
                System.out.println();
                System.out.println("Vehicle No: " + truck.getNo());
                System.out.println("Model: " + truck.getModel());
                System.out.println("Manufacturer: " + truck.getManufacturer());
                System.out.println("Color: " + truck.getColor());
                System.out.println("Loading Capacity: " + truck.getLoad());
                System.out.println();
                System.out.println(" if U want to update color and loading capacity press 1 and to exit press 2 ..");
    
                loop_option = Integer.parseInt(br.readLine());
    
                if (loop_option == 1) {
                    updateColorAndCapacity(br, truck);
                }
    
            } while (loop_option == 1);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Dear all,Now i have this question in my java program,I think it should be
Dear friends, I need your help. I need to send .bmp file to another
Dear Friends from Stackoverflow, Please help me with a problem that i'm having when
hello and good day dear xml-friends, i am new to xml so do not
hello and good day dear xml-friends, i am new to xml so do not
Dear Friends good afternoon. My problem may be this is very basic one i.e.
Hello dear friends of SO. I have this tables: PRECIOS +---------+--------+-----------+-------------+------------+ | priceID |
my dear friends. Could you help me to figure out where do I have
Dear friends,I want to extract text 平均3.6 星 from this code segment excerpted from
Dear all: In advance, thank you for your time. Lately, I have decided to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.