Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package oi;
- import java.util.Scanner;
- public class Monitoria {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- List a = new List();
- a.add("Paulo", 2.0, 3);
- a.add("Lo", 7.6789, 2);
- a.add("K", 5, 9);
- a.add("Digo", 1, 1);
- a.add("Digos", 878, 1);
- a.remove(6);
- a.print();
- }
- }
- class List {
- private String name;
- private Double price;
- private Integer qtd;
- private List next;
- public List() {
- this.name = null;
- this.price = null;
- this.qtd = null;
- this.next = null;
- }
- public List(String s, double p, int q) {
- this.name = s;
- this.price = p;
- this.qtd = q;
- this.next = null;
- }
- public void add(String s, double p, int q) {
- if (this.next == null) {
- if(this.price==null) {
- this.price=p;
- this.name=s;
- this.qtd = q;
- }else {
- this.next = new List(s, p, q);
- }
- } else {
- this.next.add(s, p, q);
- }
- }
- public void remove(double p) {
- if(this.next!=null && this.price!=null) { // TUDO MENOS O ULTIMO
- if(this.price>p) {
- this.price = this.next.price;
- this.name = this.next.name;
- this.qtd = this.next.qtd;
- this.next = this.next.next;
- if(this.next!=null) {
- this.next.remove(p);
- }
- }
- else {
- this.next.remove(p);
- }
- } if(this.price!=null && this.price>p) {
- this.price = null;
- this.name =null;
- this.qtd = null;
- }
- }
- public void print() {
- if (this.next == null && this.name != null) { // ULTIMO
- System.out.println(this.name);
- } else if (this.next != null) {
- if (this.name == null) {
- this.next.print();
- } else {
- System.out.println(this.name);
- this.next.print();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement