Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write in java>> programe 1 Help a car dealer to implement an electronic track fo

ID: 3630221 • Letter: W

Question

write in java>>
programe 1
Help a car dealer to implement an electronic track for his sells. Using Linked list data structure build him a system where he can:
1.Enter cars information (car brand, car model, car color, buy- price, sell-price)
2.Allow him to add cars at the end of his list.
3.Give him a chance to delete an item from the list using the car brand and color.
Hint: you may consider either the single linked list or the doubly linked list approach.
________________________________________________________________________
programe 2
Write a program that reads ten integers and displays them in the reverse of the order in which they were read

Explanation / Answer

import java.util.*;

class Info{

        protected String _brand;
        protected String _model;
        protected String _colour;
        protected int _bprice;
        protected int _sprice;

        public Info(String brand, String model, String colour, int bprice, int sprice){
                _brand = brand;
                _model = model;
                _colour = colour;
                _bprice = bprice;
                _sprice = sprice;
        }
}

class Car{

        public static void main(String[] args) {

                LinkedList<Info> list = new LinkedList<Info>();;
                int entries = 0;
                Scanner sc = new Scanner(System.in);

                System.out.print("Enter 1 to input car info, enter 2 to remove car, enter 3 to print and enter 0 to exit. ");

                int operator = sc.nextInt();

                while (operator != 0){

                        if(operator == 1){
                                System.out.print("Enter brand : ");
                                String b = sc.next();
                                System.out.print("Enter model : ");
                                String m = sc.next();
                                System.out.print("Enter colour : ");
                                String c = sc.next();
                                System.out.print("Enter buy price : ");
                                int bp = sc.nextInt();
                                System.out.print("Enter sell price : ");
                                int sp = sc.nextInt();

                                Info cinfo = new Info(b,m,c,bp,sp);
                                list.add(cinfo);
                        } else if (operator == 2){

                                int index = 0;
                                System.out.print("Enter brand : ");
                                String b = sc.next();
                                System.out.print("Enter colour : ");
                                String c = sc.next();

                                for(int i = 0; i < list.size(); i++){

                                        if (list.get(i)._brand.equals(b) && list.get(i)._colour.equals(c)){
                                                index = i;
                                        }
                                }

                                list.remove(index);
                        } else if (operator ==3){

                                System.out.println("Car brand Car model Car colour Buy price Sell price");
                                for (int i =0; i<list.size();i++){
                                        System.out.printf("%s %s %s %d %d ",list.get(i)._brand,list.get(i)._model,list.get(i)._colour,list.get(i)._bprice,list.get(i)._sprice);
                                }
                        }

                        System.out.print("Enter 1 to input car info, enter 2 to remove car, enter 3 to print and enter 0 to exit. ");
                        operator = sc.nextInt();
                }
        }
}