Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* 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 ex03_1_exercise;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Veo detalle en los paquetes. Por ejemplo en este archivo debería ser: jorgeantonio.exercises.ex03_1_exercise;


/**
*
* @author Hp
*/
public class ShoppingCart {
public static void main (String[] args){
System.out.println("Este es mi mensaje");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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 ex04_1_exercise;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lo mismo aquí, checar paquetes


/**
*
* @author Hp
*/
public class ShoppingCart {
public static void main(String[] args) {
// Declare and initialize String variables. Do not initialize message yet.
String custName = "Jorge ", itemDesc = "loves the music";
String message;


// Assign the message variable
message = custName + itemDesc;

// Print and run the code

System.out.println(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 ex04_2_exercise;

/**
*
* @author Hp
*/
public class ShoppingCart {
public static void main(String[] args) {
String custName = "Jorge";
String itemDesc = "Discs";
String message = custName+" bought "+itemDesc;
double price = 52.0 , tax = 5.2;
int quantity = 2;
double total;
// Declare and initialize numeric fields: price, tax, quantity, and total.


// Modify message to include quantity
message = custName + " bought " + quantity + " " + itemDesc;

System.out.println(message);

total = price * quantity * tax;


// Calculate total and then print the total cost

System.out.println("and they cost " + total);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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 ex05_1_exercise;
public class ShoppingCart {

public static void main(String[] args) {
String custName = "Mary Smith";
String itemDesc = "Shirt";

// numeric fields
double price = 21.99;
int quantity = 2;
double tax = 1.04;
double total;
String message = custName+" wants to purchase "+quantity+" "+itemDesc;

// Calculating total cost
total = (price*quantity)*tax;


// Declare outOfStock variable and initialize it
boolean outOfStock = true;

// Test quantity and modify message if quantity > 1.
if(quantity > 1){
message = message +"s";
}

// Test outOfStock and notify user in either case.

if(outOfStock == true){
System.out.println("The item unavailable");
}else{
System.out.println(message);
System.out.println("And the total is " + total);
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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 ex05_2_exercise;

/**
*
* @author Hp
*/

public class ShoppingCart {

public static void main(String[] args) {
// local variables
String custName = "Mary Smith";
String message = custName + " wants to purchase a several items.";

//Declare and initialize the items String array
String items [] = new String[]{"Shirt","Jeans","Shoes",""};



// Change message to show the number of items purchased.

message = "The items in total are " + items.length;

System.out.println(message);
// Print an element from the items array.
System.out.print(items[0]+"\n");

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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 ex05_3_exercise;

public class ShoppingCart {

public static void main(String[] args) {
// local variables
String custName = "Mary Smith";
String message;
double price = 21.99;
int quantity = 2;
double tax = 1.04;

String items[];
items = new String[4];
items[0] = "Shirt";
items[1] = "Belt";
items[2] = "Scarf";
items[3] = "Skirt";

message = custName + " wants to purchase "+items.length+" items.";
System.out.println(message);

for (int i = 0; i < items.length; i++) {
System.out.println(items[i]);
}


}
}

17 changes: 17 additions & 0 deletions src/main/java/jorgeantonio/exercices/ex06_1_exercise/Item.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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 ex06_1_exercise;

/**
*
* @author Hp
*/
public class Item {
public int id;
public String descr;
public int quantity;
public double price;
}
19 changes: 19 additions & 0 deletions src/main/java/jorgeantonio/exercices/ex06_2_exercise/Item.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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 ex06_2_exercise;



/**
*
* @author Hp
*/
public class Item {
public int itemId;
public String descr;
public int quantity;
public double price;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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 ex06_2_exercise;

public class ShoppingCart {

public static void main(String args[]) {
// Declare and initialize 2 Item objects
Item item1 = new Item();
Item item2 = new Item();

item1.itemId = 1;
item1.descr = "Playera de Brasil";
item1.price = 500.00;
item1.quantity = 5;

item2.itemId = 1;
item2.descr = "Playera de Mexico";
item2.price = 1150.00;
item2.quantity = 5;

// Print both item descriptions and run code.
System.out.println("The first description is " + item1.descr + "\n"
+ "The second description is " + item2.descr);

item1 = item2;

System.out.println("The new description is " + item1.descr);

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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 ex07_1_exercise;

public class ShoppingCart {
public static void main (String[] args){
String custName = "Steve Smith";
String firstName;
int spaceIdx;

// Get the index of the space character (" ") in custName.
spaceIdx = custName.indexOf(" ");


// Use the substring method parse out the first name and print it.
firstName = custName.substring(0,spaceIdx);

System.out.println(firstName);

}
}
18 changes: 18 additions & 0 deletions src/main/java/jorgeantonio/exercices/ex08_1_exercise/Item.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

package ex08_1_exercise;

public class Item {
char color;

public boolean SetColor(char colorCode){
if(colorCode == ' '){
return false;
}else{
this.color = colorCode;
return true;
}

}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

package ex08_1_exercise;

public class ShoppingCart {
public static void main(String[] args){
Item item1 = new Item();
if(true == item1.SetColor('e')){
System.out.println("THE NEW COLOR IS " + item1.color);
}else{
System.out.println("INVALID COLOR");
}

// Call the setColor method on item1. Print the new color value from
// item1 if the method returns true. Otherwise print an "invalid color"
// message.


// Test the class, using both valid and invalid colors.


}
}
36 changes: 36 additions & 0 deletions src/main/java/jorgeantonio/exercices/ex08_2_exercise/Item.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

package ex08_2_exercise;


public class Item {
String desc;
int quantity;
double price;
char colorCode = 'U'; //'U' = Undetermined

public void displayItem() {
System.out.println("Item: " + desc + ", " + quantity + ", "
+ price + ", "+colorCode);
}

// Write a public 3-arg setItemDisplay method that returns void.
public void setItemFields(String desc, int quantity, double price){
this.desc = desc;
this.quantity = quantity;
this.price = price;
}
public int setItemFields(String desc, int quantity, double price,char colorCode){
if(colorCode == ' '){
return-1;
}else{
this.colorCode = colorCode;
setItemFields(desc, quantity, price);
return 1;
}
}

// Write a public 4-arg setItemDisplay method that returns an int.



}
Loading